Class: Dynamoid::AdapterPlugin::AwsSdkV3::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb

Constant Summary collapse

OPTIONS_KEYS =
%i[
  limit hash_key hash_value range_key consistent_read scan_index_forward
  select index_name batch_size exclusive_start_key record_limit scan_limit
  project
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, table, opts = {}) ⇒ Query

Returns a new instance of Query.



19
20
21
22
23
24
25
26
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 19

def initialize(client, table, opts = {})
  @client = client
  @table = table

  opts = opts.symbolize_keys
  @options = opts.slice(*OPTIONS_KEYS)
  @conditions = opts.except(*OPTIONS_KEYS)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



17
18
19
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 17

def client
  @client
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



17
18
19
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 17

def conditions
  @conditions
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 17

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



17
18
19
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 17

def table
  @table
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb', line 28

def call
  request = build_request

  Enumerator.new do |yielder|
    api_call = -> (request) do
      client.query(request).tap do |response|
        yielder << response
      end
    end

    middlewares = Middleware::Backoff.new(
      Middleware::StartKey.new(
        Middleware::Limit.new(api_call, record_limit: record_limit, scan_limit: scan_limit)
      )
    )

    catch :stop_pagination do
      loop do
        middlewares.call(request)
      end
    end
  end
end