Skip to content

BatchProjectedGet

Command to retrieve specific attributes of multiple items by primary keys in a single operation.

import { DynamoTable, DynamoEntity, key, BatchProjectedGet } 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(),
email: z.string(),
age: z.number(),
}),
partitionKey: user => key('USER', user.userId),
sortKey: () => 'METADATA',
});
const batchProjectedGetCommand = new BatchProjectedGet({
keys: [
{ userId: 'user1' },
{ userId: 'user2' },
],
projection: ['name', 'email'],
projectionSchema: z.object({
name: z.string(),
email: z.string(),
}),
});
const { items } = await userEntity.send(batchProjectedGetCommand);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

ProjectionSchema extends ZodObject

The Zod schema defining the structure of the projected attributes.

new BatchProjectedGet<Schema, ProjectionSchema>(config): BatchProjectedGet<Schema, ProjectionSchema>;

BatchProjectedGetConfig<Schema, ProjectionSchema>

BatchProjectedGet<Schema, ProjectionSchema>

execute(entity): Promise<BatchProjectedGetResult<ProjectionSchema>>;

DynamoEntity<Schema>

Promise<BatchProjectedGetResult<ProjectionSchema>>

BaseCommand.execute