yangweijie / es-think-orm
Think ORM adapter for EasySwoole - Provides connection pooling, coroutine context, and state isolation
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/yangweijie/es-think-orm
Requires
- php: >=7.4
- ext-swoole: >=4.6
- easyswoole/easyswoole: ^3.4
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- topthink/think-orm: thinkphp 官方 orm,适合高于7.4使用
- yangweijie/think-orm: 个人降级php7.4 版本的think-orm 4 版本,适合7.4版本使用
This package is auto-updated.
Last update: 2026-02-24 08:55:20 UTC
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