BatchWrite
Command to put and/or delete multiple items in a single operation.
Example
Section titled “Example”import { DynamoTable, DynamoEntity, key, BatchWrite } from 'dynamo-document-builder';
const table = new DynamoTable({ tableName: 'ExampleTable', documentClient,});
const todoEntity = new DynamoEntity({ table, schema: z.object({ userId: z.string(), todoId: z.string(), title: z.string(), }), partitionKey: todo => key('USER', todo.userId), sortKey: todo => key('TODO', todo.todoId),});
const batchWriteCommand = new BatchWrite({ items: [ { userId: 'user1', todoId: 'todo1', title: 'Task 1' }, { userId: 'user2', todoId: 'todo2', title: 'Task 2' }, ], deletes: [ { userId: 'user3', todoId: 'todo3' }, ],});
const { unprocessedPuts, unprocessedDeletes } = await todoEntity.send(batchWriteCommand);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<BatchWriteResult<Schema>,Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BatchWrite<Schema>(config): BatchWrite<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”BatchWriteConfig<Schema>
Returns
Section titled “Returns”BatchWrite<Schema>
Methods
Section titled “Methods”buildDeleteRequests()
Section titled “buildDeleteRequests()”buildDeleteRequests(entity): Promise<object[]>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<object[]>
buildPutRequests()
Section titled “buildPutRequests()”buildPutRequests(entity): Promise<object[] | object[]>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<object[] | object[]>
execute()
Section titled “execute()”execute(entity): Promise<BatchWriteResult<Schema>>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<BatchWriteResult<Schema>>