Module: CassandraORM::Model::Finder
- Included in:
- CassandraORM::Model
- Defined in:
- lib/cassandra-orm/model/finder.rb
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #count ⇒ Object
- #find(attrs, options = {}) ⇒ Object
- #find!(attrs, options = {}) ⇒ Object
- #find_all(attrs = {}, options = {}) ⇒ Object
- #first(options = {}) ⇒ Object
Instance Method Details
#all(options = {}) ⇒ Object
34 35 36 |
# File 'lib/cassandra-orm/model/finder.rb', line 34 def all = {} find_all({}, ) end |
#count ⇒ Object
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, = {} all = find_all attrs, .merge(limit: 1) [:async] ? AsyncWrapper.new(all, :first) : all.first end |
#find!(attrs, options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/cassandra-orm/model/finder.rb', line 28 def find! attrs, = {} result = find attrs, .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 = {}, = {} attrs = attrs.symbolize_keys invalid = attrs.keys - attributes keys = (attributes & attrs.keys) + invalid values = keys.map { |key| attrs[key] } limit = .delete :limit async = [:async] result = _find_all(keys, values, limit: limit, **) 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 = {} find({}, ) end |