Libraries v5.0.0
    Preparing search index...

    Class SchemaQueryBuilder<S, Row, Relations, Writable, P, Connected>

    Immutable table query whose row schema follows its decoded selection and relations. Configuration returns independent lazy builders; metadata access never executes SQL. Only unprojected table queries can write. Full ORM rows may participate in tracking.

    Type Parameters

    Hierarchy

    Index
    "[PARAMETER_READER]": TableParameterReader

    Type-only fluent return constructor.

    "[PARAMETER_STATE]": P

    Type-only ordered argument contract.

    "[READ_QUERY]": true

    Nominal identity for typed child-query customizers.

    rowSchema: Row

    Runtime structural schema; stable across filters, pagination and transaction clones.

    • get returnsEntityRows(): boolean

      True only when rows retain their complete entity shape.

      Returns boolean

    • Internal

      Compiled SELECT protocol; never replays consumer callbacks.

      Returns CompiledReader

    • Parameters

      • predicate: ReadPredicate

      Returns this

    • Configure an isolated Knex SELECT once, declaring the complete raw row output.

      Type Parameters

      Parameters

      • configure: (query: QueryBuilder) => QueryBuilder<any, any> | undefined
      • options: QueryOutput<O>

      Returns OpaqueQuery<O>

    • Internal

      Reject writes through projections or loaded relations.

      Returns void

    • Insert in parameter-safe chunks, retaining schema hooks and conflict handling.

      Parameters

      Returns Promise<InferType<Row>[]>

    • Internal

      Compile a bound SQL statement; callers never receive the mutable builder.

      Parameters

      • Optionalcorrelate: ReadCorrelation
      • Optionalmode: typeof COMPILE_PARAMETERS

      Returns QueryBuilder

    • Count matching rows, or non-null column values, without mutating this query. Ignores source ordering/limits/offsets while retaining filters and transactions.

      Type Parameters

      Parameters

      • Optionaloptions: AggregateOptions<O>

        Optional output parser; receives the raw driver value.

      Returns Promise<AggregateResult<O, number>>

      A safe integer by default, including zero for an empty source.

      If the default count overflows, the source is grouped/distinct, or parsing fails.

    • Count non-null column values without mutating the source query. Source paging/order is ignored; filters, scopes and transactions remain.

      Type Parameters

      Parameters

      Returns Promise<AggregateResult<O, number>>

      If the default result overflows or the source is grouped/distinct.

    • Internal

      Decode a SQL/JSON row using the same metadata exposed to consumers.

      Parameters

      • row: any
      • Optionalpath: string

      Returns any

    • Execute one statement and decode its selected row graph.

      Returns Promise<InferType<Row>[]>

    • Execute a limited copy, returning undefined when no row matches.

      Returns Promise<InferType<Row> | undefined>

    • Join a typed collection, applying child projection and pagination independently per parent.

      Type Parameters

      Parameters

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              AddField<
                  Row,
                  K,
                  ArraySchemaBuilder<
                      Child["rowSchema"],
                      true,
                      false,
                      undefined,
                      false,
                      {},
                      Child["rowSchema"] extends undefined
                          ? any[]
                          : Child["rowSchema"] extends SchemaBuilder<T1, T2, false, false, {}>
                              ? (T2 extends true ? T1 : T1 | undefined)[]
                              : never,
                  >,
                  SchemaProps<Row>,
              >,
              Relations & Record<K, RelationInfo<"hasMany", F>>,
              false,
              AttachParameters<P, ParametersOf<Child>, `relation:${K}`>,
              Connected,
          >,
          Connected,
      >

    • Find the largest non-null column value without retaining source paging.

      Type Parameters

      Parameters

      • column: C

        Schema property to aggregate.

      • Optionaloptions: AggregateOptions<O>

        Optional parser replacing default decoding, including null handling.

      Returns Promise<AggregateResult<O, SelectedValue<ReadColumns<S, keyof Relations>, C>>>

      Null for empty/all-null input; otherwise the column representation. Dates return Date; numeric SQL overrides may return exact strings.

    • Find the smallest non-null column value without retaining source paging.

      Type Parameters

      Parameters

      • column: C

        Schema property to aggregate.

      • Optionaloptions: AggregateOptions<O>

        Optional parser replacing default decoding, including null handling.

      Returns Promise<AggregateResult<O, SelectedValue<ReadColumns<S, keyof Relations>, C>>>

      Null for empty/all-null input; otherwise the column representation. Dates return Date; numeric SQL overrides may return exact strings.

    • Type Parameters

      • const A extends readonly RawBinding[]

      Parameters

      • sql: string
      • bindings: A & WithoutParameters<NoInfer<A>>

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              P extends ParameterState ? P : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Parameters

      • sql: string

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              P extends ParameterState ? P : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Fetch a numbered page and a count without mutating the source query.

      Parameters

      • options: { page: number; pageSize: number }

      Returns Promise<PaginationResult<InferType<Row>>>

    • 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.

      Parameters

      Returns Promise<CursorPaginationResult<InferType<Row>>>

    • Read a page using a single raw cursor value; choose a unique, non-null sort column.

      Parameters

      • options: {
            column?: ColumnRef<S>;
            cursor?: unknown;
            direction?: "desc" | "asc";
            limit: number;
        }

      Returns Promise<CursorPaginationResult<InferType<Row>>>

    • Read values of one selected property without altering this query.

      Type Parameters

      • K extends string

      Parameters

      • key: K

      Returns Promise<InferType<SchemaProps<Row>[K]>[]>

    • Apply a named schema projection with the same exact row-schema guarantees.

      Type Parameters

      • K extends string

      Parameters

      • name: K

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              ObjectSchemaBuilder<
                  Pick<
                      SchemaProps<ObjectReadSchema<S>>,
                      Extract<NamedKeys<S, K>, keyof SchemaProps<ObjectReadSchema<S>>>,
                  > & Pick<
                      SchemaProps<Row>,
                      Extract<keyof SchemaProps<Row>, keyof Relations>,
                  >,
                  true,
                  false,
                  undefined,
                  false,
                  {},
                  [],
              >,
              Relations,
              false,
              P,
              Connected,
          >,
          Connected,
      >

    • Returns ReadPredicateContext<ReadColumns<S, keyof Relations>>

    • Internal

      Prevent customizers from substituting an unrelated query source.

      Parameters

      • other: unknown

      Returns boolean

    • Select an exact flat row shape, retaining per-field runtime schemas.

      Type Parameters

      • K extends string

      Parameters

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              ObjectSchemaBuilder<
                  Pick<SchemaProps<ObjectReadSchema<S>>, K>,
                  true,
                  false,
                  undefined,
                  false,
                  {},
                  [],
              >,
              Relations,
              false,
              P,
              Connected,
          >,
          Connected,
      >

    • Select named output fields and aggregates, replacing the previous scalar projection.

      Type Parameters

      • Selected extends Selection

      Parameters

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              ObjectSchemaBuilder<
                  MergeProps<
                      {
                          -readonly [K in string
                          | number
                          | symbol as K extends string ? K : never]-?: Selected[K] extends ReadColumn<
                              R,
                              string,
                          >
                              ? R
                              : Selected[K] extends AggregateExpression<T>
                                  ? SchemaForValue<T>
                                  : never
                      },
                      Pick<SchemaProps<Row>, Extract<keyof SchemaProps<Row>, keyof Relations>>,
                  >,
                  true,
                  false,
                  undefined,
                  false,
                  {},
                  [],
              >,
              Relations,
              false,
              P,
              Connected,
          >,
          Connected,
      >

    • Replace the projection with trusted raw SQL and an explicit output schema.

      Type Parameters

      Parameters

      • sql: string
      • bindings: readonly RawBinding[]
      • options: QueryOutput<O>

      Returns OpaqueQuery<O>

    • Internal

      Native storage columns for composing CTI table sources.

      Returns QueryBuilder

    • Awaiting executes the query; repeated awaits deliberately execute again.

      Type Parameters

      • T = InferType<Row>[]
      • E = never

      Parameters

      • Optionalresolve: ((rows: InferType<Row>[]) => T | PromiseLike<T>) | null
      • Optionalreject: ((error: any) => E | PromiseLike<E>) | null

      Returns Promise<T | E>

    • Return an independent mutable Knex snapshot, never the query's owned state.

      Returns QueryBuilder

    • Render debugging SQL without execution; bound values may be sensitive.

      Returns string

    • Type Parameters

      • S extends string | ((columns: C) => AliasedColumn<any>)
      • const A extends readonly [unknown, unknown]

      Parameters

      • column: S
      • range: A & CheckParameterValue<
            P,
            NoInfer<A>,
            PredicateValue<ReadColumns<S, keyof Relations>, S>,
        >

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              ValueParameters<P, A, PredicateValue<ReadColumns<S, keyof Relations>, S>> extends ParameterState
                  ? ParameterState & ValueParameters<
                      P,
                      A,
                      PredicateValue<ReadColumns<S, keyof Relations>, S>,
                  >
                  : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Type Parameters

      Parameters

      • column: S
      • value: A & (
            A extends QueryParameter<string>
                ? CheckParameterValue<
                    P,
                    NoInfer<A>,
                    PredicateValue<ReadColumns<S, keyof Relations>, S>,
                >
                : string
        )

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              ValueParameters<P, A, PredicateValue<ReadColumns<S, keyof Relations>, S>> extends ParameterState
                  ? ParameterState & ValueParameters<
                      P,
                      A,
                      PredicateValue<ReadColumns<S, keyof Relations>, S>,
                  >
                  : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Type Parameters

      Parameters

      • column: S
      • value: A & (
            A extends QueryParameter<string>
                ? CheckParameterValue<
                    P,
                    NoInfer<A>,
                    PredicateValue<ReadColumns<S, keyof Relations>, S>,
                >
                : string
        )

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              ValueParameters<P, A, PredicateValue<ReadColumns<S, keyof Relations>, S>> extends ParameterState
                  ? ParameterState & ValueParameters<
                      P,
                      A,
                      PredicateValue<ReadColumns<S, keyof Relations>, S>,
                  >
                  : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Negate equality while preserving ordinary SQL null semantics.

      Type Parameters

      Parameters

      • column: S
      • value: A & CheckScalarParameter<
            P,
            NoInfer<A>,
            PredicateValue<ReadColumns<S, keyof Relations>, S>,
        >

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              ValueParameters<P, A, PredicateValue<ReadColumns<S, keyof Relations>, S>> extends ParameterState
                  ? ParameterState & ValueParameters<
                      P,
                      A,
                      PredicateValue<ReadColumns<S, keyof Relations>, S>,
                  >
                  : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Type Parameters

      • S extends string | ((columns: C) => AliasedColumn<any>)
      • const A extends readonly [unknown, unknown]

      Parameters

      • column: S
      • range: A & CheckParameterValue<
            P,
            NoInfer<A>,
            PredicateValue<ReadColumns<S, keyof Relations>, S>,
        >

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              ValueParameters<P, A, PredicateValue<ReadColumns<S, keyof Relations>, S>> extends ParameterState
                  ? ParameterState & ValueParameters<
                      P,
                      A,
                      PredicateValue<ReadColumns<S, keyof Relations>, S>,
                  >
                  : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Trusted SQL with concrete bindings; use a typed predicate for placeholders.

      Type Parameters

      • const A extends readonly RawBinding[]

      Parameters

      • sql: string
      • bindings: A & WithoutParameters<NoInfer<A>>

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              P extends ParameterState ? P : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >

    • Trusted SQL with concrete bindings; use a typed predicate for placeholders.

      Parameters

      • sql: string

      Returns QueryView<
          SchemaQueryBuilder<
              S,
              Row,
              Relations,
              Writable,
              P extends ParameterState ? P : never,
              Connected extends true ? true : false,
          >,
          Connected extends true ? true : false,
      >