Download the PHP package a-h-abid/eloquent-cassandra without Composer
On this page you can find all versions of the php package a-h-abid/eloquent-cassandra. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-cassandra
Eloquent Cassandra
Cassandra driver for Eloquent ORM.
Installation
Note: Make sure you have the Cassandra PHP driver installed (version 1.3+). You can find more information at DataStax PHP Driver.
Installation using composer:
Laravel
And add the service provider in config/app.php
:
The service provider will register a cassandra database extension with the original database manager. There is no need to register additional facades or objects. When using cassandra connections, Laravel will automatically provide you with the corresponding cassandra objects.
For usage outside Laravel, check out the Capsule manager and add:
Lumen
Add next lines to your bootstrap.php
Configuration
Change your default database connection name in config/database.php
:
And add a new cassandra connection:
You can connect to multiple servers with the following configuration:
Note: you can enter all of your nodes in .env like :
# .env
DB_HOST=192.168.0.1,192.168.0.2,192.168.0.3
Note: list of available consistency levels (php constants):
Cassandra::CONSISTENCY_ANY
Cassandra::CONSISTENCY_ONE
Cassandra::CONSISTENCY_TWO
Cassandra::CONSISTENCY_THREE
Cassandra::CONSISTENCY_QUORUM
Cassandra::CONSISTENCY_ALL
Cassandra::CONSISTENCY_SERIAL
Cassandra::CONSISTENCY_QUORUM
Cassandra::CONSISTENCY_LOCAL_QUORUM
Cassandra::CONSISTENCY_EACH_QUORUM
Cassandra::CONSISTENCY_LOCAL_SERIAL
Cassandra::CONSISTENCY_LOCAL_ONE
Note: you can set specific consistency level according to the query using options
Eloquent
Model Usage
Supported most of eloquent query build features, events, fields access.
Relations - NOT SUPPORTED
Attributes casting
There is ability to use UUID as model primary key
Query Builder
The database driver plugs right into the original query builder. When using cassandra connections, you will be able to build fluent queries to perform database operations.
If you did not change your default database connection, you will need to specify it when querying.
Default use of get
method of query builder will call chunked fetch from database.
Chunk size can be configured on config file ('page_size' => env('DB_PAGE_SIZE', 5000)
) or with additional query builder`s method setPageSize
.
WARNING: Not recomended to use get
if there are a lot of data in table. Use getPage
instead.
Get single page of resuts
There is an ability to set next page token what allows to get next chunk of results
Get next page:
Get next page token:
Append collection with next page`s result:
Check if it is last page:
Get raw cassandra response for current page (\Cassandra\Rows):
Read more about the query builder on http://laravel.com/docs/queries
Examples
-
store users data to csv
-
Simple api to make
Load more
as paggination on page - If you use cassandra materialized views you can easily use it with eloquent models
TODO:
[ ] full support of composite primary key [ ] full test coverage [ ] fix diff between \Cassandra\Date with Carbon [ ] add schema queries support [ ] add ability to use async queries
Docker:
There is docker-compose setup stored in package root. It can be used for local development and test running. Works well with PHPStorm testing tools + coverage.
Run command below inside of the "main" container to run tests and generate coverage file:
All versions of eloquent-cassandra with dependencies
ext-cassandra Version ^1.3
illuminate/support Version ^5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0
illuminate/container Version ^5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0
illuminate/database Version ^5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0
illuminate/events Version ^5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0