Skip to content

Query

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

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);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

new Query<Schema>(config): Query<Schema>;

QueryConfig<Schema>

Query<Schema>

buildCommandInput(entity): QueryCommandInput;

DynamoEntity<Schema>

QueryCommandInput


buildResult(items, queryResult): QueryResult<Schema>;

EntitySchema<Schema>[]

QueryCommandOutput

QueryResult<Schema>


execute(entity): Promise<QueryResult<Schema>>;

DynamoEntity<Schema>

Promise<QueryResult<Schema>>

BaseCommand.execute


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

DynamoEntity<Schema>

AsyncGenerator<QueryResult<Schema>, void, unknown>

BasePaginatable.executePaginated


validateItems(entity, items): Promise<EntitySchema<Schema>[]>;

DynamoEntity<Schema>

Record<string, any>[] | undefined

Promise<EntitySchema<Schema>[]>