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 8 and 9 are both supported and tested against CockroachDB 2.5.
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.
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',
]
To enable set DB_CONNECTION=crdb
in your .env.
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.
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.
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.
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. Also deletes with joins do not work compared to other Laravel supported databases so the delete with limit test uses a sub query instead.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.