PHP code example of shso / laravel-cassandra

1. Go to this page and download the library: Download shso/laravel-cassandra library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shso / laravel-cassandra example snippets


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

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

# 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,
],

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

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

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

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

$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']);

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

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

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

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

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

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

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

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

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

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

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

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

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

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
    ]);

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

updateCollection(collection_type, column_name, operator, value);

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();

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

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