beauty-framework/cockroach-db-support

1.0.0 2025-06-20 11:56 UTC

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.