PHP code example of a-h-abid / eloquent-cassandra
1. Go to this page and download the library: Download a-h-abid/eloquent-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/ */
a-h-abid / eloquent-cassandra example snippets
AHAbid\EloquentCassandra\CassandraServiceProvider::class,
$capsule->getDatabaseManager()->extend('cassandra', function($config)
{
return new AHAbid\EloquentCassandra\Connection($config);
});
$app->configure('database');
$app->register(AHAbid\EloquentCassandra\CassandraServiceProvider::class);
'default' => env('DB_CONNECTION', 'cassandra'),
'cassandra' => [
'driver' => 'cassandra',
'scheme' => env('DB_SCHEME', 'tcp'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 9042),
'keyspace' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'page_size' => env('DB_PAGE_SIZE', 5000),
'consistency' => Cassandra::CONSISTENCY_LOCAL_ONE,
'timeout' => null,
'connect_timeout' => 5.0,
'request_timeout' => 12.0,
'ssl' => [
'verify_peer' => nv('DB_SSL_VERIFY_PEER', false),
'trusted_cert' => nv('DB_SSL_TRUSTED_CERT_FILE', null),
'client_cert' => nv('DB_SSL_CLIENT_CERT_FILE', null),
'private_cert' => nv('DB_SSL_PRIVATE_CERT_FILE', null),
'private_passphrase' => nv('DB_SSL_PRIVATE_PASSPHRASE', null),
],
],
'cassandra' => [
'driver' => 'cassandra',
'host' => ['192.168.0.1', '192.168.0.2'], //or '192.168.0.1,192.168.0.2'
'port' => env('DB_PORT', 9042),
'keyspace' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'page_size' => env('DB_PAGE_SIZE', 5000),
'consistency' => Cassandra::CONSISTENCY_LOCAL_ONE,
'timeout' => null,
'connect_timeout' => 5.0,
'request_timeout' => 12.0,
],
$users = User::all();
$user = User::where('email', '[email protected] ')->first();
$user = User::find(new \Cassandra\Uuid("7e4c27e2-1991-11e8-accf-0ed5f89f718b"))
$users = DB::table('users')->get();
$user = DB::table('users')->where('name', 'John')->first();
$user = DB::connection('cassandra')->table('users')->get();
$comments = Comments::setPageSize(500)->get(); // will return all comments, not 500
$comments = Comments::setPageSize(500)->getPage(); // will return collection with 500 results
$comments = Comments::setPaginationStateToken($token)->getPage();
$comments = $comments->nextPage();
$comments = $comments->getNextPageToken();
$comments->appendNextPage();
$comments->isLastPage();
$rows = $commants->getRows();
$users = User::setPageSize(1000)->getPage();
while(!$users->isLastPage()) {
foreach($users as $user) {
// here you can write a lines to csv file
}
$users = $users->nextPage();
}
public function getComments(Request $request) {
...
$comments = Comment::setPageSize(50)
->setPaginationStateToken($request->get('nextPageToken', null)
->getPage();
...
return response()->json([
...
'comments' => $comments,
'nextPageToken' => !$comments->isLastPage() ? $comments->getNextPageToken() : null,
...
]);
}
$users = User::from('users_by_country_view')->where('country', 'USA')->get();