Skip to content

ProjectedQuery

Command to retrieve specific attributes of multiple items by partition key with optional sort key conditions.

The Zod schema defining the structure of the projected attributes.

import { DynamoTable, DynamoEntity, key, ProjectedQuery, beginsWith } 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(),
description: z.string(),
isComplete: z.boolean(),
}),
partitionKey: todo => key('USER', todo.userId),
sortKey: todo => key('TODO', todo.todoId),
});
const projectedQueryCommand = new ProjectedQuery({
key: { userId: 'user123' },
projection: ['title', 'isComplete'],
projectionSchema: z.object({
title: z.string(),
isComplete: z.boolean(),
}),
limit: 10,
});
const { items, count } = await todoEntity.send(projectedQueryCommand);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

ProjectedSchema extends ZodObject

new ProjectedQuery<Schema, ProjectedSchema>(config): ProjectedQuery<Schema, ProjectedSchema>;

ProjectedQueryConfig<Schema, ProjectedSchema>

ProjectedQuery<Schema, ProjectedSchema>

buildCommandInput(entity): QueryCommandInput;

DynamoEntity<Schema>

QueryCommandInput


buildResult(items, queryResult): ProjectedQueryResult<Schema, ProjectedSchema>;

EntitySchema<ProjectedSchema>[]

QueryCommandOutput

ProjectedQueryResult<Schema, ProjectedSchema>


execute(entity): Promise<ProjectedQueryResult<Schema, ProjectedSchema>>;

DynamoEntity<Schema>

Promise<ProjectedQueryResult<Schema, ProjectedSchema>>

BaseCommand.execute


executePaginated(entity): AsyncGenerator<ProjectedQueryResult<Schema, ProjectedSchema>, void, unknown>;

DynamoEntity<Schema>

AsyncGenerator<ProjectedQueryResult<Schema, ProjectedSchema>, void, unknown>

BasePaginatable.executePaginated


validateItems(items): Promise<EntitySchema<ProjectedSchema>[]>;

Record<string, any>[] | undefined

Promise<EntitySchema<ProjectedSchema>[]>