Skip to content

BatchWrite

Command to put and/or delete multiple items in a single operation.

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

Schema extends ZodObject

The Zod schema defining the structure of the entity.

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

BatchWriteConfig<Schema>

BatchWrite<Schema>

buildDeleteRequests(entity): Promise<object[]>;

DynamoEntity<Schema>

Promise<object[]>


buildPutRequests(entity): Promise<object[] | object[]>;

DynamoEntity<Schema>

Promise<object[] | object[]>


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

DynamoEntity<Schema>

Promise<BatchWriteResult<Schema>>

BaseCommand.execute