Created
July 2, 2012 08:51
-
-
Save bru/3032084 to your computer and use it in GitHub Desktop.
Quicksandra - light wrapper around Cassandra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cassandra_helper' | |
module Quicksandra | |
attr_accessor :key | |
attr_reader :column_names | |
def get(key) | |
cassandra.get :CdfItems, key.to_s | |
end | |
def multi_get | |
cassandra.multi_get :CdfItems, keys.map(&:to_s) | |
end | |
def create(args={}) | |
new(args).save | |
end | |
def columns(*cols) | |
cols.each do |column| | |
register_column(column.to_sym) | |
end | |
end | |
def column_family(cf=nil) | |
return @cf if @cf && cf.nil? | |
@cf = cf.to_sym | |
end | |
def register_column(col) | |
@column_names ||= [] | |
attr_accessor col | |
@column_names << col | |
end | |
def cassandra | |
CassandraHelper.cassandra | |
end | |
module InstanceMethods | |
def initialize(args={}) | |
args.each do |k, v| | |
self.send("#{k}=", v) | |
end | |
end | |
def save | |
cassandra.insert(column_family, self.key) | |
end | |
def cassandra | |
self.class.cassandra | |
end | |
end | |
include InstanceMethods | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment