Module: CassandraORM::Model::Finder

Included in:
CassandraORM::Model
Defined in:
lib/cassandra-orm/model/finder.rb

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



34
35
36
# File 'lib/cassandra-orm/model/finder.rb', line 34

def all options = {}
  find_all({}, options)
end

#countObject



42
43
44
# File 'lib/cassandra-orm/model/finder.rb', line 42

def count
  execute('count', "SELECT COUNT(*) FROM #{table_name}").first['count']
end

#find(attrs, options = {}) ⇒ Object



23
24
25
26
# File 'lib/cassandra-orm/model/finder.rb', line 23

def find attrs, options = {}
  all = find_all attrs, options.merge(limit: 1)
  options[:async] ? AsyncWrapper.new(all, :first) : all.first
end

#find!(attrs, options = {}) ⇒ Object

Raises:



28
29
30
31
32
# File 'lib/cassandra-orm/model/finder.rb', line 28

def find! attrs, options = {}
  result = find attrs, options.except(:async)
  raise RecordNotFound unless result
  result
end

#find_all(attrs = {}, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cassandra-orm/model/finder.rb', line 8

def find_all attrs = {}, options = {}
  attrs = attrs.symbolize_keys
  invalid = attrs.keys - attributes
  keys = (attributes & attrs.keys) + invalid
  values = keys.map { |key| attrs[key] }
  limit = options.delete :limit
  async = options[:async]
  result = _find_all(keys, values, limit: limit, **options)
  if async
    AsyncWrapper.new(result, :get) { |all| all.map(&method(:_fetch)) }
  else
    result.map(&method(:_fetch))
  end
end

#first(options = {}) ⇒ Object



38
39
40
# File 'lib/cassandra-orm/model/finder.rb', line 38

def first options = {}
  find({}, options)
end