定制 brash/dbal 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brash/dbal

最新稳定版本:v1.0.0

Composer 安装命令:

composer require brash/dbal

包简介

An Async Database Abstract Layer based on Doctrine DBAL

README 文档

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

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-04