ProjectedQuery
Command to retrieve specific attributes of multiple items by partition key with optional sort key conditions.
Template
Section titled “Template”The Zod schema defining the structure of the projected attributes.
Example
Section titled “Example”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);Type Parameters
Section titled “Type Parameters”Schema
Section titled “Schema”Schema extends ZodObject
The Zod schema defining the structure of the entity.
ProjectedSchema
Section titled “ProjectedSchema”ProjectedSchema extends ZodObject
Implements
Section titled “Implements”BaseCommand<ProjectedQueryResult<Schema,ProjectedSchema>,Schema>BasePaginatable<ProjectedQueryResult<Schema,ProjectedSchema>,Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ProjectedQuery<Schema, ProjectedSchema>(config): ProjectedQuery<Schema, ProjectedSchema>;Parameters
Section titled “Parameters”config
Section titled “config”ProjectedQueryConfig<Schema, ProjectedSchema>
Returns
Section titled “Returns”ProjectedQuery<Schema, ProjectedSchema>
Methods
Section titled “Methods”buildCommandInput()
Section titled “buildCommandInput()”buildCommandInput(entity): QueryCommandInput;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”QueryCommandInput
buildResult()
Section titled “buildResult()”buildResult(items, queryResult): ProjectedQueryResult<Schema, ProjectedSchema>;Parameters
Section titled “Parameters”EntitySchema<ProjectedSchema>[]
queryResult
Section titled “queryResult”QueryCommandOutput
Returns
Section titled “Returns”ProjectedQueryResult<Schema, ProjectedSchema>
execute()
Section titled “execute()”execute(entity): Promise<ProjectedQueryResult<Schema, ProjectedSchema>>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<ProjectedQueryResult<Schema, ProjectedSchema>>
Implementation of
Section titled “Implementation of”executePaginated()
Section titled “executePaginated()”executePaginated(entity): AsyncGenerator<ProjectedQueryResult<Schema, ProjectedSchema>, void, unknown>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”AsyncGenerator<ProjectedQueryResult<Schema, ProjectedSchema>, void, unknown>
Implementation of
Section titled “Implementation of”BasePaginatable.executePaginated
validateItems()
Section titled “validateItems()”validateItems(items): Promise<EntitySchema<ProjectedSchema>[]>;Parameters
Section titled “Parameters”Record<string, any>[] | undefined
Returns
Section titled “Returns”Promise<EntitySchema<ProjectedSchema>[]>