query
While select provides high-level abstraction, the query builder (available via db.query) offers more direct control over DynamoDB’s Query and Scan operations.
import { db } from "./db";import { users } from "./schema";import { eq } from "@aurios/mizzle";
const results = await db .query(users) .where(eq(users.id, "123")) .limit(10) .sort(false) // Descending .execute();Methods
Section titled “Methods”query(entity)
Section titled “query(entity)”Initializes the query builder for a specific entity.
- Arguments:
entity: A Mizzle entity definition.
- Returns:
DynamoQueryBuilder
where(condition)
Section titled “where(condition)”Sets the condition for the query.
- Arguments:
condition: A Mizzle expression.
- Returns:
this
limit(val)
Section titled “limit(val)”Sets the maximum number of items to evaluate.
- Arguments:
val: Number of items.
- Returns:
this
sort(forward)
Section titled “sort(forward)”Specifies the order of index traversal.
- Arguments:
forward:truefor ascending (default),falsefor descending.
- Returns:
this
index(name)
Section titled “index(name)”Specifies a Global Secondary Index (GSI) to use for the query.
- Arguments:
name: The name of the GSI.
- Returns:
this
setProjection(cols)
Section titled “setProjection(cols)”Specifies which attributes to return.
- Arguments:
cols: An array of column names.
- Returns:
this
execute()
Section titled “execute()”Executes the operation (Query if PK is provided, otherwise Scan).
- Returns:
Promise<T[]>