brash / dbal
An Async Database Abstract Layer based on Doctrine DBAL
Requires
- php: ^8.3.0
- clue/reactphp-sqlite: ^1.6
- doctrine/dbal: ^4.2
- react/async: ^4.3
- react/mysql: ^0.7@dev
- react/promise: ^3.2
- voryx/pgasync: ^2.0
Requires (Dev)
- laravel/pint: ^1.18.1
- mockery/mockery: ^1.6
- pestphp/pest: ^3.5.1
- pestphp/pest-plugin-type-coverage: ^3.1
- phpstan/phpstan: ^1.12.7
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
This package is auto-updated.
Last update: 2025-05-10 20:05:40 UTC
README
Brash DBAL
This is a DBAL on top of ReactPHP SQL clients and Doctrine DBAL. With this, you will be able to use
Doctrine QueryBuilder model
Doctrine Schema model
SQL Statements
Easy-to-use shortcuts for common operations
Using this non-blocking approach, you release your processes from the burden of keeping await operations while you can take the most out of your processor, with the advantage of seemingly unnoticeable await
keywords.
How to use
You may find concrete examples (and working!) in examples
directory, but this package does pretty much what Doctrine DBAL does, since it is just a way to extend Doctrine DBAL's already useful and knwon qualities. The additions are transparent, but basically:
- A connection pool
- Async drivers
- A custom Driver Manager
It goes like this ;)
use Brash\Dbal\DriverManager; $connectionParams = [ 'dbname' => 'mydb', 'user' => 'root', 'password' => 'secret', 'host' => 'localhost', 'driver' => 'async_mysql', # pay attention to the driver selection! 'port' => 3306 ]; $conn = DriverManager::getConnection($connectionParams); $conn->insert("test", [ 'id' => 1, 'username' => "Gabo Bertir" ]);
Configuration
You can configure the driver manager directly from the class just like the connection pool values.
use Brash\Dbal\DriverManager; DriverManager::setPoolOptions(new ConnectionPoolOptions( maxConnections: 10, idleTimeout: 2, # in seconds maxRetries: 5, discardIdleConnectionsIn: 5, # seconds minConnections: 2, keepAliveIntervalSec: 0 # Disabled when 0 )); DriverManager::getConnection([...]);
Driver Options
Choose between MySQL, MariaDB, Postgres and SQLite, just passing the correct driver in your Connection Params
.
'async_postgres' => AsyncPostgresDriver::class, 'async_mysql' => AsyncMysqlDriver::class, 'async_sqlite' => AsyncSqliteDriver::class,
Under the hood
Internally, the: Postgres Async Driver is an implementation on top of Voryx/PgAsync; SQLite Async Driver is an implementation on top of Clue/reactphp-sqlite, and MySQL/MariaDB is an implementation on top of react/mysql.
Requires PHP 8.3+
๐งน Keep a modern codebase with Pint:
composer lint
โ Run refactors using Rector
composer refacto
โ๏ธ Run static analysis using PHPStan:
composer test:types
โ Run unit tests using PEST
composer test:unit
๐ Run the entire test suite:
composer test