Skip to content

Latest commit

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

FluentCQL

Dependency

Initialize

$connection = newCassandra\Connection(['127.0.0.1'], 'my_keyspace');

FluentCQL\Query

  • SELECT COMMAND
$query = FluentCQL\Query::select('count(*)')
->from('table_name')
->where('id = ?', 123);
$query->assemble(); // SELECT count(*) FROM table_name where id = 123$query->setDbAdapter($connection)->querySync(); // execute query syncronously
  • INSERT COMMAND
$query = FluentCQL\Query::insertInto('table_name')
->clause('(from_id, to_id, updated_uuid)')
->values('(?, ?, ?)', 321, 123, new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509'));
$query->assemble(); // INSERT INTO table_name (from_id, to_id, updated_uuid) values (321, 123, 2dc65ebe-300b-11e4-a23b-ab416c39d509);$query->setDbAdapter($connection)->querySync(); // execute query syncronously
  • UPDATE COMMAND
$query = FluentCQL\Query::update('table_name')
->set('a = :a, b = :b', $a, $b)
->where('c = :c', $c)
->and('d = :d', $d)
->ifExists();
$query->assemble(); // 'UPDATE table_name SET a = :a, b = :b WHERE c = :c AND d = :d'$query->setDbAdapter($connection)->querySync(); // execute query syncronously
  • DELETE COMMAND
$query = FluentCQL\Query::delete()
->from('table_name')
->where('id = ?', 123);
$query->assemble(); // DELETE FROM table_name where id = 123$query->setDbAdapter($connection)->querySync(); // execute query syncronously

FluentCQL\Table

Table Class Definition

class Friendship extends \FluentCQL\Table{
protectedstatic$_name = 'friendship';
protectedstatic$_primary = array('from_id', 'to_id');
protectedstatic$_columns = array(
'from_id' => Type\Base::BIGINT,
'to_id' => Type\Base::BIGINT,
'updated_uuid' => Type\Base::TIMEUUID,
);
protectedstatic$_readConsistency = 0x0001;
protectedstatic$_writeConsistency = 0x0002;
}

Initialize

$connection = newCassandra\Connection(['127.0.0.1'], 'my_keyspace');
FluentCQL\Table::setDefaultDbAdapter($connection);

Queries

  • Table::find()
$response = Friendship::find(321, 123); // synchronously query and get binary response $response->fetchAll(); // get all rows in a SplFixedArray$response->fetchRow(); // get first row in a ArrayObject from response
  • Table::select()
// this way totally equal to Friendship::find()$response = Friendship::select()
->where('from_id = ? AND to_id = ?', 321, 123)
->querySync();
  • Table::insert()
$response = Friendship::insert()
->clause('(from_id, to_id, updated_uuid)')
->values('(?, ?, ?)', 321, 123, new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509'))
->querySync();
  • Table::update()
$response = Friendship::update()
->set('update_uuid = ?', new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509'))
->where('from_id = ? AND to_id = ?', 321, 123)
->querySync();
  • Table::delete()
$response = Friendship::delete()
->where('from_id = ? AND to_id = ?', 321, 123)
->if('updated_uuid = ?', new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509'))
->querySync();
  • Table::insertRow($data)
// Insert a row through an array.$response = Friendship::insertRow([
'from_id' => 123,
'to_id' => 321,
'updated_uuid'=> '2dc65ebe-300b-11e4-a23b-ab416c39d509',
])->querySync();
  • Table::updateRow($primary, $data)
// Update a row by primary key.$response = Friendship::updateRow([123, 321], ['updated_uuid'=> '2dc65ebe-300b-11e4-a23b-ab416c39d509'])->querySync();
  • Table::deleteRow($primary)
// Delete a row or rows by primary key.$response = Friendship::deleteRow([123])->querySync();

Custom Consistency and Options

$query = newFluentCQL\Query();
$query->setConsistency(0x0001)
->setOptions(['page_size' => 20]);

ActiveRecord-like Usage

$post = newFriendship(); $post['from_id'] = 123;
$post['to_id'] = 321;
$post['updated_uuid'] = '2dc65ebe-300b-11e4-a23b-ab416c39d509';
$post->save();

About

an php CQL building library

Resources

Stars

6 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages