Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby
Branch: master
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
CHANGELOG
Gemfile Add a cassandra group
LICENSE
MIT-LICENSE
README.md
Rakefile
gotime-cassandra_object.gemspec

README.md

Cassandra Object

Build Status Code Climate

Cassandra Object uses ActiveModel to mimic much of the behavior in ActiveRecord.

Installation

Add the following to your Gemfile:

gem 'gotime-cassandra_object'

Change the version of Cassandra accordingly. Recent versions have not been backward compatible.

Defining Models

class Widget < CassandraObject::Base
  string :name
  string :description
  integer :price
  array :colors, unique: true

  validates :name, presence: :true

  before_create do
    self.description = "#{name} is the best product ever"
  end
end

Using with Cassandra

Add the cassandra-cql gem to Gemfile:

gem 'cassandra-cql'

Add a config/cassandra.yml:

development:
  adapter: cassandra
  keyspace: my_app_development
  servers: ["127.0.0.1:9160"]
  thrift:
    timeout: 20
    retries: 2

Using with Postgres HStore

Add the pg gem to your Gemfile:

gem 'pg'

And a config/cassandra.yml:

development:
  adapter: hstore

Creating and updating records

Cassandra Object has equivalent methods as ActiveRecord:

widget = Widget.new
widget.valid?
widget = Widget.create(name: 'Acme', price: 100)
widget.update_attribute(:price, 1200)
widget.update_attributes(price: 1200, name: 'Acme Corporation')
widget.attributes = {price: 300}
widget.price_was
widget.save
widget.save!

Finding records

widget = Widget.find(uuid)
widget = Widget.first
widgets = Widget.all
Widget.find_each do |widget|
  # Codez
end

Scoping

Some lightweight scoping features are available:

  Widget.where('color' => 'red')
  Widget.select(['name', 'color'])
  Widget.limit(10)
Something went wrong with that request. Please try again.