Skip to content

TransactWrite

Command to perform an atomic multi-item write transaction (all-or-nothing).

import { DynamoTable, DynamoEntity, key, TransactWrite, Put, Update, Delete } from 'dynamo-document-builder';
const table = new DynamoTable({
tableName: 'ExampleTable',
documentClient,
});
const userEntity = new DynamoEntity({
table,
schema: z.object({
userId: z.string(),
name: z.string(),
balance: z.number(),
}),
partitionKey: user => key('USER', user.userId),
sortKey: () => 'METADATA',
});
const transactWriteCommand = new TransactWrite({
writes: [
new Put({ item: { userId: 'user1', name: 'John', balance: 100 } }),
new Update({ key: { userId: 'user2' }, update: { balance: add(50) } }),
new Delete({ key: { userId: 'user3' } }),
],
idempotencyToken: 'unique-token',
});
await userEntity.send(transactWriteCommand);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

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

TransactWriteConfig<Schema>

TransactWrite<Schema>

execute(entity): Promise<TransactWriteResult>;

DynamoEntity<Schema>

Promise<TransactWriteResult>

BaseCommand.execute