定制 beauty-framework/cockroach-db-support 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-20