Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
6 contributors

Users who have contributed to this file

@f3l1x @josefbenjac @solcik @jankonas @vody105 @mabar
170 lines (128 sloc) 3.67 KB

Nettrine DBAL

Doctrine DBAL for Nette Framework.

Content

Setup

Install package

composer require nettrine/dbal

Register extension

extensions:
    dbal: Nettrine\DBAL\DI\DbalExtension

There is also bridge to Symfony\Console. More in Bridges.

Configuration

Minimal configuration could looks like this.

dbal:
    debug:
        panel: %debugMode%
    connection:
        host: localhost
        driver: mysqli
        dbname: nettrine
        user: root
        password: root

Full configuration options:

dbal:
    debug:
        panel: %debugMode%
        sourcePaths: [%appDir%]
    configuration:
        sqlLogger: NULL
        resultCacheImpl: NULL
        filterSchemaAssetsExpression: NULL
        autoCommit: TRUE

    connection:
        url: NULL
        pdo: NULL
        memory: NULL
        driver: pdo_mysql
        driverClass: NULL
        host: NULL
        dbname: NULL
        servicename: NULL
        user: NULL
        password: NULL
        charset: UTF8
        portability: PortabilityConnection::PORTABILITY_ALL
        fetchCase: PDO::CASE_LOWER
        persistent: TRUE
        types: []
        typesMapping: []
        wrapperClass: NULL

Types

Here is a example how to custom type. For more information, follow the official documention.

dbal:
    connection:
        types:
            uuid_binary_ordered_time:
                class: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
                commented: false

        typesMapping:
            uuid_binary_ordered_time: binary

Debug

  • sourcePaths - displays all source files from provided paths where a query is called from
  • Queries table is sortable

Events

You can use native Doctrine DBAL event system.

services:
    subscriber1:
      class: App\PostConnectSubscriber

Register and create your own subscribers. There're services, so constructor injection will works. There're also loaded lazily, don't worry about performance.

namespace App;

use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;

final class PostConnectSubscriber implements EventSubscriber
{
	public function postConnect(ConnectionEventArgs $args): void
	{
		// Magic goes here...
	}

	public function getSubscribedEvents(): array
	{
		return [Events::postConnect];
	}

}

Bridges

Symfony\Console

This package works pretty well with Symfony/Console. Take a look at Contributte/Console tiny integration for Nette Framework.

extensions:
    # Console
    console: Contributte\Console\DI\ConsoleExtension

    # Dbal
    dbal: Nettrine\Dbal\DI\DbalExtension
    dbal.console: Nettrine\Dbal\DI\DbalConsoleExtension(%consoleMode%)

From this moment when you type bin/console, there'll be registered commands from Doctrine DBAL.

Commands

Psr\Log

Log all queries with a PSR-3 logger, e.g. Monolog

dbal:
    configuration:
        sqlLogger: Nettrine\DBAL\Logger\PsrLogger()
You can’t perform that action at this time.