lib/dynamoid/adapter.rb in dynamoid-0.6.1 vs lib/dynamoid/adapter.rb in dynamoid-0.7.0

- old
+ new

@@ -63,29 +63,32 @@ # automatically. Finally, if a range key is present, it will also interpolate that into the ids so that the batch get will acquire the # correct record. # # @param [String] table the name of the table to write the object to # @param [Array] ids to fetch, can also be a string of just one id - # @param [Number] range_key the range key of the record + # @param [Hash] options: Passed to the underlying query. The :range_key option is required whenever the table has a range key, + # unless multiple ids are passed in and Dynamoid::Config.partitioning? is turned off. # # @since 0.2.0 def read(table, ids, options = {}) - range_key = options[:range_key] + range_key = options.delete(:range_key) + if ids.respond_to?(:each) ids = ids.collect{|id| range_key ? [id, range_key] : id} if Dynamoid::Config.partitioning? - results = batch_get_item(table => id_with_partitions(ids)) + results = batch_get_item({table => id_with_partitions(ids)}, options) {table => result_for_partition(results[table],table)} else - batch_get_item(table => ids) + batch_get_item({table => ids}, options) end else if Dynamoid::Config.partitioning? ids = range_key ? [[ids, range_key]] : ids - results = batch_get_item(table => id_with_partitions(ids)) + results = batch_get_item({table => id_with_partitions(ids)}, options) result_for_partition(results[table],table).first else + options[:range_key] = range_key if range_key get_item(table, ids, options) end end end @@ -183,11 +186,11 @@ if table.range_key range_key_name = table.range_key.name.to_sym final_hash = {} - + results.each do |record| test_record = final_hash[record[range_key_name]] if test_record.nil? || ((record[range_key_name] == test_record[range_key_name]) && (record[:updated_at] > test_record[:updated_at])) #get ride of our partition and put it in the array with the range key @@ -252,14 +255,12 @@ #loop and query on each of the partition ids ids.each do |id| modified_options[:hash_value] = id query_result = Dynamoid::Adapter::AwsSdk.query(table_name, modified_options) - query_result = [query_result] if !query_result.is_a?(Array) - - results = results + query_result unless query_result.nil? + results += query_result.inject([]){|array, result| array += [result]} if query_result.any? end - + result_for_partition results, table_name end end end end