Skip to content

ConditionalUpdate

Command to modify existing item attributes with a condition expression.

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);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

new ConditionalUpdate<Schema>(config): ConditionalUpdate<Schema>;

ConditionalUpdateConfig<Schema>

ConditionalUpdate<Schema>

execute(entity): Promise<ConditionalUpdateResult<Schema>>;

DynamoEntity<Schema>

Promise<ConditionalUpdateResult<Schema>>

BaseCommand.execute


prepareWriteTransaction(entity): Promise<TransactWriteOperation>;

DynamoEntity<Schema>

Promise<TransactWriteOperation>

WriteTransactable.prepareWriteTransaction