AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::Record::BatchWrite

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-record/record/batch_write.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ BatchWrite

Returns a new instance of BatchWrite.

Parameters:

  • client (Aws::DynamoDB::Client)

    the DynamoDB SDK client.



18
19
20
# File 'lib/aws-record/record/batch_write.rb', line 18

def initialize(client:)
  @client = client
end

Instance Method Details

#complete?Boolean

Indicates if all items have been processed.

Returns:

  • (Boolean)

    true if unprocessed_items is empty, false otherwise



54
55
56
# File 'lib/aws-record/record/batch_write.rb', line 54

def complete?
  unprocessed_items.values.none?
end

#delete(record) ⇒ Object

Append a DeleteItem operation to a batch write request.

Parameters:



34
35
36
37
38
# File 'lib/aws-record/record/batch_write.rb', line 34

def delete(record)
  table_name, params = record_delete_params(record)
  operations[table_name] ||= []
  operations[table_name] << { delete_request: params }
end

#execute!Aws::Record::BatchWrite

Perform a batch_write_item request.

Returns:



44
45
46
47
48
# File 'lib/aws-record/record/batch_write.rb', line 44

def execute!
  result = @client.batch_write_item(request_items: operations)
  @operations = result.unprocessed_items
  self
end

#put(record) ⇒ Object

Append a PutItem operation to a batch write request.

Parameters:



25
26
27
28
29
# File 'lib/aws-record/record/batch_write.rb', line 25

def put(record)
  table_name, params = record_put_params(record)
  operations[table_name] ||= []
  operations[table_name] << { put_request: params }
end

#unprocessed_itemsHash

Returns all DeleteItem and PutItem operations that have not yet been processed successfully.

Returns:

  • (Hash)

    All operations that have not yet successfully completed.



62
63
64
# File 'lib/aws-record/record/batch_write.rb', line 62

def unprocessed_items
  operations
end