lzpeng / hyperf-cycle
Cycle ORM support for hyperf
1.0.4
2024-07-03 03:33 UTC
Requires
- php: >=8.1
- cycle/orm: ^2.8
- hyperf/pool: ^3.1
Requires (Dev)
- pestphp/pest: ^2.34
This package is auto-updated.
Last update: 2025-03-31 05:00:03 UTC
README
Cycle ORM support for hyperf
使用Hyperf/Pool增加连接池功能
用法与CycleORM基本相同:
use Lzpeng\HyperfCycle\DatabaseManager; use Lzpeng\HyperfCycle\Config\DatabaseConfig; use Lzpeng\HyperfCycle\Config\MySQLDriverConfig; use Cycle\Database\Config\MySQL\TcpConnectionConfig; $databaseManager = new DatabaseManager( new DatabaseConfig([ 'default' => 'default', 'databases' => [ 'default' => ['connection' => 'mysql'] ], 'connections' => [ 'mysql' => new MySQLDriverConfig( connection: new TcpConnectionConfig( database: 'spiral', host: '127.0.0.1', port: 3306, user:'spiral', password: '', ), queryCache: true, // 增加了连接池配置 poolOptions: [ 'min_connections' => 1, 'max_connections' => 20, 'connect_timeout' => 10.0, 'wait_timeout' => 3.0, 'heartbeat' => -1, 'max_idle_time' => 60.0, ] ), ] ]) ); $container = /** 获取容器 **/ $schemaConfig = /** schema配置 **/; $schema = new Schema($schemaConfig); $commandGenerator = new EventDrivenCommandGenerator($schema, $container); $ormFactory = new ORMFactory($databaseManager, $schema, $commandGenerator); // 获取ORM实例 $orm = $ormFactory->orm(); // 获取EntityManager实例 $em = $ormFactory->entityManager();