Module: DynamoRecord::Query::ClassMethods
- Defined in:
- lib/dynamo_record/query.rb
Instance Method Summary collapse
- #all(opts = {}) ⇒ Object
- #find_by_hash_and_range(hash_key, range_key = nil) ⇒ Object
- #where(condition = {}) ⇒ Object
Instance Method Details
#all(opts = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/dynamo_record/query.rb', line 6 def all(opts = {}) = self. .merge!(opts.slice(:limit)) response = self.client.scan() DynamoRecord::Collection.new(response, self) end |
#find_by_hash_and_range(hash_key, range_key = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dynamo_record/query.rb', line 29 def find_by_hash_and_range(hash_key, range_key=nil) key_conditions = {} key_conditions[self.hash_key] = { attribute_value_list: [hash_key], comparison_operator: 'EQ' } if range_key key_conditions[self.range_key] = { attribute_value_list: [range_key], comparison_operator: 'EQ' } end = self. .merge!(key_conditions: key_conditions) response = self.client.query() DynamoRecord::Collection.new(response, self) end |
#where(condition = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dynamo_record/query.rb', line 14 def where(condition = {}) attribute = condition.first.first.to_s value = condition.first.second key_conditions = {} key_conditions[attribute] = { attribute_value_list: [value], comparison_operator: 'EQ' } index_name = "#{attribute}-index" = self. .merge!(key_conditions: key_conditions, index_name: index_name) response = self.client.query() DynamoRecord::Collection.new(response, self) end |