ConditionCheck
Builds a condition to check against an entity item for the transaction to succeed, to be used within TransactWriteItems operations:
import { execute } from 'dynamodb-toolbox/entity/actions/transactWrite'
import { ConditionCheck } from 'dynamodb-toolbox/entity/actions/transactCheck'
const transaction = PokemonEntity.build(ConditionCheck)
const params = transaction.params()
await execute(transaction, ...otherTransactions)
ConditionCheck can be executed in conjunction with PutTransactions, UpdateTransactions and DeleteTransactions.
Check the Transaction Documentation to learn more about the execute function.
Only one transaction per item is supported. For instance, you cannot run a ConditionCheck and an UpdateTransaction on the same item: You can, however, condition the UpdateTransaction itself.
Requestβ
.key(...)β
(required)
The key of the item to check (i.e. attributes that are tagged as part of the primary key):
const transaction = PokemonEntity.build(ConditionCheck).key(
{ pokemonId: 'pikachu1' }
)
You can use the KeyInputItem generic type to explicitly type an object as a ConditionCheck key object:
import type { KeyInputItem } from 'dynamodb-toolbox/entity'
const key: KeyInputItem<typeof PokemonEntity> = {
pokemonId: 'pikachu1'
}
const transaction =
PokemonEntity.build(ConditionCheck).key(key)
.condition(...)β
(required)
The condition to check against:
const transaction = PokemonEntity.build(ConditionCheck)
.key(...)
.condition({ attr: 'level', gte: 50 })
See the ConditionParser action for more details on how to write conditions.