class Dynamoid::AdapterPlugin::AwsSdkV3::ExecuteStatement

Excecute a PartiQL query

Documentation:

NOTE: For reads result may be paginated. Only pagination with NextToken is implemented. Currently LastEvaluatedKey in response cannot be fed to ExecuteStatement to get the next page.

See also:

Attributes

client[R]
options[R]
parameters[R]
statement[R]

Public Class Methods

new(client, statement, parameters, options) click to toggle source
# File lib/dynamoid/adapter_plugin/aws_sdk_v3/execute_statement.rb, line 23
def initialize(client, statement, parameters, options)
  @client = client
  @statement = statement
  @parameters = parameters
  @options = options.symbolize_keys.slice(:consistent_read)
end

Public Instance Methods

call() click to toggle source
# File lib/dynamoid/adapter_plugin/aws_sdk_v3/execute_statement.rb, line 30
def call
  request = {
    statement: @statement,
    parameters: @parameters,
    consistent_read: @options[:consistent_read],
  }

  response = client.execute_statement(request)

  unless response.next_token
    return response_to_items(response)
  end

  Enumerator.new do |yielder|
    yielder.yield(response_to_items(response))

    while response.next_token
      request[:next_token] = response.next_token
      response = client.execute_statement(request)
      yielder.yield(response_to_items(response))
    end
  end
end

Private Instance Methods

response_to_items(response) click to toggle source
# File lib/dynamoid/adapter_plugin/aws_sdk_v3/execute_statement.rb, line 56
def response_to_items(response)
  response.items.map(&:symbolize_keys)
end