Module: DynamoRecord::Query::ClassMethods

Defined in:
lib/dynamo_record/query.rb

Instance Method Summary collapse

Instance Method Details

#all(opts = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/dynamo_record/query.rb', line 6

def all(opts = {})
  options = self.default_options
  options.merge!(opts.slice(:limit))

  response = self.client.scan(options)
  DynamoRecord::Collection.new(response, self)
end

#where(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dynamo_record/query.rb', line 14

def where(opts={})
  limit = opts.delete(:limit)
  exclusive_start_key = opts.delete(:exclusive_start_key)

  key_conditions = {}
  opts.each do |key, value|
    key_conditions[key] = { attribute_value_list: [value], 
                             comparison_operator: 'EQ' } 
  end

  options = self.default_options
  options.merge!(key_conditions: key_conditions)
  options.merge!(limit: limit) if limit
  options.merge!(exclusive_start_key: exclusive_start_key) if exclusive_start_key

  response = self.client.query(options)
  DynamoRecord::Collection.new(response, self)
end