UpdateItem

Edit an existing item's attributes, or add a new item to a table if it does not already exist. You can put or add attribute values.

Source:
See:

Methods

(inner) update(key, itemOrBuilder, request) → {Promise}

Source:
See:

Edits an existing item's attributes, or adds a new item to the table if it does not already exist by its primary key. The primary key name defaults to id if not explicitly provided. Returns the Attributes value from the DynamoDB response. By default, it sets ReturnValues to ALL_NEW so it returns all of the attributes of the item, as they appear after the update operation. This function uses the UpdateItem operation internally.

Examples
// Updates item with primary key `{id: 42}` in `SomeTable`.
 await update(42, { foo: 'bar' }, { TableName: 'SomeTable' });
// Updates item with primary key `{ customId: 42}` in `SomeTable`.
 await update({ customId: 42 }, { foo: 'bar' }, { TableName: 'SomeTable' });
// Updates item and returns the previous attributes
 await update(42, { foo: 'bar' }, { TableName: 'SomeTable', ReturnValues: 'ALL_OLD' });
Parameters:
Name Type Description
key *

The primary key value.

itemOrBuilder Object | function

Either an update expression builder function or the partial item that will be merged with the existing item in AWS.DynamoDB. An appropriate UpdateExpression will be automatically created from this argument. While you can null them or replace them, removing attributes from an item is only supported through manually defining an UpdateExpression using the request argument.

request Object

Parameters as expected by DynamoDB UpdateItem operation. Must include, at least, a TableName attribute.

Returns:

A promise that resolves to the Attributes property of the DynamoDB response.

Type
Promise

(inner) updateFor(key, payload, requestopt) → {Promise}

Source:
See:

Returns a function that edits an existing item's attributes, or adds a new item to the table if it does not already exist by its primary key. The primary key name defaults to id if not explicitly provided. Returns the Attributes value from the DynamoDB response. By default, it sets ReturnValues to ALL_NEW so it returns all of the attributes of the item, as they appear after the update operation. This function uses the UpdateItem operation internally. You would typically use this function through forTable.

Examples
// Updates item with primary key `{id: 42}` in `SomeTable`.
 await updateFor('SomeTable')(42, { foo: 'bar' });
// Exported from `forTable`
 const { update } = forTable('SomeTable');
 await update(42, { foo: 'bar' });
Parameters:
Name Type Attributes Description
key *

The primary key value.

payload Object

The update payload that will be merged with the item present in DynamoDB. An appropriate UpdateExpression will be automatically created from this argument. While you can null them or replace them, removing attributes from an item is only supported through manually defining an UpdateExpression on request.

request Object <optional>

Parameters as expected by DynamoDB UpdateItem operation.

Returns:

A promise that resolves to the Attributes property of the DynamoDB response.

Type
Promise