TransactWrite
Command to perform an atomic multi-item write transaction (all-or-nothing).
Example
Section titled “Example”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);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<TransactWriteResult,Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TransactWrite<Schema>(config): TransactWrite<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”TransactWriteConfig<Schema>
Returns
Section titled “Returns”TransactWrite<Schema>
Methods
Section titled “Methods”execute()
Section titled “execute()”execute(entity): Promise<TransactWriteResult>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<TransactWriteResult>