lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
def batch_get_item(table_ids, options = {})
        request_items = Hash.new{|h, k| h[k] = []}
        return request_items if table_ids.all?{|k, v| v.empty?}

        table_ids.each do |t, ids|
          next if ids.empty?
          tbl = describe_table(t)
          hk  = tbl.hash_key.to_s
          rng = tbl.range_key.to_s

          keys = if rng.present?
            Array(ids).map do |h,r|
              { hk => h, rng => r }
            end
          else
            Array(ids).map do |id|
              { hk => id }
            end
          end

          request_items[t] = {
            keys: keys
          }
        end

        results = client.batch_get_item(
          request_items: request_items
        )

        ret = Hash.new([].freeze) # Default for tables where no rows are returned
        results.data[:responses].each do |table, rows|
          ret[table] = rows.collect { |r| result_item_to_hash(r) }
        end
        ret
      end
# Get many items at once from DynamoDB. More efficient than getting each item individually.
#
# @example Retrieve IDs 1 and 2 from the table testtable
#   Dynamoid::Adapter::AwsSdkV2.batch_get_item({'table1' => ['1', '2']})
#
# @param [Hash] table_ids the hash of tables and IDs to retrieve
# @param [Hash] options to be passed to underlying BatchGet call
#
# @return [Hash] a hash where keys are the table names and the values are the retrieved items
#
# @since 1.0.0
#
# @todo: Provide support for passing options to underlying batch_get_item http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#batch_get_item-instance_method
Get many items at once from DynamoDB. More efficient than getting each item individually.
Get many items at once from DynamoDB . More efficient than getting each item individually .
def batch_get_item(table_ids, options = {})
        request_items = Hash.new{|h, k| h[k] = []}
        return request_items if table_ids.all?{|k, v| v.empty?}
        table_ids.each do |t, ids|
          next if ids.empty?
          tbl = describe_table(t)
          hk  = tbl.hash_key.to_s
          rng = tbl.range_key.to_s
          keys = if rng.present?
            Array(ids).map do |h,r|
              { hk => h, rng => r }
            end
          else
            Array(ids).map do |id|
              { hk => id }
            end
          end
          request_items[t] = {
            keys: keys
          }
        end
        results = client.batch_get_item(
          request_items: request_items
        )
        ret = Hash.new([].freeze) 
        results.data[:responses].each do |table, rows|
          ret[table] = rows.collect { |r| result_item_to_hash(r) }
        end
        ret
      end
def batch_get_item ( table_ids , options = { } ) request_items = Hash . new { | h , k | h [ k ] = [ ] } return request_items if table_ids . all? { | k , v | v . empty? } table_ids . each do | t , ids | next if ids . empty? tbl = describe_table ( t ) hk = tbl . hash_key . to_s rng = tbl . range_key . to_s keys = if rng . present? Array ( ids ) . map do | h , r | { hk => h , rng => r } end else Array ( ids ) . map do | id | { hk => id } end end request_items [ t ] = { keys : keys } end results = client . batch_get_item ( request_items : request_items ) ret = Hash . new ( [ ] . freeze ) results . data [ :responses ] . each do | table , rows | ret [ table ] = rows . collect { | r | result_item_to_hash ( r ) } end ret end
Get many items at once from DynamoDB.
Get many items at once from DynamoDB .
# Default for tables where no rows are returned
a hash where keys are the table names and the values are the retrieved items
a hash where keys are the table names and the values are the retrieved items
Hash
table_ids
options
options to be passed to underlying BatchGet call
options to be passed to underlying BatchGet call
example
Retrieve IDs 1 and 2 from the table testtable Dynamoid::Adapter::AwsSdkV2.batch_get_item({'table1' => ['1', '2']})
Retrieve IDs 1 and 2 from the table testtable Dynamoid :: Adapter :: AwsSdkV2 . batch_get_item ( { ' table1 ' = > [ ' 1 ' ' 2 ' ] } )
since
None
todo:
None