PutItem

Create new items, or replace old items with new ones.

Source:
See:

Methods

(inner) insert(item, request) → {Promise}

Source:
See:

Creates a new item, or replaces an old item with a new item. If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item. This function uses PutItem internally.

Example
await insert({ id: 42, foo: 'bar' }, { TableName: 'SomeTable' });
 // Upserts item of primary key `{id: 42}` of `SomTable`
Parameters:
Name Type Description
item Object

The item to insert. Will be converted into a map of DynamoDB attributes.

request Object

Parameters as expected by DynamoDB PutItem operation. Must contain, at least, TableName attribute.

Returns:

Resolves to the response from DynamoDB client.

Type
Promise

(inner) insertFor(tableName, item, requestopt) → {Promise}

Source:
See:

Returns a function Creates a new item, or replaces an old item with a new item. If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item. This function uses PutItem internally. The last request argument is optional and is only required if any non mandatory attribute needs to be included in the request. You would typically use this function through forTable.

Examples
// Upserts item of primary key `{id: 42}` of `SomeTable`
 await insertFor('SomeTable')({ id: 42, foo: 'bar' });
// Upserts item of primaty key `{id: 42}` as long as `name` is not 'Alice'
 await insertFor('SomeTable')(
   { id: 42, name: 'Bob' },
   { ConditionExpression: 'name <> :f', ExpressionAttributeValues: { ':f': { 'S': 'Alice' } } }
 );
// Upserts item of primary key `{id: 42}` of `SomeTable`
 const { insert } = forTable('SomeTable');
 await insert({ id: 42, name: 'Bob' });
Parameters:
Name Type Attributes Description
tableName string

The name of the DynamoDB table to run the query on

item Object

The item to insert. Will be converted into a map of DynamoDB attributes.

request Object <optional>

Parameters as expected by DynamoDB PutItem operation. Must contain, at least, TableName attribute.

Returns:

Resolves to the response from DynamoDB client.

Type
Promise