Entity Manager
Entity class represents a model for your application.
- To read more about modeling entities check out Decorators and Modeling pages.
Instance of a class represents an item for a given model in DynamoDB.
- It can be created locally (meaning that is not yet saved in DynamoDB) with entity constructor,
- It can be already stored in DynamoDB (e.g.
EntityManager.get(primaryKey, options?)
orEntityManager.put(item, options?)
).
Entity Manager class is used to perform operations on a given model.
- Exposes static methods that you can use to read, insert, update, delete items in DynamoDB. This page describes in detail all available methods.
- To create an instance of Entity Manager use
TableManager.entityManager(entity?)
method.
new Entity(props)
Description
Entity constructor is used to initialize an item for a given model. When you construct an item using new Entity(props)
the item is only created locally, meaning that it is not yet saved in DynamoDB. If you want to save it to the table use for example EntityManager.put(item, options?)
method.
Arguments
props
- Props are defined based on your needs when you define the model.
Examples
User model is defined here. to initialize it, simply use a constructor.
const user = new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}); // Item is not saved in DynamoDB at this point
await UserManager.put(user); // Item is saved in DynamoDB
EntityManager.condition()
You can construct a conditional by using the EntityManager.condition()
method. This initializes Condition
class that acts as a condition builder to construct your conditional that you can pass to Entity Manager methods, Query
and Scan
classes. To learn more check out Condition
page.
EntityManager.query()
You can query items by using the EntityManager.query()
method. This initializes Query
class that acts as a builder to construct your DynamoDB query with the appropriate filters. To learn more check out Query
page.
EntityManager.scan()
You can scan items by using the EntityManager.scan()
method. This initializes Scan
class that acts as a builder to construct your DynamoDB scan with the appropriate filters. To learn more check out Scan
page.
EntityManager.get(primaryKey, options?)
Description
This method is used to retrieve an item from DynamoDB. It uses the GetItem DynamoDB operation.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to retrieve. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns initialized class with retrieved data. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
attributes | What item attributes should be retrieved and returned. This uses DynamoDB's ProjectionExpression . If this value is undefined , then all attributes will be returned. | string[] | undefined |
consistent | Whether to perform a strongly consistent read or not. | boolean | false |
extraInput | Extra input that is passed to GetItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | GetItemCommandInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const user = await UserManager.get({ partitionKey: '1', sortKey: 'blazej' });
const user = await UserManager.get({ partitionKey: '1', sortKey: 'blazej' }, { return: 'default' }); // the same
Output:
User {
dynamodeEntity: 'User',
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [ 'tomas', 'david' ],
config: { isAdmin: true }
}
const input = UserManager.get({ partitionKey: '1', sortKey: 'blazej' }, { return: 'input' });
Output:
{
TableName: 'users',
Key: { partitionKey: { S: '1' }, sortKey: { S: 'blazej' } },
ConsistentRead: false
}
const output = await UserManager.get({ partitionKey: '1', sortKey: 'blazej' }, { return: 'output' });
Output:
{
'$metadata': {
...
},
ConsumedCapacity: undefined,
Item: {
dynamodeEntity: { S: 'User' },
sortKey: { S: 'blazej' },
partitionKey: { S: '1' },
config: { M: [Object] },
email: { S: 'blazej@gmail.com' },
age: { N: '18' },
friends: { L: [Array] },
username: { S: 'blazej' }
}
}
EntityManager.put(item, options?)
Description
This method is used to insert an item to DynamoDB. It uses the PutItem DynamoDB operation.
Arguments
item
: Entity
- Instance of a model that you want to insert.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns initialized class. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
overwrite | PutItem DynamoDB operation overwrites items on insertion by default. If you want to prevent overwrites use EntityManager.create(item, options?) instead, or set overwrite prop to false . | boolean | true |
condition | This is an optional instance of a Condition for the save. Item won't be inserted in case condition fails. | Condition | undefined |
extraInput | Extra input that is passed to PutItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | PutItemCommandInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const userInstance = new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
});
const user = await UserManager.put(userInstance);
// OR
const user = await UserManager.put(userInstance, { return: 'default' });
Output:
User {
dynamodeEntity: 'User',
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [ 'tomas', 'david' ],
config: { isAdmin: true }
}
const userInstance = new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
});
const input = UserManager.put(userInstance, { return: 'input' });
Output:
{
TableName: 'users',
Item: {
dynamodeEntity: { S: 'User' },
partitionKey: { S: '1' },
sortKey: { S: 'blazej' },
username: { S: 'blazej' },
email: { S: 'blazej@gmail.com' },
age: { N: '18' },
friends: { L: [Array] },
config: { M: [Object] }
}
}
const userInstance = new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
});
const output = await UserManager.put(userInstance, { return: 'output' });
Output:
{
'$metadata': {
...
},
Attributes: undefined,
ConsumedCapacity: undefined,
ItemCollectionMetrics: undefined
}
EntityManager.create(item, options?)
Description
This method is almost identical to EntityManager.put(item, options?)
. The only difference being that EntityManager.create(item, options?)
won't overwrite existing item in DynamoDB (overwrite is set to false
as default).
EntityManager.update(primaryKey, props, options?)
Description
This method is used to update an item in DynamoDB. It uses the UpdateItem DynamoDB operation.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to update. [partitionKey]
and [sortKey]
are inferred from the metadata(tableMetadata)
function.
props
: UpdateProps
- An object with DynamoDB update operations. For every operation you can pass properties that you want to update.
Name | Acceptable property types | Description |
---|---|---|
add | number | Set<number> | Set<string> | Adds a value to sets or increments/decrements number property. |
set | All | Sets a value on property name. |
setIfNotExists | All | Sets a value on property name (unless it exists on the item). |
listAppend | Array<any> | Appends a value to an array. |
increment | number | Increments property with passed value. |
decrement | number | Decrements property with passed value. |
delete | Set<number> | Set<string> | Removes value from a set. |
remove | All | Removes property from the item. |
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns initialized class with retrieved data. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
returnValues | In which state to return the item after update. You can get the item attributes as they appear before or after update. This uses DynamoDB's ReturnValues . | 'none' | 'allOld' | 'allNew' | 'updatedOld' | 'updatedNew' | 'allNew' |
condition | This is an optional instance of a Condition for the update. Item won't be updated in case condition fails. | Condition | undefined |
extraInput | Extra input that is passed to UpdateItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | UpdateItemCommandInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const item = await AllPossiblePropertiesManager.update(
{ partitionKey: 'pk1', sortKey: 'sk1' },
{
add: {
set: new Set(['5']),
},
set: {
string: 'string',
},
setIfNotExists: {
'object.optional': 'optional',
},
},
);
// OR
const item = await AllPossiblePropertiesManager.update(
{ partitionKey: 'pk1', sortKey: 'sk1' },
{
add: {
set: new Set(['5']),
},
set: {
string: 'string',
},
setIfNotExists: {
'object.optional': 'optional',
},
},
{ return: 'default' }
);
Output:
AllPossibleProperties {
dynamodeEntity: 'AllPossibleProperties',
partitionKey: 'pk1',
sortKey: 'sk1',
GSI_1_PK: undefined,
GSI_1_SK: undefined,
LSI_1_SK: undefined,
createdAt: 2022-10-16T07:08:21.168Z,
updatedAt: 2022-10-16T07:08:21.168Z,
string: 'string',
object: { optional: 'test', required: 2 },
array: [ '1' ],
map: Map(1) { '1' => 'test' },
set: Set(4) { '1', '2', '3', '5' },
number: 10,
boolean: true,
unsaved: 'unsaved'
}
const input = AllPossiblePropertiesManager.update(
{ partitionKey: 'pk1', sortKey: 'sk1' },
{
listAppend: {
array: ['value'],
},
increment: {
number: 10,
},
},
{ return: 'input' }
);
Output:
{
TableName: 'all-possible-properties',
Key: { partitionKey: { S: 'prefix#pk1' }, sortKey: { S: 'sk1' } },
ReturnValues: 'ALL_NEW',
ExpressionAttributeNames: { '#array': 'array', '#number': 'number' },
ExpressionAttributeValues: { ':array': { L: [Array] }, ':array__1': { N: '10' } },
UpdateExpression: 'SET #array = list_append(#array, :array), #number = #number + :array__1'
}
const output = await AllPossiblePropertiesManager.update(
{ partitionKey: 'pk1', sortKey: 'sk1' },
{
decrement: {
'object.required': 2,
},
delete: {
set: new Set(['2', '5']),
},
remove: ['number'],
},
{ return: 'output' }
);
Output:
{
'$metadata': {
...
},
Attributes: {
createdAt: { S: '2022-10-16T07:08:21.168Z' },
dynamodeEntity: { S: 'AllPossibleProperties' },
boolean: { BOOL: true },
set: { SS: [Array] },
sortKey: { S: 'sk1' },
partitionKey: { S: 'prefix#pk1' },
string: { S: 'string' },
array: { L: [Array] },
map: { M: [Object] },
object: { M: [Object] },
updatedAt: { N: '1665904101168' }
},
ConsumedCapacity: undefined,
ItemCollectionMetrics: undefined
}
EntityManager.delete(primaryKey, options?)
Description
This method is used to delete an item from DynamoDB. It uses the DeleteItem DynamoDB operation.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to delete. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns nothing. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
condition | Instance of Condition class with conditionals that has to pass to delete the item. | Condition | undefined |
throwErrorIfNotExists | DeleteItem DynamoDB operation does not throw an error when deleting an item that doesn't exist. If you want to prevent deleting non existent item set throwErrorIfNotExists prop to true . | boolean | false |
returnValues | Whether or not to return the item after deletion. You can get the item attributes as they appear before deletion or none at all. This uses DynamoDB's ReturnValues . | 'none' | 'allOld' | 'allOld' |
extraInput | Extra input that is passed to DeleteItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | DeleteItemCommandInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const deletedUser = await UserManager.delete({ partitionKey: '1', sortKey: 'blazej' });
// OR
const deletedUser = await UserManager.delete({ partitionKey: '1', sortKey: 'blazej' }, { return: 'default' });
Output:
User {
dynamodeEntity: 'User',
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [ 'tomas', 'david' ],
config: { isAdmin: true }
}
const input = UserManager.delete({ partitionKey: '1', sortKey: 'blazej' }, { return: 'input' });
Output:
{
TableName: 'users',
Key: { partitionKey: { S: '1' }, sortKey: { S: 'blazej' } }
}
const output = await UserManager.delete({ partitionKey: '1', sortKey: 'blazej' }, { return: 'output' });
Output:
{
'$metadata': {
...
},
Attributes: {
dynamodeEntity: { S: 'User' },
sortKey: { S: 'blazej' },
partitionKey: { S: '1' },
config: { M: [Object] },
email: { S: 'blazej@gmail.com' },
age: { N: '18' },
friends: { L: [Array] },
username: { S: 'blazej' }
},
ConsumedCapacity: {
CapacityUnits: 1,
GlobalSecondaryIndexes: undefined,
LocalSecondaryIndexes: undefined,
ReadCapacityUnits: undefined,
Table: undefined,
TableName: 'users',
WriteCapacityUnits: undefined
},
ItemCollectionMetrics: undefined
}
EntityManager.batchGet(primaryKeys, options?)
Description
This method is used to retrieve multiple items from DynamoDB. It uses the BatchGetItem DynamoDB operation.
Arguments
primaryKeys
: Array<{ [partitionKey]: string | number; [sortKey]?: string | number }>
- Primary keys of the items you want to retrieve. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns array of initialized classes with retrieved data. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
attributes | What items attributes should be retrieved and returned. This uses DynamoDB's ProjectionExpression . If this value is undefined , then all attributes will be returned. | string[] | undefined |
consistent | Whether to perform a strongly consistent reads or not. | boolean | false |
extraInput | Extra input that is passed to BatchGetItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | BatchGetItemCommandInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const input = await UserManager.batchGet([
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
]);
// OR
const input = await UserManager.batchGet(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{
return: 'default',
},
);
Output:
{
items: [
User {
dynamodeEntity: 'User',
partitionKey: '2',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [Array],
config: [Object]
},
User {
dynamodeEntity: 'User',
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [Array],
config: [Object]
}
],
unprocessedKeys: []
}
const input = UserManager.batchGet(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{
return: 'input',
},
);
Output:
{ RequestItems: { users: { Keys: [Array], ConsistentRead: false } } }
const output = await UserManager.batchGet(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{
return: 'output',
},
);
Output:
{
'$metadata': {
...
},
ConsumedCapacity: undefined,
Responses: { users: [ [Object], [Object] ] },
UnprocessedKeys: {}
}
EntityManager.batchPut(items, options?)
Description
This method is used to insert multiple items to DynamoDB. It uses the BatchWriteItem DynamoDB operation.
This method is overwriting, so it will overwrite the data you currently have in place for the existing key in your table.
Arguments
items
: Array<Entity>
- Instances of entity that you want to insert.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns initialized classes. For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
extraInput | Extra input that is passed to BatchWriteItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | BatchWriteItemInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const users = [
new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
new User({
partitionKey: '2',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
];
const result = await UserManager.batchPut(users);
// OR
const result = await UserManager.batchPut(users, {
return: 'default',
});
Output:
{
items: [
User {
dynamodeEntity: 'User',
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [Array],
config: [Object]
},
User {
dynamodeEntity: 'User',
partitionKey: '2',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: [Array],
config: [Object]
}
],
unprocessedItems: []
}
const users = [
new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
new User({
partitionKey: '2',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
];
const input = UserManager.batchPut(users, {
return: 'input',
});
Output:
{ RequestItems: { users: [ [Object], [Object] ] } }
const users = [
new User({
partitionKey: '1',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
new User({
partitionKey: '2',
sortKey: 'blazej',
username: 'blazej',
email: 'blazej@gmail.com',
age: 18,
friends: ['tomas', 'david'],
config: {
isAdmin: true,
},
}),
];
const output = await UserManager.batchPut(users, {
return: 'output',
});
Output:
{
'$metadata': {
...
},
ConsumedCapacity: undefined,
ItemCollectionMetrics: undefined,
UnprocessedItems: {}
}
EntityManager.batchDelete(primaryKeys, options?)
Description
This method is used to delete multiple items from DynamoDB. It uses the BatchWriteItem DynamoDB operation.
Arguments
primaryKeys
: Array<{ [partitionKey]: string | number; [sortKey]?: string | number }>
- Primary keys of the items you want to delete. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
return | What the method should return. For 'default' method returns an object with unprocessedKeys . For 'input' method returns prepared DynamoDB input command and no request is made to DynamoDB (method no longer returns a promise). For 'output' method returns the bare output from DynamoDB operation. | 'default' | 'input' | 'output' | 'default' |
extraInput | Extra input that is passed to BatchWriteItem DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | BatchWriteItemInput | undefined |
Examples
- return: 'default'
- return: 'input'
- return: 'output'
const result = await UserManager.batchDelete(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
);
// OR
const result = await UserManager.batchDelete(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{ return: 'default' },
);
Output:
{ unprocessedItems: [] }
const input = UserManager.batchDelete(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{ return: 'input' },
);
{ RequestItems: { users: [ [Object], [Object] ] } }
const output = await UserManager.batchDelete(
[
{ partitionKey: '1', sortKey: 'blazej' },
{ partitionKey: '2', sortKey: 'blazej' },
],
{ return: 'output' },
);
Output:
{
'$metadata': {
...
},
ConsumedCapacity: undefined,
ItemCollectionMetrics: undefined,
UnprocessedItems: {}
}
EntityManager.transactionGet(primaryKey, options?)
Description
This method is used to build a retrieve item operation. EntityManager.transactionGet(primaryKey, options?)
used separately won't make a DynamoDB API call. You need to pass it to transactionGet(transactions, options?)
function. This allows to retrieve multiple items in a single transaction.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to retrieve. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
attributes | What item attributes should be retrieved and returned. This uses DynamoDB's ProjectionExpression . If this value is undefined, then all attributes will be returned. | string[] | undefined |
extraInput | Extra input that is passed to Get DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | Get | undefined |
Examples
Check out transactionGet(transactions, options?)
function to see example usage.
EntityManager.transaction.put(item, options?)
Description
This method is used to build an insert item operation. EntityManager.transaction.put(item, options?)
used separately won't make a DynamoDB API call. You need to pass it to transactionWrite(transactions, options?)
function. This allows to insert multiple items in a single transaction
Arguments
item
: Entity
- Instance of a model that you want to insert.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
overwrite | TransactItems.Put DynamoDB operation overwrites items on insertion by default. If you want to prevent overwrites use EntityManager.transaction.create(item, options?) instead, or set overwrite prop to false. | boolean | true |
condition | This is an optional instance of a Condition for the save. Item won't be inserted in case condition fails. | Condition | undefined |
returnValuesOnFailure | Whether or not to return the item if the Put condition fails. You can get the item attributes as they appear before insertion or none at all. This uses DynamoDB's ReturnValuesOnConditionCheckFailure . | 'none' | 'allOld' | 'allOld' |
extraInput | Extra input that is passed to Put DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | TransactItems.Put | undefined |
Examples
Check out transactionWrite(transactions, options?)
function to see example usage.
EntityManager.transaction.create(item, options?)
Description
This method is almost identical to EntityManager.transaction.put(item, options?)
. The only difference being that EntityManager.transaction.create(item, options?)
won't overwrite existing item in DynamoDB (overwrite is set to false
as default).
EntityManager.transaction.update(primaryKey, props, options?)
Description
This method is used to build an update item operation. EntityManager.transaction.update(primaryKey, props, options?)
used separately won't make a DynamoDB API call. You need to pass it to transactionWrite(transactions, options?)
function. This allows to update multiple items in a single transaction.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to update. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
props
: UpdateProps
- An object with DynamoDB update operations. For every operation you can pass properties that you want to update.
Name | Acceptable property types | Description |
---|---|---|
add | number | Set<number> | Set<string> | Adds a value to sets or increments/decrements number property. |
set | All | Sets a value on property name. |
setIfNotExists | All | Sets a value on property name (unless it exists on the item). |
listAppend | Array<any> | Appends a value to an array. |
increment | number | Increments property with passed value. |
decrement | number | Decrements property with passed value. |
delete | Set<number> | Set<string> | Removes value from a set. |
remove | All | Removes property from the item. |
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
condition | This is an optional instance of a Condition for the update. Item won't be updated in case condition fails. | Condition | undefined |
returnValuesOnFailure | In which state to return the item if the Update condition fails. You can get the item attributes as they appear before or after update. This uses DynamoDB's ReturnValuesOnConditionCheckFailure . | 'none' | 'allOld' | 'allNew' | 'updatedOld' | 'updatedNew' | 'allNew' |
extraInput | Extra input that is passed to Update DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | TransactItems.Update | undefined |
Examples
Check out transactionWrite(transactions, options?)
function to see example usage.
EntityManager.transaction.delete(primaryKey, options?)
Description
This method is used to build a delete item operation. EntityManager.transaction.delete(primaryKey, options?)
used separately won't make a DynamoDB API call. You need to pass it to transactionWrite(transactions, options?)
function. This allows to delete multiple items in a single transaction.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to delete. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
You can add optional options
parameter that is an object. The table below represents options that you can pass in:
Name | Description | Type | Default |
---|---|---|---|
condition | Instance of Condition class with conditionals that has to pass to delete the item. | Condition | undefined |
extraInput | Extra input that is passed to Delete DynamoDB operation. Use it only in case that you know what are you are doing as it may override other properties passed to DynamoDB operation. | TransactItems.Delete | undefined |
Examples
Check out transactionWrite(transactions, options?)
function to see example usage.
EntityManager.transaction.condition(primaryKey, conditionInstance)
Description
This method is used to build a conditionCheck
when running a transaction. EntityManager.transaction.condition(primaryKey, conditionInstance)
used separately won't make a DynamoDB API call. You need to pass it to transactionWrite(transactions, options?)
function. This allows add multiple condition to a single transaction.
Arguments
primaryKey
: { [partitionKey]: string | number; [sortKey]?: string | number }
- Primary key of the item you want to delete. [partitionKey]
and [sortKey]
are inferred from the new TableManager(tableEntity, tableMetadata)
function.
conditionInstance
: Condition
- Instance of Condition
class with conditionals that has to pass in order for transaction to succeed.
Examples
Check out transactionWrite(transactions, options?)
function to see example usage.