yangweijie/es-think-orm
最新稳定版本:v1.0.2
Composer 安装命令:
composer require yangweijie/es-think-orm
包简介
Think ORM adapter for EasySwoole - Provides connection pooling, coroutine context, and state isolation
README 文档
README
Think ORM adapter for EasySwoole - Provides connection pooling, coroutine context, and state isolation.
Installation
composer require easyswoole/easy-orm
Features
- Connection Pooling: Automatic management of database connections
- Coroutine Context: Safe database operations in Swoole coroutines
- State Isolation: Each request has independent database state
- Multi-Database Support: Multiple database connections with separate pools
- Query Caching: Built-in support for file and Redis caching
- Transaction Management: Coroutine-safe transaction support
- Hot Reload: Development mode hot reload support
- Pool Monitoring: Connection pool status monitoring
Quick Start
Configuration
// config/database.php return [ 'default' => 'mysql', 'connections' => [ 'mysql' => [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => '', 'hostport' => '3306', 'charset' => 'utf8mb4', 'debug' => true, 'pool' => [ 'min_active' => 2, 'max_active' => 10, 'max_wait_time' => 5, 'max_idle_time' => 60, ], 'cache' => [ 'class' => 'EasyOrm\FileCacheHandler', 'params' => [ 'cache_dir' => EASYSWOOLE_ROOT . '/Temp/cache', ], ], ], ], ];
Redis Cache Configuration
// config/database.php return [ 'default' => 'mysql', 'connections' => [ 'mysql' => [ // ... database config ... 'cache' => [ 'class' => 'EasyOrm\RedisCacheHandler', 'params' => [ 'host' => '127.0.0.1', 'port' => 6379, 'auth' => '', // Redis password (optional) 'db_index' => 0, // Redis database index 'timeout' => 3.0, // Connection timeout ], ], ], ], ];
Custom Cache Handler
You can also create your own cache handler:
use EasyOrm\EasyDb; // Create custom cache handler class MyCacheHandler { public function get($key) { // Return cached value or null } public function set($key, $value, $ttl = null) { // Store value, return bool } public function rm($key) { // Remove cached value, return bool } } // Set cache handler manually EasyDb::setCacheHandler(new MyCacheHandler());
Initialize in EasySwooleEvent
use EasyOrm\EasyDb; public static function initialize() { $config = require EASYSWOOLE_ROOT . '/config/database.php'; EasyDb::init($config); }
Usage
use EasyOrm\EasyDb; // Basic query $users = EasyDb::name('user')->where('status', 1)->select(); // With cache $users = EasyDb::name('user')->cache(true, 60)->where('status', 1)->select(); // Transaction EasyDb::transaction(function() { EasyDb::name('user')->insert(['name' => 'test']); EasyDb::name('order')->insert(['user_id' => 1]); });
Documentation
See API.md for detailed API documentation.
License
Apache-2.0
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-24