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(opts = {}) ⇒ BatchWrite

Returns a new instance of BatchWrite.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • client (Aws::DynamoDB::Client)

    the DynamoDB SDK client.



8
9
10
# File 'lib/aws-record/record/batch_write.rb', line 8

def initialize(opts = {})
  @client = opts[:client]
end

Instance Method Details

#complete?Boolean

Indicates if all items have been processed.

See Aws::Record::Batch.write for example usage.

Returns:

  • (Boolean)

    true if unprocessed_items is empty, false otherwise



49
50
51
# File 'lib/aws-record/record/batch_write.rb', line 49

def complete?
  unprocessed_items.values.none?
end

#delete(record) ⇒ Object

Append a DeleteItem operation to a batch write request.

See Aws::Record::Batch.write for example usage.

Parameters:



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

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.

See Aws::Record::Batch.write for example usage.

Returns:



38
39
40
41
42
# File 'lib/aws-record/record/batch_write.rb', line 38

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.

See Aws::Record::Batch.write for example usage.

Parameters:



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

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.

See Aws::Record::Batch.write for example usage.

Returns:

  • (Hash)

    All operations that have not yet successfully completed.



58
59
60
# File 'lib/aws-record/record/batch_write.rb', line 58

def unprocessed_items
  operations
end