API Reference
All generic types accept either interface or type as the shape parameter — both work identically.
Core Types
Section titled “Core Types”QuerySchema
Section titled “QuerySchema”The portable query model. Can be constructed via the aq builder or as a plain object.
interface QuerySchema<TShape extends SchemaShape = SchemaShape> { where?: QueryWhere<TShape> | null orderBy?: QueryOrderBy<TShape>[] limit?: number offset?: number mate?: Record<string, any> table?: string}QueryWhere
Section titled “QueryWhere”Represents a single condition or logical combination.
type QueryWhere<TShape> = | ComparisonWhere<TShape> | CompoundWhere<TShape> | UnaryLogicalWhere<TShape>ComparisonWhere
Section titled “ComparisonWhere”A discriminated union of four comparison variants:
type ComparisonWhere<TShape, TField = FieldPathByShape<TShape>> = | UnaryComparisonWhere<TShape, TField> // op: '=' | '>' | '>=' | '<' | '<=' | 'like' | 'ilike' | SetComparisonWhere<TShape, TField> // op: '@>' | '<@' | '&&' | ToMultiComparisonWhere<TShape, TField> // op: 'in' (uses `values` instead of `value`) | PredicateWhere<TShape, TField> // op: 'is null' (no value field)CompoundWhere
Section titled “CompoundWhere”Logical combination (and / or).
interface CompoundWhere<TShape> { op: 'and' | 'or' conditions: QueryWhere<TShape>[]}UnaryLogicalWhere
Section titled “UnaryLogicalWhere”Negation (not).
interface UnaryLogicalWhere<TShape> { op: 'not' condition: QueryWhere<TShape>}QueryOrderBy
Section titled “QueryOrderBy”interface QueryOrderBy<TShape> { field: FieldPathByShape<TShape> direction?: 'asc' | 'desc'}Functions
Section titled “Functions”Create a new QuerySchema builder.
aq<TShape>(state?: QuerySchema<TShape>): AgnosticQuery<TShape>newWhere
Section titled “newWhere”Create a standalone WHERE builder.
newWhere<TShape>(state?: QueryWhere<TShape> | null): NewWhere<TShape>newComparisonWhere
Section titled “newComparisonWhere”Create a reusable ComparisonWhere factory.
newComparisonWhere<TShape>(): <Col, Op>(col, op, value) => ComparisonWhere<TShape>findWhere
Section titled “findWhere”Create a WHERE tree searcher.
findWhere<TShape>(where: QueryWhere<TShape>): WhereSearcher<TShape>createExpr
Section titled “createExpr”Create a WhereExpr for use in callbacks. Used internally by .where(callback).
createExpr<TShape>(q?: QueryWhere<TShape> | null): WhereExpr<TShape>Adapter Functions
Section titled “Adapter Functions”Drizzle
Section titled “Drizzle”toDrizzle<T>(db, table, data: QuerySchema<T>): Promise<T[]>toDrizzleWhere<T>(table, where?: QueryWhere<T>): SQL | undefinedtoDrizzleOrderBy<T>(table, orderBy?: QueryOrderBy<T>[]): SQL[]Raw SQL (PostgreSQL)
Section titled “Raw SQL (PostgreSQL)”toSql(options: { table: string } & QuerySchema): SqlResult | undefinedtoSqlWhere(where?: QueryWhere): stringtoSqlOrderBy(orderBy?: QueryOrderBy[]): stringKysely
Section titled “Kysely”fromKysely<T>(query: SelectQueryBuilder): QuerySchema<T>toKyselyWhere<T>(where: QueryWhere<T>): ExpressionOrFactory<...>toKyselyOrderBy<T>(query: SelectQueryBuilder, orderBy: QueryOrderBy<T>[]): SelectQueryBuilderTanStack DB
Section titled “TanStack DB”fromTanDbWhere(where: unknown): QueryWhere | undefinedfromTanDbOrderBy(orderBy: unknown): QueryOrderBy[]fromTanDb<TShape>(loadSubsetOptions?: LoadSubsetOptions): QuerySchema<TShape>toDb0<T>(db: Database, data: QuerySchema<T>): Promise<T[]>Zod / Valibot
Section titled “Zod / Valibot”createQuerySchema<TShape>(): ZodSchema<QuerySchema<TShape>>