lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
# Query the DynamoDB table. This employs DynamoDB's indexes so is generally faster than scanning, but is
# only really useful for range queries, since it can only find by one hash key at once. Only provide
# one range key to the hash.
#
# @param [String] table_name the name of the table
# @param [Hash] opts the options to query the table with
# @option opts [String] :hash_value the value of the hash key to find
# @option opts [Number, Number] :range_between find the range key within this range
# @option opts [Number] :range_greater_than find range keys greater than this
# @option opts [Number] :range_less_than find range keys less than this
# @option opts [Number] :range_gte find range keys greater than or equal to this
# @option opts [Number] :range_lte find range keys less than or equal to this
#
# @return [Enumerable] matching items
#
# @since 1.0.0
#
# @todo Provide support for various other options http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method
Query the DynamoDB table. This employs DynamoDB's indexes so is generally faster than scanning, but is
only really useful for range queries, since it can only find by one hash key at once. Only provide
one range key to the hash.
Query the DynamoDB table . This employs DynamoDB ' s indexes so is generally faster than scanning but is only really useful for range queries since it can only find by one hash key at once . Only provide one range key to the hash .
def query(table_name, opts = {})
        table = describe_table(table_name)
        hk    = (opts[:hash_key].present? ? opts[:hash_key] : table.hash_key).to_s
        rng   = (opts[:range_key].present? ? opts[:range_key] : table.range_key).to_s
        q     = opts.slice(
                  :consistent_read,
                  :scan_index_forward,
                  :limit,
                  :select,
                  :index_name
                )
        opts.delete(:consistent_read)
        opts.delete(:scan_index_forward)
        opts.delete(:limit)
        opts.delete(:select)
        opts.delete(:index_name)
        opts.delete(:next_token).tap do |token|
          break unless token
          q[:exclusive_start_key] = {
            hk  => token[:hash_key_element],
            rng => token[:range_key_element]
          }
        end
        key_conditions = {
          hk => {
            comparison_operator: EQ,
            attribute_value_list: [
              opts.delete(:hash_value).freeze
            ]
          }
        }
        opts.each_pair do |k, v|
          next unless(op = RANGE_MAP[k])
          key_conditions[rng] = {
            comparison_operator: op,
            attribute_value_list: [
              opts.delete(k).freeze
            ].flatten 
          }
        end
        q[:table_name]     = table_name
        q[:key_conditions] = key_conditions
        Enumerator.new { |y|
          result = client.query(q)
          result.items.each { |r|
            y << result_item_to_hash(r)
          }
        }
      end
def query ( table_name , opts = { } ) table = describe_table ( table_name ) hk = ( opts [ :hash_key ] . present? ? opts [ :hash_key ] : table . hash_key ) . to_s rng = ( opts [ :range_key ] . present? ? opts [ :range_key ] : table . range_key ) . to_s q = opts . slice ( :consistent_read , :scan_index_forward , :limit , :select , :index_name ) opts . delete ( :consistent_read ) opts . delete ( :scan_index_forward ) opts . delete ( :limit ) opts . delete ( :select ) opts . delete ( :index_name ) opts . delete ( :next_token ) . tap do | token | break unless token q [ :exclusive_start_key ] = { hk => token [ :hash_key_element ] , rng => token [ :range_key_element ] } end key_conditions = { hk => { comparison_operator : EQ , attribute_value_list : [ opts . delete ( :hash_value ) . freeze ] } } opts . each_pair do | k , v | next unless ( op = RANGE_MAP [ k ] ) key_conditions [ rng ] = { comparison_operator : op , attribute_value_list : [ opts . delete ( k ) . freeze ] . flatten } end q [ :table_name ] = table_name q [ :key_conditions ] = key_conditions Enumerator . new { | y | result = client . query ( q ) result . items . each { | r | y << result_item_to_hash ( r ) } } end
Query the DynamoDB table.
Query the DynamoDB table .
# TODO: Provide option for other operators like NE, IN, LE, etc # TODO: ATM, only few comparison operators are supported, provide support for all operators # Flatten as BETWEEN operator specifies array of two elements
None
Enumerable
table_name
opts
:range_lte find range keys less than or equal to this
: range_lte find range keys less than or equal to this
opts the options to query the table with
opts the options to query the table with
since
None
todo
None