PHPackages                             cipwebapp/laravel-cassandra - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. cipwebapp/laravel-cassandra

ActiveLibrary[Database &amp; ORM](/categories/database)

cipwebapp/laravel-cassandra
===========================

Cassandra based query builder for laravel.

v1.1.6(6y ago)0761MITPHPPHP ^7.0 || ^7.1CI failing

Since Jun 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/cipwebapp/laravel-cassandra)[ Packagist](https://packagist.org/packages/cipwebapp/laravel-cassandra)[ RSS](/packages/cipwebapp-laravel-cassandra/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (10)Used By (0)

Lacassa
=======

[](#lacassa)

[![Build Status](https://camo.githubusercontent.com/846588e11ea08f253357624210bfb23968194719f50fbfcc0585779af0cbed58/68747470733a2f2f7472617669732d63692e6f72672f53686168696e536f726b682f6c61726176656c2d63617373616e6472612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ShahinSorkh/laravel-cassandra)[![codecov](https://camo.githubusercontent.com/6020e48c54c0aee601fa47b58fa27a8a8ae822c2164ac8e6aec535db4ce7949c/68747470733a2f2f636f6465636f762e696f2f67682f53686168696e536f726b682f6c61726176656c2d63617373616e6472612f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ShahinSorkh/laravel-cassandra)

WORKING ON A NEW VERSION WAIT FOR DOCUMENTATION UPDATES
-------------------------------------------------------

[](#working-on-a-new-version-wait-for-documentation-updates)

A Query builder with support for Cassandra, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.

**Table of contents**
---------------------

[](#table-of-contents)

- Installation
- Configuration
- Query Builder
- Schema
- Extensions
- Examples

**Installation**
----------------

[](#installation)

Make sure you have the DataStax PHP Driver for Apache Cassandra installed. You can find installation instructions at [datastax repo](https://github.com/datastax/php-driver).

Note: *datastax php-driver works with php version 5.6.\*, 7.0.\* and 7.1.\* only*

### Installation using composer

[](#installation-using-composer)

```
composer require cipwebapp/laravel-cassandra
```

And add the service provider in config/app.php:

```
# config/app.php
...
providers: [
    ...,
    cipwebapp\Lacassa\CassandraServiceProvider::class,
    ...,
],
...
```

**Configuration**
-----------------

[](#configuration)

Change your default database connection name in config/database.php:

```
# config/database.php
'default' => env('DB_CONNECTION', 'cassandra'),
```

And add a new cassandra connection:

```
# config/database.php
'cassandra' => [
    'driver' => 'cassandra',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', 9042),
    'keyspace' => env('DB_DATABASE', 'cassandra_db'),
    'username' => env('DB_USERNAME', ''),
    'password' => env('DB_PASSWORD', ''),
    'page_size' => '5000',
    'consistency' => 'local_one',
    'timeout' => null,
    'connect_timeout' => 5.0,
    'request_timeout' => 12.0,
],
```

Note: *you can enter all of your nodes like:*

```
# .env
DB_HOST=192.168.100.140,192.168.100.141,192.168.100.142

```

Note: *you can choose one of the consistency levels below:*

`any``three``local_qourum``local_one``one``qourum``each_qourum``serial``two``all``local_serial`***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.

```
$emp = DB::table('emp')->get();
$emp = DB::table('emp')->where('emp_name', 'Christy')->first();
```

If you did not change your default database connection, you will need to specify it on each query.

```
$emp = DB::connection('cassandra')->table('emp')->get();
```

**Examples**
------------

[](#examples)

### **Retrieving All Records**

[](#retrieving-all-records)

```
$emp = DB::table('emp')->all();
```

### **Indexing columns**

[](#indexing-columns)

`CREATE INDEX` creates a new index on the given table for the named column.

```
DB::table('users')->index(['name']);
```

### **Selecting columns**

[](#selecting-columns)

```
$emp = DB::table('emp')->where('emp_no', '>', 50)->select('emp_name', 'emp_no')->get();
$emp = DB::table('emp')->where('emp_no', '>', 50)->get(['emp_name', 'emp_no']);
```

### **Wheres**

[](#wheres)

The WHERE clause specifies which rows to query. In the WHERE clause, refer to a column using the actual name, not an alias. Columns in the WHERE clause need to meet one of these requirements:

- The partition key definition includes the column.
- A column that is indexed using `CREATE INDEX`.

```
$emp = DB::table('emp')->where('emp_no', '>', 50)->take(10)->get();
```

### **And Statements**

[](#and-statements)

```
$emp = DB::table('emp')->where('emp_no', '>', 50)->where('emp_name', '=', 'Christy')->get();
```

### **Using Where In With An Array**

[](#using-where-in-with-an-array)

```
$emp = DB::table('emp')->whereIn('emp_no', [12, 17, 21])->get();
```

### **Order By**

[](#order-by)

`ORDER BY` clauses can select a single column only. Ordering can be done in ascending or descending order, default ascending, and specified with the ASC or DESC keywords. In the `ORDER BY` clause, refer to a column using the actual name, not the aliases.

```
$emp = DB::table('emp')->where('emp_name', 'Christy')->orderBy('emp_no', 'desc')->get();
```

### **Limit**

[](#limit)

We can use limit() and take() for limiting the query.

```
$emp = DB::table('emp')->where('emp_no', '>', 50)->take(10)->get();
$emp = DB::table('emp')->where('emp_no', '>', 50)->limit(10)->get();
```

### **Distinct**

[](#distinct)

Distinct requires a *primary key* field for which to return the distinct values.

```
$emp = DB::table('emp')->distinct()->get(['emp_id']);
```

Distinct can be combined with **where**:

```
$emp = DB::table('emp')->where('emp_sal', 45000)->distinct()->get(['emp_name']);
```

### **Count**

[](#count)

```
$number = DB::table('emp')->count();
```

Count can be combined with **where**:

```
$sal = DB::table('emp')->where('emp_sal', 45000)->count();
```

### **Truncate**

[](#truncate)

```
$sal = DB::table('emp')->truncate();
```

### **Filtering a collection set, list, or map**

[](#filtering-a-collection-set-list-or-map)

You can index the collection column, and then use the CONTAINS condition in the WHERE clause to filter the data for a particular value in the collection.

```
$emp = DB::table('emp')->where('emp_name', 'contains', 'Christy')->get();
```

After [indexing the collection keys](https://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_index_r.html#reference_ds_eqm_nmd_xj__CreatIdxCollKey)in the venues map, you can filter on map keys.

```
$emp = DB::table('emp')->where('todo', 'contains key', '2014-10-02 06:30:00+0000')->get();
```

### **Raw Query**

[](#raw-query)

The CQL expressions can be injected directly into the query.

```
$emp = DB::raw('select * from emp');
```

**Inserts, updates and deletes**
--------------------------------

[](#inserts-updates-and-deletes)

Inserting, updating and deleting records works just like the original QB.

### **Insert**

[](#insert)

```
DB::table('emp')
    ->insertCollection('set', 'phn', [123, 1234, 12345])
    ->insertCollection('map', 'friends', [['John', 'Male'], ['Eli', 'Female']])
    ->insert([
        'emp_id' => 11,
        'emp_name' => 'Christy',
        'emp_phone' => 12345676890,
        'emp_sal' => 500
    ]);
```

### **Updating**

[](#updating)

To update a model, you may retrieve it, change an attribute, and use the update method.

```
DB::table('emp')
    ->where('emp_id', 11)
    ->update([
        'emp_city' => 'kochi',
        'emp_name' => 'Christy jos',
        'emp_phone' =>  123456789
    ]);
```

### **Updating a collection set, list, and map**

[](#updating-a-collection-set-list-and-map)

Update collections in a row. The method will be like

```
updateCollection(collection_type, column_name, operator, value);
```

Collection\_type is any of set, list or map.

Column\_name is the name of column to be updated.

Operator is + or -, + for adding the values to collection and - to remove the value from collection.

Value can be associative array for map type and array of string/number for list and set types.

```
DB::table('users')->where('id', 1)
    ->updateCollection('set', 'phn', '+', [123, 1234,12345])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('set', 'phn', '-', [123])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('list', 'hobbies', '+', ['reading', 'cooking', 'cycling'])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('set', 'phn', '+', [123, 1234,12345])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('set', 'phn', '-', [123])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('list', 'hobbies', '+', ['reading', 'cooking', 'cycling'])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('list', 'hobbies', '-', ['cooking'])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('map', 'friends', '+', [['John', 'Male'], ['Rex', 'Male']])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('map', 'friends', '-', ['John'])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('map', 'friends', '+', [['John', 'Male'], ['Rex', 'Male']])->update();

DB::table('users')->where('id', 1)
    ->updateCollection('map', 'friends', '-', ['John'])->update();
```

### **Deleting**

[](#deleting)

To delete a model, simply call the delete method on the instance. We can delete the rows in a table by using deleteRow method:

```
$emp = DB::table('emp')->where('emp_city', 'Kochi')->deleteRow();
```

We can also perform delete by the column in a table using deleteColumn method:

```
$emp = DB::table('emp')->where('emp_id', 3)->deleteColumn();
```

**Testing**
-----------

[](#testing)

I have created a docker container which has php7.0 and cassandra php driver installed. It is prefered to use docker for testing purposes.

Also there is a `run` executable which is there to ease use of docker container. It checks everything and makes sure all dependancies and the cassandra server are up and running and then passes your command to the container.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 69.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Recently: every ~35 days

Total

8

Last Release

2423d ago

PHP version history (2 changes)v1.0.1PHP ^5.6 || ^7.0 || ^7.1

v1.1.3PHP ^7.0 || ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/986a68f5c84dad440fbd21d1ac9624c0a289087e18aa24f4e512a45365f55468?d=identicon)[cipwebapp](/maintainers/cipwebapp)

---

Top Contributors

[![ShahinSorkh](https://avatars.githubusercontent.com/u/13497697?v=4)](https://github.com/ShahinSorkh "ShahinSorkh (94 commits)")[![cubetsijoy](https://avatars.githubusercontent.com/u/19144427?v=4)](https://github.com/cubetsijoy "cubetsijoy (25 commits)")[![rennymroy](https://avatars.githubusercontent.com/u/26161767?v=4)](https://github.com/rennymroy "rennymroy (10 commits)")[![cipwebapp](https://avatars.githubusercontent.com/u/55080435?v=4)](https://github.com/cipwebapp "cipwebapp (3 commits)")[![marcoslozina](https://avatars.githubusercontent.com/u/12201607?v=4)](https://github.com/marcoslozina "marcoslozina (3 commits)")[![cubettech](https://avatars.githubusercontent.com/u/2525619?v=4)](https://github.com/cubettech "cubettech (1 commits)")

---

Tags

laraveldatabasenosqlquery buildercassandracql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cipwebapp-laravel-cassandra/health.svg)

```
[![Health](https://phpackages.com/badges/cipwebapp-laravel-cassandra/health.svg)](https://phpackages.com/packages/cipwebapp-laravel-cassandra)
```

###  Alternatives

[cubettech/lacassa

Cassandra based query builder for laravel.

358.5k](/packages/cubettech-lacassa)[datastax/php-driver

DataStax PHP Driver for Apache Cassandra

437521.5k18](/packages/datastax-php-driver)[mroosz/php-cassandra

A pure-PHP client for Apache Cassandra and ScyllaDB with support for CQL binary protocol v3, v4 and v5 (Cassandra 2.1+ incl. 3.x-5.x; ScyllaDB 6.2 and 2025.x), synchronous and asynchronous APIs, prepared statements, batches, result iterators, object mapping, SSL/TLS, and LZ4 compression.

205.6k2](/packages/mroosz-php-cassandra)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[soosyze/queryflatfile

The Queryflatfile is PHP library for simple database not SQL

181.0k1](/packages/soosyze-queryflatfile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
