beauty-framework / cockroach-db-support
Beauty CockroachDB support
Requires
- php: >=8.1
- ext-pdo: *
- beauty-framework/database: ^1.0
Requires (Dev)
- phpunit/phpunit: ^12.3@dev
This package is not auto-updated.
Last update: 2025-06-21 10:09:25 UTC
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.