ylsideas/cockroachdb-laravel
Composer 安装命令:
composer require ylsideas/cockroachdb-laravel
包简介
This is my package cockroachdb-laravel
README 文档
README
A driver/grammar for Laravel that works with CockroachDB. While CockroachDB is compatible with Postgresql, this support is not 1 to 1 meaning you may run into issues, this driver hopes to resolve those problems as much as possible.
Laravel 9 through to Laravel 11 is supported and tested against CockroachDB 22 & 23.
Supporting Open Source
Peter Fox here, I just want to say this project has been my hardest yet. It's been a real labour of love to make and takes up a lot of time trying to organise the test suite so that compatibility is maintained between Eloquent and CockroachDB.
I see a lot of promise in using CockroachDB's serverless offering which is what compelled me to go down this route originally. You can read an article I made about using their service.
If you're using this project at all then do please consider sponsoring me as a way of encouraging more development.
Installation
You can install the package via composer:
composer require ylsideas/cockroachdb-laravel
You need to add the connection type to the database config:
'crdb' => [ 'driver' => 'crdb', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '26257'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, 'schema' => 'public', 'sslmode' => 'prefer', ]
You can also use URLs.
DATABASE_URL=cockroachdb://<username>:<password>@<host>:<port>/<database>?sslmode=verify-full
Usage
To enable set DB_CONNECTION=crdb in your .env.
Notes
CockroachDB should work inline with the feature set of Postgresql, with some exceptions. You can look at the features of each CockroachDB server in the CockroachDB Docs.
Deletes with Joins
CockroachDB does not support performing deletes using joins. If you wish to do something like this you will need to use a sub-query instead.
At current if you try to call the delete method of the Query builder together with a join then
a YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException exception will be thrown.
Fulltext Search
Eloquent and Postgresql support Fulltext search. CockroachDB does not support any full text search meaning the feature cannot be used when using this driver.
At current if you try to create a Fulltext index using the Schema builder or try to use the whereFulltext
method of the Query builder a YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException exception will be thrown.
Serverless Support
Cockroach Serverless requires you to provide a cluster with connection.
Laravel doesn't provide this out of the box, so, it's being implemented as an extra cluster parameter in the
database config. Just pass the cluster identification from CockroachDB Serverless.
Schema Dumps
You may use schema dumps. I'm not 100% sure the functionality is correct in line with other drivers. Please raise an issue if it isn't working as expect for you.
'crdb' => [ 'driver' => 'crdb', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '26257'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, 'schema' => 'public', 'sslmode' => 'prefer', 'cluster' => env('COCKROACHDB_CLUSTER', ''), ]
You may also use a URL in the following format.
DATABASE_URL=cockroachdb://<username>:<password>@<host>:<port>/<database>?sslmode=verify-full&cluster=<cluster>
Testing
The tests try to closely follow the same functionality of the grammar provided by Laravel by lifting the tests straight from laravel/framework. This does provide some complications. Namely, cockroachdb is designed to be distributed so primary keys do not occur in sequence.
Tests should also try to be compatible with not just the latest version of Laravel but across Laravel 8, 9 and 10, this requires some tests to be skipped.
You can run up a local cockroachDB test instance using Docker compose.
docker-composer up -d
If you need to you may run the docker compose file with different cockroachdb versions
VERSION=v23.1.13 docker-compose up -d
Then run the following PHP script to create a test database and user
php ./database.php
Afterwards you can run the test suite.
composer test
To clean up, you only need stop docker composer.
docker-composer down
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
ylsideas/cockroachdb-laravel 适用场景与选型建议
ylsideas/cockroachdb-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31.51k 次下载、GitHub Stars 达 73, 最近一次更新时间为 2021 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「cockroachdb」 「ylsideas」 「cockroachdb-laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ylsideas/cockroachdb-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ylsideas/cockroachdb-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ylsideas/cockroachdb-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for handling feature flags
A Laravel package for adding unsubscribe links to notifications
Simple CockroachDB driver for Laravel 6+
CockroachDB driver for Lumen 8
Doctrine CockroachDB Driver (Symfony supports)
This is my package cockroachdb-laravel
统计信息
- 总下载量: 31.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 73
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-14