ConditionalUpdate
Command to modify existing item attributes with a condition expression.
Example
Section titled “Example”import { DynamoTable, DynamoEntity, key, ConditionalUpdate, add } from 'dynamo-document-builder';
const table = new DynamoTable({ tableName: 'ExampleTable', documentClient,});
const userEntity = new DynamoEntity({ table, schema: z.object({ userId: z.string(), balance: z.number(), status: z.string(), }), partitionKey: user => key('USER', user.userId), sortKey: () => 'METADATA',});
const conditionalUpdateCommand = new ConditionalUpdate({ key: { userId: 'user123' }, update: { balance: add(50) }, condition: { status: 'active' }, returnValues: 'ALL_NEW',});
const { updatedItem } = await userEntity.send(conditionalUpdateCommand);Type Parameters
Section titled “Type Parameters”Schema
Section titled “Schema”Schema extends ZodObject
The Zod schema defining the structure of the entity.
Implements
Section titled “Implements”BaseCommand<ConditionalUpdateResult<Schema>,Schema>WriteTransactable<Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ConditionalUpdate<Schema>(config): ConditionalUpdate<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”ConditionalUpdateConfig<Schema>
Returns
Section titled “Returns”ConditionalUpdate<Schema>
Methods
Section titled “Methods”execute()
Section titled “execute()”execute(entity): Promise<ConditionalUpdateResult<Schema>>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<ConditionalUpdateResult<Schema>>
Implementation of
Section titled “Implementation of”prepareWriteTransaction()
Section titled “prepareWriteTransaction()”prepareWriteTransaction(entity): Promise<TransactWriteOperation>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<TransactWriteOperation>