Readonly Internal[Type-only fluent return constructor.
Readonly Internal[Type-only ordered argument contract.
Readonly Internal[Nominal identity for typed child-query customizers.
Configure a discriminator branch with the canonical strongly typed query API.
ReadonlyrowRuntime structural schema; stable across filters, pagination and transaction clones.
Restrict a polymorphic query to declared variants and narrow its row schema.
Internal
Compiled SELECT protocol; never replays consumer callbacks.
Explicit AND spelling of where(), including groups and typed parameters.
Explicit AND spelling of where(), including groups and typed parameters.
Explicit AND spelling of where(), including groups and typed parameters.
Explicit AND spelling of where(), including groups and typed parameters.
Configure an isolated Knex SELECT once, declaring the complete raw row output.
Internal
Reject writes through projections or loaded relations.
Select a typed AVG result on a new query.
Average non-null values in an unpaginated clone of this query.
Numeric schema property to aggregate.
Optionaloptions: AggregateOptions<O>
Optional parser receiving the raw driver result, including null.
Exact database numeric text or null by default; a parser overrides this.
Internal
Compile a bound SQL statement; callers never receive the mutable builder.
Optionalcorrelate: ReadCorrelationOptionalmode: typeof COMPILE_PARAMETERSSelect a typed COUNT result on a new query.
Optionalcolumn: ReadPredicateSelector<Select a typed COUNTDISTINCT result on a new query.
Count distinct non-null values in an unpaginated clone of this query.
Schema property to count; SQL nulls do not contribute.
Optionaloptions: AggregateOptions<O>
Optional parser replacing default safe-integer conversion.
A safe integer, or the parser's inferred output type.
Count matching rows, or non-null column values, without mutating this query. Ignores source ordering/limits/offsets while retaining filters and transactions.
Optionaloptions: AggregateOptions<O>
Optional output parser; receives the raw driver value.
A safe integer by default, including zero for an empty source.
Count non-null column values without mutating the source query. Source paging/order is ignored; filters, scopes and transactions remain.
Mapped schema property to count.
Optionaloptions: AggregateOptions<O>
Optional parser replacing safe-integer decoding.
Internal
Decode a SQL/JSON row using the same metadata exposed to consumers.
Optionalpath: stringKeep only distinct selected rows, preserving the row schema.
Select a property subset and eliminate duplicate rows on that immutable projection.
Look up a single entity by primary key. Returns undefined when no
row matches.
The PK column(s) are resolved automatically from the entity's schema
via the primaryKey / hasPrimaryKey extensions. Composite PKs are
passed as a tuple in declaration order:
await db.todos.find(42); // single PK
await db.userRoles.find([userId, role]); // composite PK
Any chained .include() / .includeVariant() calls on this query
are honoured by the underlying SELECT.
Look up multiple entities by primary key in a single SQL statement.
Returns rows in DB order (no ordering guarantee relative to pks).
For composite PKs each element of pks is a tuple matching
declaration order. Returns [] when pks is empty.
Group rows before typed aggregate projection.
Group using trusted SQL without changing the explicit projection.
Filter groups by a mapped column comparison.
Filter grouped results using trusted SQL and captured bindings.
Optionalbindings: readonly RawBinding[]Eager-load a relation declared on TEntity via .hasOne() /
.hasMany() / .belongsTo() / .belongsToMany(). Selector returns
the relation key as a string literal.
Optionalcustomize: (Internal
Reuse a captured child query across polymorphic parent branches.
Eager-load a relation declared inside a polymorphic variant (CTI/STI).
The relation is only populated on rows whose discriminator matches
variantKey. Type-level: when relationName is a key of the
entity's relations, it appears only on the matching branch of the
discriminated-union result; otherwise the result type is unchanged.
Optionalcustomize: (Join a typed collection, applying child projection and pagination independently per parent.
Optionalcustomize: (Join one typed nested object with explicit property keys, including nullable joins.
Optionalcustomize: (Select a typed MAX result on a new query.
Find the largest non-null column value without retaining source paging.
Schema property to aggregate.
Optionaloptions: AggregateOptions<O>
Optional parser replacing default decoding, including null handling.
Null for empty/all-null input; otherwise the column representation. Dates return Date; numeric SQL overrides may return exact strings.
Select a typed MIN result on a new query.
Find the smallest non-null column value without retaining source paging.
Schema property to aggregate.
Optionaloptions: AggregateOptions<O>
Optional parser replacing default decoding, including null handling.
Null for empty/all-null input; otherwise the column representation. Dates return Date; numeric SQL overrides may return exact strings.
Add an OR comparison or parenthesized group.
Add an OR comparison or parenthesized group.
Add an OR comparison or parenthesized group.
Add an OR comparison or parenthesized group.
Fetch a numbered page and a count without mutating the source query.
Read a lossless composite cursor page using native SQL ordering. Cursor sort values remain private text columns, independent of projections and Date decoding. Requires non-null scalar order columns containing a declared unique key.
Read a page using a single raw cursor value; choose a unique, non-null sort column.
Apply a named schema projection with the same exact row-schema guarantees.
Quote a mapped column for trusted raw SQL or correlated subqueries.
Internal
Prevent customizers from substituting an unrelated query source.
Select an exact flat row shape, retaining per-field runtime schemas.
Select named output fields and aggregates, replacing the previous scalar projection.
Replace the projection with trusted raw SQL and an explicit output schema.
Internal
Native storage columns for composing CTI table sources.
Select a typed SUM result on a new query.
Sum non-null values in an unpaginated clone, preserving numeric precision.
Numeric schema property to sum.
Optionaloptions: AggregateOptions<O>
Optional parser receiving the raw driver value, including null.
Database numeric text, or null for empty/all-null input by default. An output parser replaces default decoding and controls the result type.
Awaiting executes the query; repeated awaits deliberately execute again.
Optionalresolve: Optionalreject: ((error: any) => E | PromiseLike<E>) | nullReturn an independent mutable Knex snapshot, never the query's owned state.
Render debugging SQL without execution; bound values may be sensitive.
Add a synchronous group, retaining the group's inferred named parameters.
Match a record of concrete equality values. Use selectors for parameters.
Match a column and infer a named parameter's storage type.
Add a bound comparison using a supported SQL operator.
Match a fixed value tuple or captured SELECT subquery.
JSON-path strings do not provide a schema-derived parameter type.
Optionaloperator: stringOptionalvalue: A & WithoutParameters<NoInfer<A>>Negate equality while preserving ordinary SQL null semantics.
Match SQL null without changing the declared result type.
Trusted SQL with concrete bindings; use a typed predicate for placeholders.
Trusted SQL with concrete bindings; use a typed predicate for placeholders.
Internal
Apply an already captured Framework predicate to an independent query.
Table query with ORM identity tracking and primary-key lookup helpers.