Module: CassandraModel::Persistence::ClassMethods

Defined in:
lib/cassandra-model/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#read_consistency_level(level) ⇒ Object



67
68
69
# File 'lib/cassandra-model/persistence.rb', line 67

def read_consistency_level(level)
  @read_consistency_level = level
end

#write_consistency_level(level) ⇒ Object



63
64
65
# File 'lib/cassandra-model/persistence.rb', line 63

def write_consistency_level(level)
  @write_consistency_level = level
end

Instance Method Details

#[](key) ⇒ Object

Raises:



75
76
77
78
79
# File 'lib/cassandra-model/persistence.rb', line 75

def [](key)
  record = get(key)
  raise RecordNotFound, "cannot find out key=`#{key}` in `#{column_family}`" unless record
  record
end

#all(*args) ⇒ Object



88
89
90
# File 'lib/cassandra-model/persistence.rb', line 88

def all(*args)
  find(:all, *args)
end

#create(attributes) ⇒ Object



57
58
59
60
61
# File 'lib/cassandra-model/persistence.rb', line 57

def create(attributes)
  new(attributes).tap do |object|
    object.save
  end
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
# File 'lib/cassandra-model/persistence.rb', line 81

def exists?(key)
  return false if key.nil? || key == ''
  #connection.exists?(column_family, key)
  key = validate_key_type(key)
  !connection.get(column_family, key).empty?
end

#find(*args) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cassandra-model/persistence.rb', line 100

def find(*args)
  options = args.extract_options!
  validate_find_options(options)
  # set_readonly_option!(options) Not Implemented Yet

  case args.first
  when :first then find_initial(options)
  when :last  then find_last(options)
  when :all   then find_every(options)
  else             find_from_ids(args, options)
  end
end

#first(*args) ⇒ Object



92
93
94
# File 'lib/cassandra-model/persistence.rb', line 92

def first(*args)
  find(:first, *args)
end

#get(key, options = {}) ⇒ Object



71
72
73
# File 'lib/cassandra-model/persistence.rb', line 71

def get(key, options = {})
  find_one(key, options)
end

#last(*args) ⇒ Object



96
97
98
# File 'lib/cassandra-model/persistence.rb', line 96

def last(*args)
  find(:last, *args)
end

#select(key, columns, options = {}) ⇒ Object

key column options



120
121
122
# File 'lib/cassandra-model/persistence.rb', line 120

def select(key, columns, options = {})
  find_select(key, columns, options)
end

#where(search_clauses, select = [], options = {}) ⇒ Object



113
114
115
# File 'lib/cassandra-model/persistence.rb', line 113

def where(search_clauses, select = [], options = {})
  find_where(search_clauses, select, options)
end