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
- #all(opts = {}) ⇒ Object
-
#where(opts = {}) ⇒ Object
search table.
Instance Method Details
#all(opts = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/dynamodb_record/query.rb', line 9 def all(opts = {}) = .merge!(opts.slice(:limit)) response = client.scan() DynamodbRecord::Collection.new(response, self) end |
#where(opts = {}) ⇒ Object
search table
18 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 |
# File 'lib/dynamodb_record/query.rb', line 18 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}".to_sym] = key.to_s expression_attribute_values[":#{key}"] = value filter_expression << if filter_expression.empty? "##{key} = :#{key}" else " And ##{key} = :#{key}" end end = .merge!(limit:) if limit .merge!(expression_attribute_names:) if expression_attribute_names.present? .merge!(expression_attribute_values:) if expression_attribute_values.present? .merge!(filter_expression:) if filter_expression.present? if exclusive_start_key.present? json_string_decode = Base64.urlsafe_decode64(exclusive_start_key) decode = JSON.parse(json_string_decode) .merge!(exclusive_start_key: decode) end DynamodbRecord::Collection.new(client.scan(), self) end |