module Dynamodb::Querying::ClassMethods

Public Instance Methods

_key_definitions(h_value, r_value = nil) click to toggle source
# File lib/dynamodb/querying.rb, line 84
def _key_definitions(h_value, r_value = nil)
  attrs = { hash_key => h_value }
  attrs.merge!({ range_key => r_value }) if r_value
  attrs
end
create(data = {}, conditions = {}) click to toggle source
# File lib/dynamodb/querying.rb, line 61
def create(data = {}, conditions = {})
  object = new(data)

  return object unless object.valid?
  # TODO: Need to test conditions - condition_expressions
  object.generate_timestamps
  put_item(table_name, object.data, conditions)

  object
rescue Aws::DynamoDB::Errors::ServiceError => e
  object.handle_error(e)
  object
end
find(h_key, r_key = nil) click to toggle source
# File lib/dynamodb/querying.rb, line 50
def find(h_key, r_key = nil)
  get_item(table_name, _key_definitions(h_key, r_key)) || not_found
rescue Aws::DynamoDB::Errors::ServiceError => e
  not_found
end
find_or_initialize_by(h_key, r_key = nil) click to toggle source
# File lib/dynamodb/querying.rb, line 56
def find_or_initialize_by(h_key, r_key = nil)
  response = find(h_key, r_key)
  response.is_a?(Hash) ? new(_key_definitions(h_key, r_key)) : response
end