select
The select builder is used to retrieve data from your DynamoDB tables. It intelligently chooses between GetItem, Query, and Scan based on the filters provided in your where clause.
import { db } from "./db";import { users } from "./schema";import { eq } from "@aurios/mizzle";
const result = await db.select().from(users).where(eq(users.id, "123")).execute();Methods
Section titled “Methods”select(fields?)
Section titled “select(fields?)”Initializes the select builder. You can optionally pass an object to specify which fields should be returned (Projections).
- Arguments:
fields(optional): An object mapping field names to column definitions.
- Returns:
SelectBuilder
from(entity)
Section titled “from(entity)”Specifies the entity you want to select from.
- Arguments:
entity: A Mizzle entity definition.
- Returns:
SelectBase
where(expression)
Section titled “where(expression)”Adds a filter to the query. Mizzle will analyze this expression to determine if it can use an index or a direct key lookup.
- Arguments:
expression: A Mizzle expression (e.g.,eq(),and(),beginsWith()).
- Returns:
this
execute()
Section titled “execute()”Executes the query against DynamoDB and returns a promise that resolves to an array of items.
- Returns:
Promise<T[]>
Intelligent Routing
Section titled “Intelligent Routing”Mizzle’s select is powerful because it abstracts DynamoDB’s different read operations:
- GetItem: Triggered when the
whereclause provides both the Partition Key and Sort Key for the main table. - Query: Triggered when only the Partition Key is provided, or when keys matching a Global Secondary Index (GSI) are provided.
- Scan: Triggered when no keys can be resolved from the
whereclause. Note: Scans are expensive and should be used with caution.