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.
- Description:
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}
- Description:
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
idif not explicitly provided. Returns theAttributesvalue from the DynamoDB response. By default, it setsReturnValuestoALL_NEWso it returns all of the attributes of the item, as they appear after the update operation. This function uses theUpdateItemoperation internally.
- Source:
- See:
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 |
request |
Object | Parameters as expected by DynamoDB |
Returns:
A promise that resolves to the Attributes property of the DynamoDB response.
- Type
- Promise
(inner) updateFor(key, payload, requestopt) → {Promise}
- Description:
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
idif not explicitly provided. Returns theAttributesvalue from the DynamoDB response. By default, it setsReturnValuestoALL_NEWso it returns all of the attributes of the item, as they appear after the update operation. This function uses theUpdateItemoperation internally. You would typically use this function throughforTable.
- Source:
- See:
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
|
|
request |
Object |
<optional> |
Parameters as expected by DynamoDB |
Returns:
A promise that resolves to the Attributes property of the DynamoDB response.
- Type
- Promise