baraja-core / doctrine
Doctrine port to Nette 3.0 with maximal performance.
Installs: 273 593
Dependents: 29
Suggesters: 0
Security: 0
Stars: 11
Watchers: 3
Forks: 3
Open Issues: 5
Requires
- php: ^8.0
- ext-pdo: *
- baraja-core/nette-symfony-console: ^1.0
- baraja-core/network: ^1.0
- baraja-core/url: ^1.1
- doctrine/annotations: ^1.13
- doctrine/orm: ^2.13
- nette/di: ^3.0
- ramsey/uuid: ^4.4
Requires (Dev)
- baraja-core/package-manager: ^3.2
- baraja-core/service-method-invoker: ^2.2
- nette/caching: ^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-nette: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- roave/security-advisories: dev-master
- spaze/phpstan-disallowed-calls: ^2.0
- tracy/tracy: ^2.9
- dev-master
- v3.7.5
- v3.7.4
- v3.7.3
- v3.7.2
- v3.7.1
- v3.7.0
- v3.6.0
- v3.5.5
- v3.5.4
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.6.1
- v2.6.0
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/doctrine/annotations-tw-2.0
- dev-renovate/configure
- dev-env-variable
- dev-em-return-void
- dev-restyled/renovate/configure
- dev-dependabot/add-v2-config-file
This package is auto-updated.
Last update: 2024-11-09 21:17:09 UTC
README
BRJ organisation
Baraja Doctrine database 📚
A simple and easy to use, maximum performance database layer with connection to Doctrine, which allows you to use all the advantages of OOP and also has support for Nette 3.
This package automatically installs Doctrine to your project (also sets everything up in the configuration) and runs stably.
🐛 Best debug Tracy panel
This package contains the most advanced native tools for debugging your application and SQL queries. You can very easily view the performed queries, click directly on the place of their original invocation and watch the time graphs on the output (with the possibility of analyzing slow queries). Write query types are displayed separately for quick control of data flow.
The package also includes advanced logic for debugging corrupted entities and queries directly through Tracy Bluescreen. Using the debugger turns on automatically and you will never lose any useful information.
📦 Installation & Basic Usage
This package can be installed using Package Manager which is also part of the Baraja Sandbox. If you are not using it, you will have to install the package manually using this guide.
A model configuration can be found in the common.neon
file inside the root of the package.
To manually install the package call Composer and execute the following command:
$ composer require baraja-core/doctrine
In the project's common.neon
you have to define the database credentials. A fully working example of configuration can be found in the common.neon
file inside this package. You can define the configuration simply using baraja.database
extension.
For example:
baraja.database: connection: host: 127.0.0.1 dbname: sandbox user: root password: root
For now the package supports only the connection to one database.
Possible connection options: url
, pdo
, memory
, driver
, driverClass
, driverOptions
, unix_socket
, host
, port
, dbname
, servicename
, user
, password
, charset
, portability
, fetchCase
, persistent
, types
, typesMapping
, wrapperClass
.
⚙️ Drivers
In default settings Doctrine use MySql
driver.
You can rewrite it for example for Postgres:
In your common.neon
simple type:
baraja.database: connection: driverClass: Doctrine\DBAL\Driver\PDO\PgSQL\Driver
🗺️ Entity mapping
In order for Doctrine to know which classes are entities and which application logic, it is necessary to set up a mapping.
For mapping, it is necessary to set the introductory part of the namespace entities and the directory where they occur in the project common.neon. A relative path can also be used.
For example:
orm.annotations: paths: App\Baraja\Entity: %rootDir%/app/model/Entity
You can also specify the ignore
key, which disables browsing a specific directory.
Important warning:
The value of the
%rootDir%
,%appDir%
,%wwwDir%
,%vendorDir%
and%tempDir%
parameters may be corrupted when running schema generation in CLI mode. To resolve this mistake, please install Package Manager and call the command as acomposer dump
.
Generate database structure from entities
This package implements a bridge to automatically execute Doctrine commands.
For example you can simply call:
php www/index.php o:s:u -f --dump-sql
The command o:s:u
means orm:schema-tool:update
.
-f
isflush
to execute changes in SQL,--dump-sql
renders the list of SQL commands that will be executed.
If everything will work fine, the command will create the table core__database_slow_query
which is defined in this package and is ready for logging slow queries.
TIP: If you are using Package Manager, you can simply call the
composer dump
command.
🚀 Performance Benchmarks
When Doctrine is used poorly, it can be unnecessarily slow.
For more details (in Czech language): https://ondrej.mirtes.cz/doctrine-2-neni-pomala
This package uses best-practices to increase the performance. It sets automatically autoGenerateProxyClasses
to false
, ProxyClasses will be generated when needed by Doctrine.
For maximum performance is best to save the generated meta data about your entities using Redis: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html
UUID
TIP: Read more about UUID binary performance (czech language)
For unique record (entity) identification the package defines the trait UuidIdentifier
or UuidBinaryIdentifier
with already defined all basic best-practice configurations for your entity. The ID will be generated automatically.
For a better experience please insert two traits to all the entities in your project:
<?php declare(strict_types=1); namespace Baraja\Doctrine\Entity; use Doctrine\ORM\Mapping as ORM; use Baraja\Doctrine\Identifier\IdentifierUnsigned; #[ORM\Entity] class DatabaseEntity { use IdentifierUnsigned; // ID trait for entity identifier. // or use uuid: // use UuidIdentifier; // UUID identifier trait
UUID will be generated automatically in PHP.
📄 License
baraja-core/doctrine
is licensed under the MIT license. See the LICENSE file for more details.