lib/dyna_model/table.rb in dyna_model-0.0.2 vs lib/dyna_model/table.rb in dyna_model-0.0.3

- old
+ new

@@ -166,19 +166,24 @@ end def get_item(hash_key, options={}) options[:consistent_read] = false unless options[:consistent_read] options[:return_consumed_capacity] ||= :none # "NONE" # || "TOTAL" - options[:select] ||= [] + options[:select] ||= [] # no :projected option, always an array or :all + raise ArgumentError, "Invalid :select. GetItem :select must be an Array (blank for :all)" unless options[:select].is_a?(Array) get_item_request = { table_name: @model.dynamo_db_table_name(options[:shard_name]), key: hash_key_item_param(hash_key), consistent_read: options[:consistent_read], return_consumed_capacity: RETURNED_CONSUMED_CAPACITY[options[:return_consumed_capacity]] } - get_item_request.merge!( attributes_to_get: [options[:select]].flatten ) unless options[:select].blank? + if options[:select].blank? + options[:select] = :all # for obj_from_attrs + else + get_item_request.merge!( attributes_to_get: [options[:select]].flatten ) + end @model.dynamo_db_client.get_item(get_item_request) end # == options # * consistent_read @@ -271,11 +276,11 @@ @model.dynamo_db_client.query(query_request) end def batch_get_item(keys, options={}) options[:return_consumed_capacity] ||= :none - options[:select] ||= [] + options[:select] ||= [] # no :projected option, always an array or :all options[:consistent_read] = false unless options[:consistent_read] raise ArgumentError, "must include between 1 - 100 keys" if keys.size == 0 || keys.size > 100 keys_request = [] keys.each do |k| @@ -293,10 +298,14 @@ keys_request << key_request end request_items_request = {} request_items_request.merge!( keys: keys_request ) - request_items_request.merge!( attributes_to_get: [options[:select]].flatten ) unless options[:select].blank? + if options[:select].blank? + options[:select] = :all # for obj_from_attrs + else + request_items_request.merge!( attributes_to_get: [options[:select]].flatten ) + end request_items_request.merge!( consistent_read: options[:consistent_read] ) if options[:consistent_read] batch_get_item_request = { request_items: { @model.dynamo_db_table_name(options[:shard_name]) => request_items_request }, return_consumed_capacity: RETURNED_CONSUMED_CAPACITY[options[:return_consumed_capacity]] }