Module: Aws::Record::ItemOperations

Included in:
Aws::Record
Defined in:
lib/aws-record/record/item_operations.rb

Defined Under Namespace

Modules: ItemOperationsClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(sub_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/aws-record/record/item_operations.rb', line 19

def self.included(sub_class)
  sub_class.extend(ItemOperationsClassMethods)
end

Instance Method Details

#delete!Object

Deletes the item instance that matches the key values of this item instance in Amazon DynamoDB. Uses the Aws::DynamoDB::Client#delete_item API.



88
89
90
91
92
93
94
# File 'lib/aws-record/record/item_operations.rb', line 88

def delete!
  dynamodb_client.delete_item(
    table_name: self.class.table_name,
    key: key_values
  )
  true
end

#save(opts = {}) ⇒ Object

Saves this instance of an item to Amazon DynamoDB. If this item is “new” as defined by having new or altered key attributes, will attempt a conditional Aws::DynamoDB::Client#put_item call, which will not overwrite an existing item. If the item only has altered non-key attributes, will perform an Aws::DynamoDB::Client#update_item call. Uses this item instance’s attributes in order to build the request on your behalf.

You can use the :force option to perform a simple put/overwrite without conditional validation or update logic.

Parameters:

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

Options Hash (opts):

  • :force (Boolean)

    if true, will save as a put operation and overwrite any existing item on the remote end. Otherwise, and by default, will either perform a conditional put or an update call.

Returns:

  • false if the record is invalid as defined by an attempt to call valid? on this item, if that method exists. Otherwise, returns client call return value.



76
77
78
79
80
81
82
# File 'lib/aws-record/record/item_operations.rb', line 76

def save(opts = {})
  if _invalid_record?(opts)
    false
  else
    _perform_save(opts)
  end
end

#save!(opts = {}) ⇒ Object

Saves this instance of an item to Amazon DynamoDB. If this item is “new” as defined by having new or altered key attributes, will attempt a conditional Aws::DynamoDB::Client#put_item call, which will not overwrite an existing item. If the item only has altered non-key attributes, will perform an Aws::DynamoDB::Client#update_item call. Uses this item instance’s attributes in order to build the request on your behalf.

You can use the :force option to perform a simple put/overwrite without conditional validation or update logic.

Parameters:

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

Options Hash (opts):

  • :force (Boolean)

    if true, will save as a put operation and overwrite any existing item on the remote end. Otherwise, and by default, will either perform a conditional put or an update call.

Raises:



47
48
49
50
51
52
53
54
# File 'lib/aws-record/record/item_operations.rb', line 47

def save!(opts = {})
  ret = save(opts)
  if ret
    ret
  else
    raise Errors::ValidationError.new("Validation hook returned false!")
  end
end