Skip to content

ProjectedGet

Command to retrieve specific attributes of a single item by primary key.

import { DynamoTable, DynamoEntity, key, ProjectedGet } 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 projectedGetCommand = new ProjectedGet({
key: { userId: 'user123' },
projection: ['name', 'email'],
projectionSchema: z.object({
name: z.string(),
email: z.string(),
}),
consistent: true,
});
const { item } = await userEntity.send(projectedGetCommand);

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 ProjectedGet<Schema, ProjectionSchema>(config): ProjectedGet<Schema, ProjectionSchema>;

ProjectedGetConfig<Schema, ProjectionSchema>

ProjectedGet<Schema, ProjectionSchema>

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

DynamoEntity<Schema>

Promise<ProjectedGetResult<ProjectionSchema>>

BaseCommand.execute