Query
Command to retrieve multiple items by partition key with optional sort key conditions.
Example
Section titled “Example”import { DynamoTable, DynamoEntity, key, Query, 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(), isComplete: z.boolean(), }), partitionKey: todo => key('USER', todo.userId), sortKey: todo => key('TODO', todo.todoId),});
const queryCommand = new Query({ key: { userId: 'user123' }, sortKeyCondition: { SK: beginsWith('TODO#') }, limit: 10,});
const { items, count } = await todoEntity.send(queryCommand);Type Parameters
Section titled “Type Parameters”Schema
Section titled “Schema”Schema extends ZodObject
The Zod schema defining the structure of the entity.
Implements
Section titled “Implements”BaseCommand<QueryResult<Schema>,Schema>BasePaginatable<QueryResult<Schema>,Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Query<Schema>(config): Query<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”QueryConfig<Schema>
Returns
Section titled “Returns”Query<Schema>
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): QueryResult<Schema>;Parameters
Section titled “Parameters”EntitySchema<Schema>[]
queryResult
Section titled “queryResult”QueryCommandOutput
Returns
Section titled “Returns”QueryResult<Schema>
execute()
Section titled “execute()”execute(entity): Promise<QueryResult<Schema>>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<QueryResult<Schema>>
Implementation of
Section titled “Implementation of”executePaginated()
Section titled “executePaginated()”executePaginated(entity): AsyncGenerator<QueryResult<Schema>, void, unknown>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”AsyncGenerator<QueryResult<Schema>, void, unknown>
Implementation of
Section titled “Implementation of”BasePaginatable.executePaginated
validateItems()
Section titled “validateItems()”validateItems(entity, items): Promise<EntitySchema<Schema>[]>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Record<string, any>[] | undefined
Returns
Section titled “Returns”Promise<EntitySchema<Schema>[]>