Module: DynamodbRecord::Query::ClassMethods

Defined in:
lib/dynamodb_record/query.rb

Overview

Module that provides class methods for queries against the DynamoDB database.

Instance Method Summary collapse

Instance Method Details

#all(opts = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/dynamodb_record/query.rb', line 10

def all(opts = {})
  options = default_options
  options.merge!(opts.slice(:limit))
  scan_pager = ScanPager.new(options, self)
  Collection.new(scan_pager, self)
end

#where(opts = {}) ⇒ Object

search table

Parameters:

  • opts (Hash) (defaults to: {})

    Limit of record and exclusive_start_key



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dynamodb_record/query.rb', line 19

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

  expression_attribute_names = {}
  expression_attribute_values = {}
  filter_expression = ''
  opts.each do |key, value|
    expression_attribute_names[:"##{key}"] = key.to_s
    expression_attribute_values[":#{key}"] = value
    filter_expression << if filter_expression.empty?
                           "##{key} = :#{key}"
                         else
                           " And ##{key} = :#{key}"
                         end
  end

  options = default_options
  options.merge!(limit:) if limit
  options.merge!(expression_attribute_names:) if expression_attribute_names.present?
  options.merge!(expression_attribute_values:) if expression_attribute_values.present?
  options.merge!(filter_expression:) if filter_expression.present?

  options.merge!(exclusive_start_key:) if exclusive_start_key
  # p options

  scan_pager = ScanPager.new(options, self)
  Collection.new(scan_pager, self)

  # DynamodbRecord::Collection.new(client.scan(options), self)
end