module TinyDyno::HashKey

Public Instance Methods

keys_as_selector() click to toggle source

return all defined hash keys on an instantiated object for further use in DynamoDB queries, i.e. to look up an object

# File lib/tiny_dyno/hash_key.rb, line 18
def keys_as_selector
  selector = {}
  primary_key_field = self.class.primary_key[:attribute_name]
  selector[primary_key_field.to_sym] = TinyDyno::Adapter.aws_attribute(field_type: fields[primary_key_field].options[:type], value: attributes[primary_key_field])
  unless range_key.empty?
    range_key_field = self.class.range_key[:attribute_name]
    selector[range_key_field.to_sym] = TinyDyno::Adapter.aws_attribute(field_type: fields[range_key_field].options[:type], value: attributes[range_key_field])
  end
  return nil if selector.empty?
  selector
end