An unopinionated Cassandra client built on top of the Datastax Cassandra Driver. Cassava provides a higher-level statement execution interface while still supporting asynchronous queries and the ability to connect to multiple clusters.
If prepared incorrectly, the cassava plant can produce cyanide, a deadly compound when consumed.
Add this line to your application's Gemfile:
gem 'cassava_rb', github: 'backupify/cassava'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cassava_rb
Creating a client requires a Cassandra::Session
object:
require 'cassava'
cluster = Cassandra.cluster
session = cluster.connect('a_keyspace')
client = Cassava::Client.new(session)
client.insert(:table, :id => 'id', :a => 1, :b => 'b')
A select statement is built and then executed. To create a statement that will select all columns:
statement = client.select(:table)
This statement can then be further refined:
new_statement = statement.where(:id => 'id').limit(2)
and then executed:
result = new_statement.execute
or executed asynchronously:
promise = new_statement.execute_async
To select only certain rows, provide those rows to the select method:
client.select(:table, [:id, :a, :b]).execute
Ordering can be specified using the order method:
client.select(:table).where('id = ? AND a > ?', 1, 'b').order(:a, :desc).execute
Filtering is permitting with the allow_filtering
method.
Multiple records can be specified by passing an array of values, but this will generate an CQL IN query and should be used with caution:
client.select(:table).where(:id => 1, :a => [1, 2])
To delete an entire record:
client.delete(table).where(:id => 1, :a => 1).execute
To delete only certain columns:
client.delete(table, [:c, :d]).where(:id => 1, :a => 1).execute
Note here that :id
and :a
must be part of the primary key and :c
and :d
must not be part of the primary key.
- Fork it ( https://github.com/backupify/cassava/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request