Skip to content

tienle/cassandra-model

Repository files navigation

cassandra-model

Simple model support for Cassandra (github.com/fauna/cassandra)

Currently, it supports:

  • Serialisation (String, Integer, Float, Boolean, DateTime, JSON)

  • Callbacks

  • Validations

Getting started

gem install cassandra-model

Define

require 'cassandra-model'

class User << CassandraModel::Base
  column_family :Users

  key :username
  column :full_name
  column :created, :datetime
  column :profile, :json

  write_consistency_level Cassandra::Consistency::ALL
  before_save :set_created_at

  validation do
    errors << "full name required" if full_name.blank?
  end

private

  def set_created_at
    self.created = Time.now
  end
end

CRUD

User.create(:username => 'foo', :full_name => 'foo bar')

foo = User.new(:username => 'foo', :full_name => 'foo bar')
foo.save

foo.full_name = 'foo baz'
foo.save

foo = User['foo']
foo = User.get('foo')

foo.destroy

Copyright © 2010 Tien Le. See LICENSE for details.

About

Minimal models for cassandra

Resources

License

Stars

Watchers

Forks

Packages

No packages published