lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
# Scan the DynamoDB table. This is usually a very slow operation as it naively filters all data on
# the DynamoDB servers.
#
# @param [String] table_name the name of the table
# @param [Hash] scan_hash a hash of attributes: matching records will be returned by the scan
#
# @return [Enumerable] matching items
#
# @since 1.0.0
#
# @todo: Provide support for various options http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#scan-instance_method
Scan the DynamoDB table. This is usually a very slow operation as it naively filters all data on
the DynamoDB servers.
Scan the DynamoDB table . This is usually a very slow operation as it naively filters all data on the DynamoDB servers .
def scan(table_name, scan_hash, select_opts = {})
        limit = select_opts.delete(:limit)
        batch = select_opts.delete(:batch_size)
        request = { table_name: table_name }
        request[:limit] = batch || limit if batch || limit
        request[:scan_filter] = scan_hash.reduce({}) do |memo, kvp|
          memo[kvp[0].to_s] = {
            attribute_value_list: [kvp[1]],
            comparison_operator: EQ
          }
          memo
        end if scan_hash.present?
        Enumerator.new do |y|
          loop do
            results = client.scan(request)
            results.data[:items].each { |row| y << result_item_to_hash(row) }
            if((lk = results[:last_evaluated_key]) && batch)
              request[:exclusive_start_key] = lk
            else
              break
            end
          end
        end
      end
def scan ( table_name , scan_hash , select_opts = { } ) limit = select_opts . delete ( :limit ) batch = select_opts . delete ( :batch_size ) request = { table_name : table_name } request [ :limit ] = batch || limit if batch || limit request [ :scan_filter ] = scan_hash . reduce ( { } ) do | memo , kvp | memo [ kvp [ 0 ] . to_s ] = { attribute_value_list : [ kvp [ 1 ] ] , comparison_operator : EQ } memo end if scan_hash . present? Enumerator . new do | y | loop do results = client . scan ( request ) results . data [ :items ] . each { | row | y << result_item_to_hash ( row ) } if ( ( lk = results [ :last_evaluated_key ] ) && batch ) request [ :exclusive_start_key ] = lk else break end end end end
Scan the DynamoDB table.
Scan the DynamoDB table .
# TODO: Provide support for all comparison operators # Batch loop, pulls multiple requests until done using the start_key
None
Enumerable
table_name
scan_hash
select_opts
scan_hash a hash of attributes: matching records will be returned by the scan
scan_hash a hash of attributes : matching records will be returned by the scan
since
None
todo:
None