lib/dynamoid/adapter.rb in dynamoid-0.3.2 vs lib/dynamoid/adapter.rb in dynamoid-0.4.0
- old
+ new
@@ -65,11 +65,12 @@
# @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
#
# @since 0.2.0
- def read(table, ids, range_key = nil)
+ def read(table, ids, options = {})
+ range_key = options[:range_key]
if ids.respond_to?(:each)
ids = ids.collect{|id| range_key ? [id, range_key] : id}
if Dynamoid::Config.partitioning?
results = benchmark('Partitioned Batch Get Item', ids) {batch_get_item(table => id_with_partitions(ids))}
{table => result_for_partition(results[table])}
@@ -80,11 +81,11 @@
if Dynamoid::Config.partitioning?
ids = range_key ? [[ids, range_key]] : ids
results = benchmark('Partitioned Get Item', ids) {batch_get_item(table => id_with_partitions(ids))}
result_for_partition(results[table]).first
else
- benchmark('Get Item', ids) {get_item(table, ids, range_key)}
+ benchmark('Get Item', ids) {get_item(table, ids, options)}
end
end
end
# Delete an item from a table. If partitioning is turned on, deletes all partitioned keys as well.
@@ -92,31 +93,31 @@
# @param [String] table the name of the table to write the object to
# @param [String] id the id of the record
# @param [Number] range_key the range key of the record
#
# @since 0.2.0
- def delete(table, id, range_key = nil)
+ def delete(table, id, options = {})
if Dynamoid::Config.partitioning?
benchmark('Delete Item', id) do
- id_with_partitions(id).each {|i| delete_item(table, i, range_key)}
+ id_with_partitions(id).each {|i| delete_item(table, i, options)}
end
else
- benchmark('Delete Item', id) {delete_item(table, id, range_key)}
+ benchmark('Delete Item', id) {delete_item(table, id, options)}
end
end
# Scans a table. Generally quite slow; try to avoid using scan if at all possible.
#
# @param [String] table the name of the table to write the object to
# @param [Hash] scan_hash a hash of attributes: matching records will be returned by the scan
#
# @since 0.2.0
- def scan(table, query)
+ def scan(table, query, opts = {})
if Dynamoid::Config.partitioning?
- results = benchmark('Scan', table, query) {adapter.scan(table, query)}
+ results = benchmark('Scan', table, query) {adapter.scan(table, query, opts)}
result_for_partition(results)
else
- adapter.scan(table, query)
+ adapter.scan(table, query, opts)
end
end
[:batch_get_item, :create_table, :delete_item, :delete_table, :get_item, :list_tables, :put_item].each do |m|
# Method delegation with benchmark to the underlying adapter. Faster than relying on method_missing.