pader / amphp-eloquent-mysql
异步/协程 amphp mysql eloquent 适配器。
1.0.0-beta.4
2024-02-28 08:05 UTC
Requires
- amphp/mysql: ^3.0
- illuminate/database: ^10.0
This package is auto-updated.
Last update: 2024-09-28 09:30:14 UTC
README
异步/协程 amphp eloquent mysql 适配器。
Amphp mysql 适配器到 laravel eloquent,结合了 amphp mysql 的连接池和高并发特性以及 eloquent 的功能和灵活性。
现在你拥有了一个高并发的 eloquent。
php 版本 >= 8.1,不需要 PDO,不需要 mysqli。
使用方法
use AmphpEloquentMysql\Connection; use Illuminate\Database\Capsule\Manager; use Illuminate\Support\Facades\DB; $capsule = new Manager(); $capsule->getDatabaseManager()->extend('ampmysql', function($config, $name) { $config['name'] = $name; return new Connection($config); }); // Create connection $capsule->addConnection([ 'driver' => 'ampmysql', 'host' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', 'port' => 3306, 'collation' => 'utf8mb4_general_ci', 'prefix' => '', ]); // Set can be visit as global static $capsule->setAsGlobal(); // Boot Eloquent (can ignore this if you use QueryBuilder only) $capsule->bootEloquent(); DB::swap($capsule->getDatabaseManager()); // Initialized finished, you can use it now $item = DB::table('users')->first();