module Dynamo::Record::Model::ClassMethods
Public Instance Methods
composite_key(*args)
click to toggle source
# File lib/dynamo/record/model.rb, line 104 def composite_key(*args) args.join(COMPOSITE_DELIMITER) end
find(opts)
click to toggle source
Calls superclass method
# File lib/dynamo/record/model.rb, line 30 def find(opts) super(opts).tap do |record| unless record name = self.name.demodulize conditions = opts.map { |k, v| "#{k}=#{v}" }.join(', ') error = "Couldn't find #{name} with #{conditions}" raise Aws::Record::Errors::NotFound, error end end end
find_all_by_gsi_hash_and_range_keys(gsi_name, hash_key_value, range_key_value)
click to toggle source
# File lib/dynamo/record/model.rb, line 50 def find_all_by_gsi_hash_and_range_keys(gsi_name, hash_key_value, range_key_value) gsi_config = global_secondary_indexes[gsi_name.to_sym] find_all_by_index_hash_and_range_keys( hash_config: { name: gsi_config[:hash_key], value: hash_key_value }, range_config: { name: gsi_config[:range_key], value: range_key_value }, index_name: gsi_name.to_s ) end
find_all_by_gsi_hash_key(gsi_name, hash_key_value, opts = {})
click to toggle source
# File lib/dynamo/record/model.rb, line 45 def find_all_by_gsi_hash_key(gsi_name, hash_key_value, opts = {}) hash_key_name = global_secondary_indexes[gsi_name.to_sym][:hash_key] find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts, gsi_name.to_s) end
find_all_by_hash_key(hash_key_value, opts = {})
click to toggle source
# File lib/dynamo/record/model.rb, line 41 def find_all_by_hash_key(hash_key_value, opts = {}) find_all_by_index_and_hash_key(hash_key, hash_key_value, opts) end
find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts = {}, index_name = nil)
click to toggle source
# File lib/dynamo/record/model.rb, line 73 def find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts = {}, index_name = nil) query_options = { select: 'ALL_ATTRIBUTES', key_condition_expression: "#{hash_key_name} = :hash_key_value", expression_attribute_values: { ':hash_key_value': hash_key_value }, scan_index_forward: true } query_options[:index_name] = index_name if index_name query_options.merge!(opts) query(query_options) end
find_all_by_index_hash_and_range_keys(hash_config:, range_config:, index_name: nil, scan_index_forward: true, limit: nil)
click to toggle source
# File lib/dynamo/record/model.rb, line 87 def find_all_by_index_hash_and_range_keys(hash_config:, range_config:, index_name: nil, scan_index_forward: true, limit: nil) range_expression = range_config[:expression] || "#{range_config[:name]} = :rkv" query_options = { select: 'ALL_ATTRIBUTES', key_condition_expression: "#{hash_config[:name]} = :hkv AND #{range_expression}", expression_attribute_values: { ':hkv': hash_config[:value], ':rkv': range_config[:value] }, scan_index_forward: scan_index_forward, limit: limit } query_options[:index_name] = index_name if index_name query(query_options) end
find_all_by_lsi_hash_and_range_keys(lsi_name, hash_key_value, range_key_value)
click to toggle source
# File lib/dynamo/record/model.rb, line 64 def find_all_by_lsi_hash_and_range_keys(lsi_name, hash_key_value, range_key_value) lsi_config = local_secondary_indexes[lsi_name.to_sym] find_all_by_index_hash_and_range_keys( hash_config: { name: lsi_config[:hash_key], value: hash_key_value }, range_config: { name: lsi_config[:range_key], value: range_key_value }, index_name: lsi_name.to_s ) end
find_all_by_lsi_hash_key(lsi_name, hash_key_value, opts = {})
click to toggle source
# File lib/dynamo/record/model.rb, line 59 def find_all_by_lsi_hash_key(lsi_name, hash_key_value, opts = {}) hash_key_name = local_secondary_indexes[lsi_name.to_sym][:hash_key] find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts, lsi_name.to_s) end
max_retries()
click to toggle source
# File lib/dynamo/record/model.rb, line 112 def max_retries DEFAULT_MAX_RETRIES end
scan()
click to toggle source
Calls superclass method
# File lib/dynamo/record/model.rb, line 24 def scan raise 'no scanning in production' if Rails.env.production? super end
split_composite(string)
click to toggle source
# File lib/dynamo/record/model.rb, line 108 def split_composite(string) string.split(COMPOSITE_DELIMITER) end
table_name()
click to toggle source
# File lib/dynamo/record/model.rb, line 20 def table_name [Rails.configuration.dynamo['prefix'], name.tableize].join('-').tr('/', '.') end