Git Product home page Git Product logo

doctrine's Introduction

Baraja Doctrine database ๐Ÿ“š

Integrity check

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.

Baraja Doctrine debug Tracy panel

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 a composer 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 is flush 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.

doctrine's People

Contributors

dependabot-preview[bot] avatar digioncz avatar idome89 avatar imgbot[bot] avatar janbarasek avatar packeta-user avatar pkotlarik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

doctrine's Issues

Identifiers explain comment

Doctrine traita pro vลกechny typy int indentifieru + komentรกล™ s rozsahem platnรฝch hodnot

Query explain

Possible design:

Screenshot from 2021-02-22 09-20-40

Possible Tracy panel code:

<a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .brj-doctrine-explain">explain</a>
<table class="tracy-collapsed brj-doctrine-explain">
   <!-- code -->
</table>

not working with Symfony 7.0

Hello,

I've tried to add it to Symfony 7.0 project, but I get the following error message:

./composer.json has been updated
Running composer update baraja-core/doctrine
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - baraja-core/doctrine[v1.0.0, ..., v1.1.0, v2.0.0, ..., v2.0.9] require symfony/console ^4.2.3 -> found symfony/console[v4.2.3, ..., v4.4.49] but it conflicts with your root composer.json require (7.0.*).
    - baraja-core/doctrine[v2.2.0, ..., v2.6.1, v3.0.0, ..., v3.1.0] require doctrine/orm ^2.7 -> found doctrine/orm[v2.7.0, ..., 2.18.1] but it conflicts with your root composer.json require (^3.0).
    - contributte/console v0.8.0 requires php ^7.2 -> your php version (8.2.12) does not satisfy that requirement.
    - baraja-core/doctrine[v2.6.0, v3.2.0, ..., v3.7.1] require doctrine/orm ^2.9 -> found doctrine/orm[2.9.0, ..., 2.18.1] but it conflicts with your root composer.json require (^3.0).
    - baraja-core/doctrine[v3.7.2, ..., v3.7.4] require doctrine/orm ^2.13 -> found doctrine/orm[2.13.0, ..., 2.18.1] but it conflicts with your root composer.json require (^3.0).
    - baraja-core/doctrine[v2.1.0, ..., v2.1.1] require contributte/console ^0.8.0 -> satisfiable by contributte/console[v0.8.0].
    - Root composer.json requires baraja-core/doctrine * -> satisfiable by baraja-core/doctrine[v1.0.0, ..., v1.1.0, v2.0.0, ..., v2.6.1, v3.0.0, ..., v3.7.4].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require baraja-core/doctrine:*" to figure out if any version is installable, or "composer require baraja-core/doctrine:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Add more database connections

  • Is your feature request related to a problem?
    Yes, as I cannot use more than 1 database in whole project
  • Explain your intentions.
    Add another connection support in neon package configuration
  • It's up to you to make a strong case to convince the project's developers of the merits of this feature.
    CASE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.