beauty-framework/cockroach-db-support
最新稳定版本:1.0.0
Composer 安装命令:
composer require beauty-framework/cockroach-db-support
包简介
Beauty CockroachDB support
README 文档
README
This package provides CockroachDB support for the beauty-framework/database component of the Beauty Framework. It offers a lightweight adapter layer for integrating CockroachDB using the existing query builder and connection system.
🚀 Installation
composer require beauty-framework/cockroach-db-support
⚙️ Configuration
To use CockroachDB, provide a connection configuration with driver set to cockroach (in config/database.php):
return [ 'default' => 'cockroach', 'connections' => [ 'cockroach' => [ 'driver' => 'cockroach', 'host' => 'localhost', 'port' => 26257, 'database' => 'app_db', 'username' => 'root', 'password' => '', 'sslmode' => 'disable', 'ssl' => [ 'cert' => '/path/to/ca.crt', 'key' => '/path/to/client.key', 'ca' => '/path/to/ca.crt' ] ], ], ];
ℹ️ Under the hood, this driver uses PostgreSQL (
pgsql) via PDO but is tailored for CockroachDB's SQL behavior.
And last, add in \App\Container\Database::configure:
$factory = new ConnectionFactory([ new PdoPgsqlDriver(), new PdoMysqlDriver(), new PdoSqliteDriver(), new PdoSqlsrvDriver(), new \Beauty\CockroachDB\Drivers\PdoCockroachDriver(), // <-- Add this ]);
📚 Usage
You can use CockroachDB exactly like any other connection in beauty/database:
$connection = $manager->connection('cockroach'); $connection->table('users')->insert([ 'name' => 'Kirill', 'email' => 'admin@example.com' ]);
Supports:
- Basic queries (select, insert, update, delete)
- Transactions
- Insert or update (via
ON CONFLICT DO UPDATE)
🧪 Testing
You can spin up a CockroachDB instance locally using Docker:
docker run -d --name=cockroach \ -p 26257:26257 -p 8080:8080 \ cockroachdb/cockroach:v24.1.0 start-single-node --insecure
docker exec -it cockroach ./cockroach sql --insecure --execute="CREATE DATABASE app_db"
Run tests:
./vendor/bin/phpunit
📝 License
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-20