A library for persisting your objects into cassandra.
Ruby Shell
Pull request Compare This branch is 2 commits ahead, 6 commits behind NZKoz:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib made all not have nil spots after an object has been deleted Apr 8, 2010
test Ensure the after_create callback is called when create succeeds Mar 4, 2010
Gemfile Changed Gemfile and test_helper to work with bundler 0.9.10 Mar 4, 2010
README.markdown README changes Jan 9, 2010
Rakefile Add support for generating the config snippets automatically Jan 9, 2010
TODO Add support for generating the config snippets automatically Jan 9, 2010
cassandra_object.gemspec Make this a pre-release as it depends on another prerelease Jan 9, 2010


Cassandra Object

Cassandra Object provides a nice API for working with Cassandra. CassandraObjects are mostly duck-type compatible with ActiveRecord objects so most of your controller code should work ok. Note that they're mostly compatible, Cassandra has no support for dynamic queries, or sorting. So the following kinds of operations aren't supported and never will be.

  • :order
  • :conditions
  • :joins
  • :group

There isn't much in the way of documentation yet, but a few examples.

    class Customer < CassandraObject::Base
      attribute :first_name,    :type => :string
      attribute :last_name,     :type => :string
      attribute :date_of_birth, :type => :date
      attribute :signed_up_at,  :type => :time_with_zone

      validate :should_be_cool

      key :uuid

      index :date_of_birth

      association :invoices, :unique=>false, :inverse_of=>:customer


      def should_be_cool
        unless ["Michael", "Anika", "Evan", "James"].include?(first_name)
          errors.add(:first_name, "must be that of a cool person")

    class Invoice < CassandraObject::Base
      attribute :number, :type=>:integer
      attribute :total, :type=>:float
      attribute :gst_number, :type=>:string

      # indexes can have a single entry also.
      index :number, :unique=>true

      # bi-directional associations with read-repair support.
      association :customer, :unique=>true, :inverse_of=>:invoices

      # Read migration support
      migrate 1 do |attrs|
        attrs["total"] ||= rand(2000) / 100.0

      migrate 2 do |attrs|
        attrs["gst_number"] = "66-666-666"

      key :natural, :attributes => :number

    @invoice = Invoice.get("12345")
    @invoice.customer.invoices.all.include?(@invoice) # true


How do I make this work?

Here are some basic directions:

  1. git clone git://github.com/NZKoz/cassandra_object.git
  2. Run the bundler gem bundle
  3. Make sure the tests pass rake test

This gem has backwards compatibility with active support version 2.3.x, this is to enable people to use it with rails 2.3 applications. This backwards compatibility may not continue after the 1.0 release.

Should I use this in production?

Only if you're looking to help out with the development, there are a bunch of rough edges right now.

Why do you use a superclass and not a module.