kern-orm 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -456,10 +456,12 @@ interface CompileOptions {
456
456
  /** PostgreSQL schema qualifying every table; tables stay unqualified when it is not set. */
457
457
  schemaName?: string;
458
458
  }
459
- /** Value compared with an expression of type `T` accepting values of type `I`; `null` is matched with `isNull` instead. */
460
- type Operand<T, I = T> = NonNullable<I> | AnyExpression<NonNullable<T> | null>;
461
- /** SQL value of an operand, unwrapping an expression. */
462
- type OperandValue<V> = V extends AnyExpression<infer T> ? T : V;
459
+ /**
460
+ * Value compared with an expression of type `T` accepting values of type `I`: a value, an expression, or a query of one value, such as of `get` or of an aggregate; `null` is matched with `isNull` instead.
461
+ */
462
+ type Operand<T, I = T> = NonNullable<I> | AnyExpression<NonNullable<T> | null> | ScalarQuery<NonNullable<T> | null>;
463
+ /** SQL value of an operand, unwrapping an expression or a query. */
464
+ type OperandValue<V> = V extends AnyExpression<infer T> ? T : V extends ScalarQuery ? ScalarQueryValue<V> : V;
463
465
  /** Boolean result that can be NULL when an input value can be NULL. */
464
466
  type BooleanResult<T> = boolean | (null extends T ? null : never);
465
467
  /** Signature of a generic operator comparing an expression with an operand of its type, such as `lt`. */
@@ -467,56 +469,73 @@ interface ComparisonSignature extends OperatorSignature {
467
469
  readonly method: <V extends Operand<this["T"], this["I"]>>(value: V) => Expression<BooleanResult<this["T"] | OperandValue<V>>>;
468
470
  }
469
471
  /**
470
- * Compares an expression with a value or another expression, encoding a plain value with the type of the expression.
472
+ * Compares an expression with a value, another expression, or a query of one value, encoding a plain value with the type of the expression.
471
473
  *
472
474
  * Operators of custom types build comparisons with it, such as `compare(self, "ILIKE", pattern)`.
473
475
  */
474
476
  declare function compare<T, V>(self: AnyExpression<T>, operator: ComparisonNode["operator"], value: V): Expression<BooleanResult<T | OperandValue<V>>>;
475
- /** Runtime mark of the operators of `equalityOperators`, which tell that a type has SQL `=`. */
476
- declare const equalityBrand: unique symbol;
477
- /** Generic operator of `equalityOperators`, which gives the type it is added to SQL `=`. */
478
- interface EqualityOperator<S extends OperatorSignature> extends GenericOperator<S> {
479
- readonly [equalityBrand]: true;
477
+ /** Selection of the rows of a nested query as the value of the field `key`. */
478
+ interface NestedSelectionNode {
479
+ readonly key: string;
480
+ readonly query: QueryNode;
481
+ /** `Db` that the nested query is bound to, which must be the `Db` that runs the statement. */
482
+ readonly db: AnyDb | undefined;
480
483
  }
481
- /** Signature of `in`: membership in a list of operands of the expression type; an empty list yields `FALSE`. */
482
- interface InSignature extends OperatorSignature {
483
- readonly method: <const L extends readonly Operand<this["T"], this["I"]>[]>(list: L) => Expression<L extends readonly [] ? boolean : BooleanResult<this["T"] | OperandValue<L[number]>>>;
484
+ /** Field selected by a query: an expression, or the rows of a nested query. */
485
+ type SelectedNode = ProjectionNode | NestedSelectionNode;
486
+ /** Select query of a table; its result mode applies when it is executed or its rows are nested. */
487
+ interface QueryNode extends ResultMode {
488
+ readonly kind: "query";
489
+ readonly from: TableSourceNode;
490
+ /** Relation whose records the query selects, correlated with its parent by the relation filter. */
491
+ readonly relation: RelationDefinition | undefined;
492
+ /** Fields in the order of the result, with unique keys; a query without them returns records without fields. */
493
+ readonly projections: readonly SelectedNode[];
494
+ readonly filters: QueryFilters;
495
+ readonly orderBy: readonly OrderNode[];
496
+ readonly limit: ExpressionNode | undefined;
497
+ readonly offset: ExpressionNode | undefined;
498
+ /** Whether a required relation guarantees the row of the query, so that a filter makes a query of rows `one` resolve without it; see `SelectQueryState`. */
499
+ readonly guaranteed: boolean;
500
+ /** Whether `all` allows a mutation of the query to change every row of the table without a filter. */
501
+ readonly all: boolean;
484
502
  }
485
- /** Operators of `equalityOperators`. */
486
- type EqualityOperators = {
487
- eq: EqualityOperator<ComparisonSignature>;
488
- ne: EqualityOperator<ComparisonSignature>;
489
- in: EqualityOperator<InSignature>;
490
- };
491
- /** Tells whether operators `O` include an operator of `equalityOperators`, so that their type has SQL `=`. */
492
- type HasEquality<O> = true extends { [K in keyof O]: O[K] extends {
493
- readonly [equalityBrand]: true;
494
- } ? true : false; }[keyof O] ? true : false;
495
503
  /**
496
- * Operators of SQL equality: `eq`, `ne`, and `in`; `orderingOperators` include them.
504
+ * Mutation of a table that returns the fields of the rows it changes, which may nest queries, or the number of the rows without them.
497
505
  *
498
- * A type has SQL `=` only with these operators, so that an array of it has them too; another operator named `eq` does not give it `=`.
506
+ * Its result mode is the rows mode of the rows it changes and whether a row is the value of its only field.
499
507
  */
500
- declare const equalityOperators: EqualityOperators;
508
+ type MutationNode = MutationStatementNode<SelectedNode>;
509
+ /** Query of `$select` without a source: one record whose fields are the values of expressions and the rows of independent queries. */
510
+ interface RecordQueryNode {
511
+ readonly kind: "record";
512
+ /** Fields in the order of the record, with unique keys. */
513
+ readonly projections: readonly SelectedNode[];
514
+ }
501
515
  /** Records of a query without selected fields. */
502
516
  type EmptyRecord = Record<never, never>;
503
517
  /** State of a query in types: the record or value of its rows, how its rows become its result, and the relations it selects records of. */
504
518
  interface QueryState extends ResultMode {
505
- /** Record of a row, or the value of its only field for a query made by `get`, `pluck`, or an aggregate method, such as `count`. */
519
+ /** Record of a row, or the value of its only field for a query made by `get`, `pluck`, an aggregate method, such as `count`, or `exists`. */
506
520
  readonly result: unknown;
507
521
  /** Relations whose records the query and the queries nested in it select, which a `Db` must have. */
508
522
  readonly uses: UsedRelation;
509
523
  }
524
+ /** Type of the value of a query: the values that it encodes, such as the fallback of `coalesce`, and its operators, which `expr` gives its expression. */
525
+ interface QueryValueType {
526
+ readonly input: unknown;
527
+ readonly operators: OperatorDefinitions;
528
+ }
510
529
  /**
511
- * State of a select query in types: its table, the relations of its schema, the record or value of its rows and the values that its value accepts, how its rows become its result, and the relations it selects records of.
530
+ * State of a select query in types: its table, the relations of its schema, the record or value of its rows and the type of its value, how its rows become its result, and the relations it selects records of.
512
531
  *
513
532
  * Methods change only their own parts of the state.
514
533
  */
515
534
  interface SelectQueryState extends QueryState {
516
535
  readonly table: AnyTable;
517
536
  readonly schema: SchemaContext;
518
- /** Values that the type of the value of a query of values encodes, such as the fallback of `coalesce`; `never` for a query of records. */
519
- readonly input: unknown;
537
+ /** Type of the value of a query of values, a `QueryValueType`; `never` for a query of records. */
538
+ readonly valueType: unknown;
520
539
  /**
521
540
  * Whether a required relation guarantees the row of the query, such as of `field.form`.
522
541
  *
@@ -524,7 +543,7 @@ interface SelectQueryState extends QueryState {
524
543
  * The callback of a helper starts with it, so that the effect of the helper records whether the callback filters.
525
544
  */
526
545
  readonly guaranteed: boolean;
527
- /** Whether the query is made by an aggregate method, such as `count`, which makes `get`, `pluck`, and the aggregate methods reject it. */
546
+ /** Whether the query is made by an aggregate method, such as `count`, or by `exists`, which makes `get`, `pluck`, the aggregate methods, and `exists` reject it. */
528
547
  readonly aggregate: boolean;
529
548
  }
530
549
  /** State of a query over table `T` with schema context `C`, whatever its result. */
@@ -539,50 +558,27 @@ interface QueryStateOf<T extends AnyTable, C extends SchemaContext = SchemaConte
539
558
  */
540
559
  interface InitialQueryState<T extends AnyTable, C extends SchemaContext = NoRelations, U extends UsedRelation = never, Rows extends ResultRows = "many", Guaranteed extends boolean = false> extends QueryStateOf<T, C> {
541
560
  readonly result: EmptyRecord;
542
- readonly input: never;
561
+ readonly valueType: never;
543
562
  readonly rows: Rows;
544
563
  readonly value: false;
545
564
  readonly uses: U;
546
565
  readonly guaranteed: Guaranteed;
547
566
  readonly aggregate: false;
548
567
  }
549
- /** Selection of the rows of a nested query as the value of the field `key`. */
550
- interface NestedSelectionNode {
551
- readonly key: string;
552
- readonly query: QueryNode;
553
- /** `Db` that the nested query is bound to, which must be the `Db` that runs the statement. */
554
- readonly db: AnyDb | undefined;
555
- }
556
- /** Field selected by a query: an expression, or the rows of a nested query. */
557
- type SelectedNode = ProjectionNode | NestedSelectionNode;
558
- /** Select query of a table; its result mode applies when it is executed or its rows are nested. */
559
- interface QueryNode extends ResultMode {
560
- readonly kind: "query";
561
- readonly from: TableSourceNode;
562
- /** Relation whose records the query selects, correlated with its parent by the relation filter. */
563
- readonly relation: RelationDefinition | undefined;
564
- /** Fields in the order of the result, with unique keys; a query without them returns records without fields. */
565
- readonly projections: readonly SelectedNode[];
566
- readonly filters: QueryFilters;
567
- readonly orderBy: readonly OrderNode[];
568
- readonly limit: ExpressionNode | undefined;
569
- readonly offset: ExpressionNode | undefined;
570
- /** Whether a required relation guarantees the row of the query, so that a filter makes a query of rows `one` resolve without it; see `SelectQueryState`. */
571
- readonly guaranteed: boolean;
572
- /** Whether `all` allows a mutation of the query to change every row of the table without a filter. */
573
- readonly all: boolean;
574
- }
575
- /**
576
- * Mutation of a table that returns the fields of the rows it changes, which may nest queries, or the number of the rows without them.
577
- *
578
- * Its result mode is the rows mode of the rows it changes and whether a row is the value of its only field.
579
- */
580
- type MutationNode = MutationStatementNode<SelectedNode>;
581
- /** Query of `$select` without a source: one record whose fields are the values of expressions and the rows of independent queries. */
582
- interface RecordQueryNode {
583
- readonly kind: "record";
584
- /** Fields in the order of the record, with unique keys. */
585
- readonly projections: readonly SelectedNode[];
568
+ /** Type of a count: a `bigint` of PostgreSQL decoded as a number, rejecting a count that a number cannot hold exactly. */
569
+ declare const countType: BaseType<number, number, MergeOperators<NoOperators, {
570
+ lt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
571
+ lte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
572
+ gt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
573
+ gte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
574
+ eq: EqualityOperator<ComparisonSignature>;
575
+ ne: EqualityOperator<ComparisonSignature>;
576
+ in: EqualityOperator<InSignature>;
577
+ }>, undefined>;
578
+ /** Type of the value of a query of a count. */
579
+ interface CountValueType extends QueryValueType {
580
+ readonly input: TypeInput<typeof countType>;
581
+ readonly operators: TypeOperators<typeof countType>;
586
582
  }
587
583
  /** Rows mode of a query of a relation of kind `Kind`: `many`, or one row, `nullable` unless `Required` is `true`; a union gives the union of their modes. */
588
584
  type RelationRows<Kind extends RelationKind, Required extends boolean> = Kind extends "many" ? "many" : Required extends true ? "one" : "nullable";
@@ -605,7 +601,7 @@ type ResultByRows<Result, Rows extends ResultRows> = Rows extends "many" ? Resul
605
601
  /** References to the columns of the query source, passed to query callbacks. */
606
602
  type ColumnRefs<T extends AnyTable> = { readonly [K in keyof T["columns"]]: Expression<Selectable<T>[K], ColumnOperators<T, K>, ColumnValues<T>[K]>; };
607
603
  /**
608
- * Queries of the records of the relations of the table of schema context `C`, by relation name, which the callback of `select` receives beside the columns.
604
+ * Queries of the records of the relations of the table of schema context `C`, by relation name, which the callbacks of `select`, `where`, and `orderBy` receive beside the columns.
609
605
  *
610
606
  * A relation name is never a column key of its table.
611
607
  * A context whose table key is not known, such as one of a query of any schema, has no relations.
@@ -616,9 +612,14 @@ type RelationQueries<R extends SchemaContext["relations"], K extends keyof R & s
616
612
  type RelatedQuery<R extends SchemaContext["relations"], K extends keyof R & string, N extends keyof R[K] & string> = SelectQuery<InitialQueryState<R[K][N]["target"], TableContext<R, R[K][N]["targetKey"]>, UsedRelation<K, N, R[K][N]>, RelationRows<R[K][N]["kind"], R[K][N]["required"]>, R[K][N]["required"]>>;
617
613
  /** Runtime context of the queries of a table in the schema they start from. */
618
614
  interface QueryContext {
619
- /** Getters of the queries of the relations of the table, which the references of `select` have as their own properties and which read the key columns from them. */
615
+ /** Getters of the queries of the relations of the table, which the references of the callbacks of `select`, `where`, and `orderBy` have as their own properties and which read the key columns from them. */
620
616
  readonly relations: PropertyDescriptorMap;
621
617
  }
618
+ /** Type of the value of a query of `exists`. */
619
+ interface ExistsValueType extends QueryValueType {
620
+ readonly input: boolean;
621
+ readonly operators: EqualityOperators;
622
+ }
622
623
  declare const conditionValues: unique symbol;
623
624
  /** Predicate accepted by `where`, `and`, `or`, and `not`; SQL treats a `NULL` predicate as not satisfied. */
624
625
  type Predicate = AnyExpression<boolean | null>;
@@ -631,11 +632,11 @@ interface Condition<V> {
631
632
  readonly [conditionValues]?: V;
632
633
  }
633
634
  /**
634
- * Operand of `and`, `or`, and `not`: a predicate, a condition, or an object of column values.
635
+ * Operand of `and`, `or`, and `not`: a predicate, a query of one Boolean value, such as of `exists`, a condition, or an object of column values.
635
636
  *
636
637
  * Column values `V` are never inferred from an object, so that object keys are checked against the table instead of determining `V`.
637
638
  */
638
- type ConditionOperand<V, T extends boolean | null = boolean | null> = AnyExpression<T> | Condition<V> | NoInfer<V>;
639
+ type ConditionOperand<V, T extends boolean | null = boolean | null> = AnyExpression<T> | ScalarQuery<T> | Condition<V> | NoInfer<V>;
639
640
  /**
640
641
  * Result of `and`, `or`, and `not`: a condition checked against the table inside `where`, a Boolean expression without a table.
641
642
  */
@@ -653,29 +654,34 @@ declare function not<V = never, T extends boolean | null = [V] extends [never] ?
653
654
  */
654
655
  type WhereValues<T extends AnyTable> = { [K in keyof T["columns"]]?: EqValue<T, K> | (null extends ColumnValues<T>[K] ? null : never); };
655
656
  /** Operand of the `eq` operator of column `K` of table `T` in an object passed to `where`, such as an expression. */
656
- type EqValue<T extends AnyTable, K extends keyof T["columns"]> = IsAny<ColumnOperators<T, K>> extends true ? ColumnValues<T>[K] : EqOperand<ColumnRefs<T>[K]>;
657
- /** Operand of the `eq` operator of an expression, if it has one taking a single operand. */
657
+ type EqValue<T extends AnyTable, K extends keyof T["columns"]> = IsAny<ColumnOperators<T, K>> extends true ? ColumnValues<T>[K] : ColumnOperators<T, K> extends {
658
+ readonly eq: EqualityOperator<ComparisonSignature>;
659
+ } ? Operand<TypeOutput<T["columns"][K]["type"]>, TypeInput<T["columns"][K]["type"]>> : EqOperand<ColumnRefs<T>[K]>;
660
+ /** Operand of the `eq` operator of an expression, if it has one taking a single operand and returning a predicate. */
658
661
  type EqOperand<E> = E extends {
659
662
  eq: (value: infer V) => Predicate;
660
663
  } ? V : never;
661
- /** Filter of `where`: a Boolean expression, an object of column values, or their combination with `and`, `or`, and `not`. */
664
+ /** Filter of `where`: a Boolean expression, a query of one Boolean value, such as of `exists`, an object of column values, or their combination with `and`, `or`, and `not`. */
662
665
  type WhereCondition<T extends AnyTable> = ConditionOperand<WhereValues<T>>;
663
- /** Argument of `where`: a condition, or a callback that receives the columns of the query and returns one. */
664
- type WhereFilter<T extends AnyTable> = WhereCondition<T> | ((columns: ColumnRefs<T>) => WhereCondition<T>);
666
+ /** Callback of `where` over table `T` with schema context `C`: it receives the columns and the queries of the relations of the table and returns a condition. */
667
+ type WhereCallback<T extends AnyTable, C extends SchemaContext = NoRelations> = (columns: ColumnRefs<T> & RelationRefs<C>) => WhereCondition<T>;
668
+ /** Argument of `where` of a query over table `T` with schema context `C`: a condition, or a callback that receives the columns and the relations of the query and returns one. */
669
+ type WhereFilter<T extends AnyTable, C extends SchemaContext = NoRelations> = WhereCondition<T> | WhereCallback<T, C>;
665
670
  /**
666
671
  * Defines a reusable condition of `where` for queries over a table, checking its objects of column values against the columns.
667
672
  *
668
673
  * The condition can be combined further with `and`, `or`, and `not`.
669
674
  */
670
- declare function defineFilter<T extends AnyTable>(table: TableOrQuery<T>, filter: NoInfer<WhereCondition<T>>): WhereCondition<T>;
675
+ declare function defineFilter<T extends AnyTable, C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, filter: NoInfer<WhereCondition<T>>): WhereCondition<T>;
671
676
  /**
672
677
  * Defines a reusable callback of `where` for queries over a table, checking its objects of column values against the columns.
673
678
  *
674
- * Another callback can call it with its columns.
679
+ * Defined with a query of a schema or a `Db`, such as `schema.form`, it receives the queries of the relations of the table in that schema, and applies to queries whose schema has them.
680
+ * Another callback of `where` can call it with the columns and the relations it receives.
675
681
  */
676
- declare function defineFilter<T extends AnyTable>(table: TableOrQuery<T>, filter: NoInfer<(columns: ColumnRefs<T>) => WhereCondition<T>>): (columns: ColumnRefs<T>) => WhereCondition<T>;
682
+ declare function defineFilter<T extends AnyTable, C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, filter: NoInfer<WhereCallback<T, C>>): WhereCallback<T, C>;
677
683
  /** Defines a reusable filter of `where` for queries over a table, either a condition or a callback. */
678
- declare function defineFilter<T extends AnyTable>(table: TableOrQuery<T>, filter: NoInfer<WhereFilter<T>>): WhereFilter<T>;
684
+ declare function defineFilter<T extends AnyTable, C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, filter: NoInfer<WhereFilter<T, C>>): WhereFilter<T, C>;
679
685
  /**
680
686
  * Values of the primary key of table `T` that `find` takes, in the order of its columns, or `never` where the type of `T` tells no primary key.
681
687
  *
@@ -703,26 +709,56 @@ type OrderColumns<T extends AnyTable> = { readonly [K in keyof T["columns"]]?: O
703
709
  /** Argument of `orderBy` of a query over table `T`: a column key, sorted in ascending order, or columns with directions. */
704
710
  type OrderKey<T extends AnyTable> = (keyof T["columns"] & string) | OrderColumns<T>;
705
711
  declare const ordering: unique symbol;
706
- /** Expression with the direction of its sort key, made by `asc`, `desc`, or `orderBy`. */
712
+ /** Expression or query of one value with the direction of its sort key, made by `asc`, `desc`, or `orderBy`. */
707
713
  interface Ordering {
708
714
  readonly [ordering]: true;
709
715
  }
710
- /** Sort key returned by the callback of `orderBy`: an expression, sorted in ascending order, or an expression with a direction. */
711
- type OrderTerm = AnyExpression | Ordering;
716
+ /** Sort key returned by the callback of `orderBy`: an expression or a query of one value, such as of an aggregate of related records, sorted in ascending order, or one with a direction. */
717
+ type OrderTerm = AnyExpression | ScalarQuery | Ordering;
712
718
  /**
713
719
  * References of the callback of `orderBy` to the fields of records `R` selected by a query: their expressions by key.
714
720
  *
715
- * A field of a nested query, such as of nested rows or of an aggregate, is among them in types, but reading it throws.
721
+ * A field of nested rows is among them in types, but reading it throws; a field of an aggregate or of `exists` sorts by its value.
716
722
  */
717
723
  type SelectedRefs<R> = { readonly [K in keyof R & string]: AnyExpression<R[K]>; };
718
724
  /** Sort keys returned by the callback of `orderBy`: one or an array of them. */
719
725
  type OrderTerms = OrderTerm | readonly OrderTerm[];
720
- /** Sorts by `expression` in ascending order, in the callback of `orderBy`. */
721
- declare function asc(expression: AnyExpression): Ordering;
722
- /** Sorts by `expression` in descending order, in the callback of `orderBy`. */
723
- declare function desc(expression: AnyExpression): Ordering;
724
- /** Sorts by `expression` in `direction`, such as `"desc nulls last"`, in the callback of `orderBy`. */
725
- declare function orderBy(expression: AnyExpression, direction: OrderDirection): Ordering;
726
+ /** Sorts by `value`, an expression or a query of one value, in ascending order, in the callback of `orderBy`. */
727
+ declare function asc(value: AnyExpression | ScalarQuery): Ordering;
728
+ /** Sorts by `value`, an expression or a query of one value, in descending order, in the callback of `orderBy`. */
729
+ declare function desc(value: AnyExpression | ScalarQuery): Ordering;
730
+ /** Sorts by `value`, an expression or a query of one value, in `direction`, such as `"desc nulls last"`, in the callback of `orderBy`. */
731
+ declare function orderBy(value: AnyExpression | ScalarQuery, direction: OrderDirection): Ordering;
732
+ /** Expressions and nested queries selected under the keys of the result fields; a record has no symbol keys. */
733
+ interface Selection {
734
+ readonly [key: string]: TypedExpression | NestedQuery;
735
+ readonly [key: symbol]: never;
736
+ }
737
+ /** Query whose rows a selection nests as the value of a field: a query of any state and kind, such as a query of a relation. */
738
+ type NestedQuery = QueryOf<SelectQueryState>;
739
+ /** Record of the values of the expressions and of the nested rows of a selection. */
740
+ type SelectionResult<S extends Selection> = { [K in keyof S]: FieldValue<S[K]>; };
741
+ /** Value of a selected field: of an expression, or of the nested rows of a query as the result of executing it, for each member of a union of them. */
742
+ type FieldValue<V> = V extends NestedQuery ? QueryResult<V["types"]> : ExpressionValue<V>;
743
+ /** Relations whose records the nested queries of a selection select. */
744
+ type SelectionUses<S extends Selection> = S[keyof S] extends (infer V) ? V extends NestedQuery ? V["types"]["uses"] : never : never;
745
+ /** Value of a selected expression. */
746
+ type ExpressionValue<E> = E extends AnyExpression<infer T> ? T : never;
747
+ /** Values that the type of an expression encodes, such as in place of its value. */
748
+ type ExpressionInput<E> = E extends AnyExpression<unknown, infer I> ? I : never;
749
+ declare const helperFields: unique symbol;
750
+ /** Marker of the input fields of a helper, carrying the keys selected by its callback. */
751
+ interface HelperFields<Keys extends PropertyKey = PropertyKey> {
752
+ readonly [helperFields]: Keys;
753
+ }
754
+ /** Records with `Fields` added or replaced, for each branch of either record type; `any` stays `any`. */
755
+ type MergeSelection<Previous, Fields> = Previous extends unknown ? Fields extends unknown ? MergeFields<RecordFields<Previous>, RecordFields<Fields>> & (IsAny<Previous> extends true ? Previous : unknown) : never : never;
756
+ /** Fields with numeric keys represented as the string keys used in result records. */
757
+ type RecordFields<Fields> = Fields extends unknown ? [Extract<keyof Fields, number>] extends [never] ? Fields : { [K in keyof Fields as K extends number ? `${K}` : K]: Fields[K]; } : never;
758
+ /** Merge of normalized fields, retaining the previous value when an optional replacement is absent. */
759
+ type MergeFields<Previous, Fields> = Simplify<{ [K in keyof Previous as K extends keyof Fields ? ({} extends Pick<Fields, K> ? K : never) : K]: K extends typeof helperFields // A branch selecting extra keys must not be reduced to one selecting fewer fields or none.
760
+ ? Previous[K] | keyof Fields : K extends keyof Fields // A decoder can return undefined, so it cannot be excluded as merely an absent property.
761
+ ? Previous[K] | Fields[K] : Previous[K]; } & { [K in keyof Fields as K extends keyof Previous ? ({} extends Pick<Fields, K> ? never : K) : K]: Fields[K]; }>;
726
762
  /** Value of column `K` of table `T` that an insert or an update sets: a value that its type encodes, `null` for a nullable column, or an expression of its values. */
727
763
  type ColumnValue<T extends AnyTable, K extends keyof T["columns"]> = ColumnValues<T>[K] | AnyExpression<Selectable<T>[K]>;
728
764
  /** Key of a column of table `T` that an insert may omit, which gets its default: one that the database gives a value, as `hasDefault` marks it, or a nullable one, whose default is `NULL` unless the database declares another. */
@@ -749,6 +785,43 @@ type FoundState<S extends SelectQueryState> = ChangeState<S, {
749
785
  }>;
750
786
  /** Query of state `S`, bound or unbound. */
751
787
  type QueryOf<S extends SelectQueryState> = SelectQuery<S, SelectQueryKind>;
788
+ declare const scalarValue: unique symbol;
789
+ /** Value of a query of state `S` in an expression: its value, or `NULL` without its row unless the query always has it. */
790
+ type ScalarValue<S extends SelectQueryState> = S["aggregate"] extends true ? S["result"] : S["guaranteed"] extends true ? S["result"] : S["result"] | null;
791
+ /**
792
+ * Query of one value of a table, such as of `get`, of an aggregate, or of `exists`, which an expression takes as a scalar subquery of its value, or as `EXISTS` of the rows of a query of `exists`.
793
+ *
794
+ * `T` is its value there: without its row, a query of `get` is `NULL`, unless a required relation guarantees the row, such as of `field.form`.
795
+ */
796
+ interface ScalarQuery<T = unknown> {
797
+ /** Value of the query in an expression, from which an expression infers `T`. */
798
+ readonly [scalarValue]: T;
799
+ readonly types: ScalarQueryState;
800
+ readonly exists: unknown;
801
+ }
802
+ /** Value of query `Q` of one value in an expression. */
803
+ type ScalarQueryValue<Q extends ScalarQuery> = Q[typeof scalarValue];
804
+ /** State of a query of one value, which an expression takes. */
805
+ interface ScalarQueryState extends SelectQueryState {
806
+ readonly rows: "one" | "optional";
807
+ readonly value: true;
808
+ }
809
+ /** State of a query of one value with the type of its value, whose expression `expr` gives. */
810
+ interface ExpressionQueryState extends ScalarQueryState {
811
+ readonly valueType: QueryValueType;
812
+ }
813
+ /** Query of values of a table of any rows, such as of `pluck`, whose value is `T`, which `in` takes as a subquery of its values. */
814
+ interface ValuesQuery<T = unknown> {
815
+ readonly types: ValuesQueryState<T>;
816
+ readonly exists: unknown;
817
+ }
818
+ /** Value of query `Q` of values, of each of its rows. */
819
+ type ValuesQueryValue<Q extends ValuesQuery> = Q["types"]["result"];
820
+ /** State of a query of values whose value is `T`. */
821
+ interface ValuesQueryState<T> extends SelectQueryState {
822
+ readonly result: T;
823
+ readonly value: true;
824
+ }
752
825
  /** State of a query whose rows are records, which `select` and `clearSelect` change. */
753
826
  type RecordQueryState$1 = SelectQueryState & {
754
827
  readonly value: false;
@@ -757,25 +830,47 @@ type RecordQueryState$1 = SelectQueryState & {
757
830
  type UnguaranteedQueryState = SelectQueryState & {
758
831
  readonly guaranteed: false;
759
832
  };
760
- /** State of a query whose rows are values, made by `get`, `pluck`, or an aggregate method, such as `count`. */
833
+ /** State of a query whose rows are values, made by `get`, `pluck`, an aggregate method, such as `count`, or `exists`. */
761
834
  type ValueQueryState = SelectQueryState & {
762
835
  readonly value: true;
763
836
  };
764
- /** State of a query not made by an aggregate method, which `get`, `pluck`, and the aggregate methods apply to. */
837
+ /** State of a query of values with the values that the type of its value encodes, which `coalesce` takes; it narrows nothing else, so that a call compares no operators. */
838
+ type CoalesceQueryState = ValueQueryState & {
839
+ readonly valueType: {
840
+ readonly input: unknown;
841
+ };
842
+ };
843
+ /** State of a query not made by an aggregate method or `exists`, which `get`, `pluck`, the aggregate methods, and `exists` apply to. */
765
844
  type UnaggregatedQueryState = SelectQueryState & {
766
845
  readonly aggregate: false;
767
846
  };
768
- /** State of a query of the value `V` of an aggregate over the rows of a query of state `S`, which always returns one row, accepting values `I` in place of its value. */
769
- type AggregateState<S extends SelectQueryState, V, I> = ChangeState<S, {
847
+ /** Type of the value of a query of column `K` of table `T`. */
848
+ type ColumnValueType<T extends AnyTable, K extends keyof T["columns"]> = {
849
+ readonly input: ColumnValues<T>[K];
850
+ readonly operators: ColumnOperators<T, K>;
851
+ };
852
+ /** Type of the value of a query of expression `E`. */
853
+ type ExpressionValueType<E extends TypedExpression> = {
854
+ readonly input: ExpressionInput<E>;
855
+ readonly operators: ExpressionOperators<E>;
856
+ };
857
+ /** State of a query of the value `V` of type `Type` of an aggregate or of `exists` over the rows of a query of state `S`, which always returns one row. */
858
+ type AggregateState<S extends SelectQueryState, V, Type extends QueryValueType> = ChangeState<S, {
770
859
  result: V;
771
- input: I;
860
+ valueType: Type;
772
861
  rows: "one";
773
862
  value: true;
774
863
  guaranteed: false;
775
864
  aggregate: true;
776
865
  }>;
866
+ /** State of a query of the number of rows or of values among the rows of a query of state `S`. */
867
+ type CountState<S extends SelectQueryState> = AggregateState<S, number, CountValueType>;
868
+ /** State of a query of an aggregate of the values of column `K` of the rows of a query of state `S`, `NULL` without values other than `NULL`. */
869
+ type ColumnAggregateState<S extends SelectQueryState, K extends keyof S["table"]["columns"]> = AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValueType<S["table"], K>>;
870
+ /** State of a query of an aggregate of the values of expression `E` over the rows of a query of state `S`, `NULL` without values other than `NULL`. */
871
+ type ExpressionAggregateState<S extends SelectQueryState, E extends TypedExpression> = AggregateState<S, ExpressionValue<E> | null, ExpressionValueType<E>>;
777
872
  /** Value `V` of a query of values whose `NULL` `coalesce` replaces with fallback `F`. */
778
- type CoalescedValue<V, F> = Exclude<V, null> | (F extends AnyExpression<infer T> ? Extract<T, null> : never);
873
+ type CoalescedValue<V, F> = Exclude<V, null> | Extract<OperandValue<F>, null>;
779
874
  /** State of a query of many rows, which `limit` and `offset` apply to. */
780
875
  type ManyRowsQueryState = SelectQueryState & {
781
876
  readonly rows: "many";
@@ -801,6 +896,8 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
801
896
  /** Relations of the table in the schema the query starts from, which `select` gives its callback. */
802
897
  readonly context: QueryContext;
803
898
  readonly types: S;
899
+ /** Value of the query in an expression, for types only. */
900
+ readonly [scalarValue]: ScalarValue<S>;
804
901
  /** `Db` that executes the query when it is awaited; `undefined` for an unbound query. */
805
902
  readonly db: QueryDb<Kind>;
806
903
  /** Executes a bound query on its `Db`; `undefined` for an unbound query, so that it is not thenable. */
@@ -808,14 +905,14 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
808
905
  constructor(table: S["table"], node: QueryNode,
809
906
  /** Relations of the table in the schema the query starts from, which `select` gives its callback. */
810
907
  context: QueryContext, db?: AnyDb);
811
- /** Adds a filter combined with `AND` with the previous ones. */
812
- where<Q extends QueryOf<UnguaranteedQueryState>>(this: Q, filter: WhereFilter<Q["types"]["table"]>): Q;
908
+ /** Adds a filter combined with `AND` with the previous ones; a callback receives the columns and the queries of the relations of the table. */
909
+ where<Q extends QueryOf<UnguaranteedQueryState>>(this: Q, filter: WhereFilter<Q["types"]["table"], Q["types"]["schema"]>): Q;
813
910
  /**
814
- * Adds a filter combined with `AND` with the previous ones.
911
+ * Adds a filter combined with `AND` with the previous ones; a callback receives the columns and the queries of the relations of the table.
815
912
  *
816
913
  * A query of the record of a required relation, such as `field.form`, resolves to `null` without a record that passes the filter, or to `undefined` after `get` or `pluck`.
817
914
  */
818
- where<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, filter: WhereFilter<S["table"]>): SelectQuery<FilteredState<S>, Kind>;
915
+ where<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, filter: WhereFilter<S["table"], S["schema"]>): SelectQuery<FilteredState<S>, Kind>;
819
916
  /** Selects all columns of the table, replacing fields under their keys. */
820
917
  select<S extends RecordQueryState$1, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, all: "*"): SelectQuery<ChangeState<S, {
821
918
  result: MergeSelection<S["result"], Selectable<S["table"]>>;
@@ -871,7 +968,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
871
968
  */
872
969
  get<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ChangeState<S, {
873
970
  result: Selectable<S["table"]>[K];
874
- input: ColumnValues<S["table"]>[K];
971
+ valueType: ColumnValueType<S["table"], K>;
875
972
  rows: OneValueRows<S["rows"]>;
876
973
  value: true;
877
974
  }>, Kind>;
@@ -884,7 +981,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
884
981
  */
885
982
  get<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ChangeState<S, {
886
983
  result: ExpressionValue<E>;
887
- input: ExpressionInput<E>;
984
+ valueType: ExpressionValueType<E>;
888
985
  rows: OneValueRows<S["rows"]>;
889
986
  value: true;
890
987
  }>, Kind>;
@@ -895,7 +992,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
895
992
  */
896
993
  pluck<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ChangeState<S, {
897
994
  result: Selectable<S["table"]>[K];
898
- input: ColumnValues<S["table"]>[K];
995
+ valueType: ColumnValueType<S["table"], K>;
899
996
  rows: ValueRows<S["rows"]>;
900
997
  value: true;
901
998
  }>, Kind>;
@@ -906,7 +1003,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
906
1003
  */
907
1004
  pluck<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ChangeState<S, {
908
1005
  result: ExpressionValue<E>;
909
- input: ExpressionInput<E>;
1006
+ valueType: ExpressionValueType<E>;
910
1007
  rows: ValueRows<S["rows"]>;
911
1008
  value: true;
912
1009
  }>, Kind>;
@@ -915,65 +1012,79 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
915
1012
  *
916
1013
  * It keeps the filters and ignores the order; with `limit` or `offset`, it counts the rows of that page.
917
1014
  */
918
- count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>): SelectQuery<AggregateState<S, number, number>, Kind>;
1015
+ count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>): SelectQuery<CountState<S>, Kind>;
919
1016
  /** Replaces the selected fields with the number of the values of the column other than `NULL` among the rows of the query and returns it instead of the rows. */
920
- count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, number, number>, Kind>;
1017
+ count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<CountState<S>, Kind>;
921
1018
  /** Replaces the selected fields with the number of the values other than `NULL` of the expression returned by `callback` among the rows of the query and returns it instead of the rows. */
922
- count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, number, number>, Kind>;
1019
+ count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<CountState<S>, Kind>;
923
1020
  /** Replaces the selected fields with the number of the distinct values of the column other than `NULL` among the rows of the query and returns it instead of the rows. */
924
- countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, number, number>, Kind>;
1021
+ countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<CountState<S>, Kind>;
925
1022
  /** Replaces the selected fields with the number of the distinct values other than `NULL` of the expression returned by `callback` among the rows of the query and returns it instead of the rows. */
926
- countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, number, number>, Kind>;
1023
+ countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<CountState<S>, Kind>;
927
1024
  /** Replaces the selected fields with the smallest value of the column among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
928
- min<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1025
+ min<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
929
1026
  /** Replaces the selected fields with the smallest value of the expression returned by `callback` among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
930
- min<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1027
+ min<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
931
1028
  /** Replaces the selected fields with the largest value of the column among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
932
- max<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1029
+ max<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
933
1030
  /** Replaces the selected fields with the largest value of the expression returned by `callback` among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
934
- max<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1031
+ max<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
935
1032
  /** Replaces the selected fields with the sum of the values of the column among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
936
- sum<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1033
+ sum<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
937
1034
  /** Replaces the selected fields with the sum of the values of the expression returned by `callback` among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`. */
938
- sum<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1035
+ sum<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
939
1036
  /** Replaces the selected fields with the average of the values of the column among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`; for `bigint` values, average an expression of a type that can represent fractional values. */
940
- avg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1037
+ avg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
941
1038
  /** Replaces the selected fields with the average of the values of the expression returned by `callback` among the rows of the query and returns it instead of the rows, or `null` without values other than `NULL`; for `bigint` values, average an expression of a type that can represent fractional values. */
942
- avg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1039
+ avg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
943
1040
  /** Replaces the selected fields with whether every value of the Boolean column other than `NULL` among the rows of the query is true and returns it instead of the rows, or `null` without such values. */
944
- every<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1041
+ every<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
945
1042
  /** Replaces the selected fields with whether every value other than `NULL` of the Boolean expression returned by `callback` among the rows of the query is true and returns it instead of the rows, or `null` without such values. */
946
- every<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1043
+ every<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
947
1044
  /** Replaces the selected fields with whether any value of the Boolean column among the rows of the query is true and returns it instead of the rows, or `null` without values other than `NULL`. */
948
- some<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1045
+ some<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<ColumnAggregateState<S, K>, Kind>;
949
1046
  /** Replaces the selected fields with whether any value of the Boolean expression returned by `callback` among the rows of the query is true and returns it instead of the rows, or `null` without values other than `NULL`. */
950
- some<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1047
+ some<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
951
1048
  /** Replaces the selected fields with the values of the text column other than `NULL` among the rows of the query, joined with `delimiter` in the order of the query, and returns them instead of the rows, or `null` without such values. */
952
- stringAgg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K, delimiter: string): SelectQuery<AggregateState<S, Selectable<S["table"]>[K] | null, ColumnValues<S["table"]>[K]>, Kind>;
1049
+ stringAgg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K, delimiter: string): SelectQuery<ColumnAggregateState<S, K>, Kind>;
953
1050
  /** Replaces the selected fields with the values other than `NULL` of the text expression returned by `callback` among the rows of the query, joined with `delimiter` in the order of the query, and returns them instead of the rows, or `null` without such values. */
954
- stringAgg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E, delimiter: string): SelectQuery<AggregateState<S, ExpressionValue<E> | null, ExpressionInput<E>>, Kind>;
1051
+ stringAgg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedExpression>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]>) => E, delimiter: string): SelectQuery<ExpressionAggregateState<S, E>, Kind>;
1052
+ /**
1053
+ * Replaces the selected fields with whether the query has a row and returns it instead of the rows, such as to filter by related records in `where`.
1054
+ *
1055
+ * It keeps the filters, the limit, and the offset, and ignores the order.
1056
+ */
1057
+ exists<S extends UnaggregatedQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>): SelectQuery<AggregateState<S, boolean, ExistsValueType>, Kind>;
955
1058
  /**
956
1059
  * Replaces a `NULL` value of a query of values, such as one made by `get`, `pluck`, or an aggregate, with `fallback`, such as `0` for a sum without rows.
957
1060
  *
958
- * `fallback` is a value that the type of the value accepts or an expression of its values, such as a column of the row of a parent query.
1061
+ * `fallback` is a value that the type of the value accepts, an expression of its values, such as a column of the row of a parent query, or a query of one such value.
959
1062
  * A missing row stays missing: an optional query still resolves to `undefined` without a row.
960
1063
  */
961
- coalesce<S extends ValueQueryState, Kind extends SelectQueryKind, F extends Operand<S["result"], S["input"]>>(this: SelectQuery<S, Kind>, fallback: F): SelectQuery<ChangeState<S, {
1064
+ coalesce<S extends CoalesceQueryState, Kind extends SelectQueryKind, F extends Operand<S["result"], S["valueType"]["input"]>>(this: SelectQuery<S, Kind>, fallback: F): SelectQuery<ChangeState<S, {
962
1065
  result: CoalescedValue<S["result"], F>;
963
1066
  }>, Kind>;
1067
+ /**
1068
+ * Returns an expression of the value of a query of one value, such as of `get` or of an aggregate, with the operators of its type, such as `form.fields.count().expr().gt(3)`.
1069
+ *
1070
+ * Without a row, the expression is `NULL`, and the query does not reject.
1071
+ */
1072
+ expr<Q extends QueryOf<ExpressionQueryState>>(this: Q): Expression<ScalarQueryValue<Q>, Q["types"]["valueType"]["operators"], Q["types"]["valueType"]["input"]>;
964
1073
  /**
965
1074
  * Sorts the rows by the sort keys returned by `callback`, after the sort keys of earlier calls.
966
1075
  *
967
- * `callback` receives the columns and the fields selected so far, and returns an expression, sorted in ascending order, `asc`, `desc`, or `orderBy` of an expression, or an array of them.
968
- * A selected field sorts by the value of the field, also when it changes from row to row, such as `random()`.
1076
+ * `callback` receives the columns with the queries of the relations of the table, and the fields selected so far.
1077
+ * It returns an expression or a query of one value, such as of an aggregate of related records, sorted in ascending order, `asc`, `desc`, or `orderBy` of one, or an array of them.
1078
+ * A selected field sorts by the value of the field, also when it changes from row to row, such as `random()`; a field of nested rows cannot be sorted by.
969
1079
  */
970
- orderBy<Q extends QueryOf<RecordQueryState$1>>(this: Q, callback: (columns: ColumnRefs<Q["types"]["table"]>, selected: SelectedRefs<Q["types"]["result"]>) => OrderTerms): Q;
1080
+ orderBy<Q extends QueryOf<RecordQueryState$1>>(this: Q, callback: (columns: ColumnRefs<Q["types"]["table"]> & RelationRefs<Q["types"]["schema"]>, selected: SelectedRefs<Q["types"]["result"]>) => OrderTerms): Q;
971
1081
  /**
972
1082
  * Sorts the values of a query made by `get` or `pluck` by the sort keys returned by `callback`, after the sort keys of earlier calls.
973
1083
  *
974
- * `callback` receives the columns and the expression of the value, and returns an expression, sorted in ascending order, `asc`, `desc`, or `orderBy` of an expression, or an array of them.
1084
+ * `callback` receives the columns with the queries of the relations of the table, and the expression of the value.
1085
+ * It returns an expression or a query of one value, sorted in ascending order, `asc`, `desc`, or `orderBy` of one, or an array of them.
975
1086
  */
976
- orderBy<Q extends QueryOf<ValueQueryState>>(this: Q, callback: (columns: ColumnRefs<Q["types"]["table"]>, value: AnyExpression<Q["types"]["result"]>) => OrderTerms): Q;
1087
+ orderBy<Q extends QueryOf<ValueQueryState>>(this: Q, callback: (columns: ColumnRefs<Q["types"]["table"]> & RelationRefs<Q["types"]["schema"]>, value: AnyExpression<Q["types"]["result"]>) => OrderTerms): Q;
977
1088
  /** Sorts the rows by the listed columns in ascending order, or in the directions of objects of columns, after the sort keys of earlier calls. */
978
1089
  orderBy<Q extends AnySelectQuery>(this: Q, ...keys: OrderKey<Q["types"]["table"]>[]): Q;
979
1090
  /** Returns at most `count` rows of a query of many rows, replacing an earlier limit. */
@@ -1045,6 +1156,18 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
1045
1156
  * A query bound to a `Db` compiles as the `Db` executes it, with the PostgreSQL schema of the `Db`, and rejects options.
1046
1157
  */
1047
1158
  toSQL(...args: ToSQLArgs<Kind>): SqlStatement;
1159
+ /**
1160
+ * Returns the node of the query as an operand of an expression, which lowering replaces with a scalar subquery of its value, or with `EXISTS` of its rows for a query of `exists`.
1161
+ *
1162
+ * It rejects a query of records or of rows `many`, which `ScalarQuery` rejects in types.
1163
+ */
1164
+ [operandNode](): ExpressionNode;
1165
+ /**
1166
+ * Returns the node of the query as the values of `in`, which lowering replaces with its statement.
1167
+ *
1168
+ * It rejects a query of records, which `ValuesQuery` rejects in types.
1169
+ */
1170
+ [valuesQueryNode](): NestedQueryNode;
1048
1171
  /** Creates a query of the same kind and `Db` with the node changes applied. */
1049
1172
  private derive;
1050
1173
  /**
@@ -1053,7 +1176,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
1053
1176
  * It adds the changes of `take` to `changes`, which must leave the limit as it is.
1054
1177
  */
1055
1178
  private deriveTaken;
1056
- /** Creates the query of the value of `projection`, an aggregate over the rows of this query, which always returns one row. */
1179
+ /** Creates the query of the value of `projection`, of an aggregate or of `exists` over the rows of this query, which always returns one row. */
1057
1180
  private deriveAggregate;
1058
1181
  /** Creates the query of the aggregate of `method` over `arg`, a column key or a callback that receives the columns and returns an expression; `delimiter` is the delimiter of `stringAgg`. */
1059
1182
  private aggregateBy;
@@ -1065,7 +1188,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
1065
1188
  private changeOneRow;
1066
1189
  /** Rejects a change of the selection by `method` of a query made by `get`, `pluck`, or an aggregate method. */
1067
1190
  private rejectValue;
1068
- /** Rejects `method`, which replaces the value or the selection, on a query made by an aggregate method. */
1191
+ /** Rejects `method`, which replaces the value or the selection, on a query made by an aggregate method or `exists`. */
1069
1192
  private rejectAggregate;
1070
1193
  }
1071
1194
  /** Select query bound to a `Db`, executed by awaiting it; every method returns a query bound to the same `Db`. */
@@ -1078,36 +1201,34 @@ type ResultOf<Q extends AnyQuery> = Q["types"]["result"];
1078
1201
  type TableOrQuery<T extends AnyTable, C extends SchemaContext = SchemaContext> = T | QueryOf<QueryStateOf<T, C>>;
1079
1202
  /** Starts a query over a new occurrence of the table. */
1080
1203
  declare function from<T extends AnyTable>(table: T): SelectQuery<InitialQueryState<T>>;
1081
- /** Expressions and nested queries selected under the keys of the result fields; a record has no symbol keys. */
1082
- interface Selection {
1083
- readonly [key: string]: TypedExpression | NestedQuery;
1084
- readonly [key: symbol]: never;
1204
+ /** Runtime mark of the operators of `equalityOperators`, which tell that a type has SQL `=`. */
1205
+ declare const equalityBrand: unique symbol;
1206
+ /** Generic operator of `equalityOperators`, which gives the type it is added to SQL `=`. */
1207
+ interface EqualityOperator<S extends OperatorSignature> extends GenericOperator<S> {
1208
+ readonly [equalityBrand]: true;
1085
1209
  }
1086
- /** Query whose rows a selection nests as the value of a field: a query of any state and kind, such as a query of a relation. */
1087
- type NestedQuery = QueryOf<SelectQueryState>;
1088
- /** Record of the values of the expressions and of the nested rows of a selection. */
1089
- type SelectionResult<S extends Selection> = { [K in keyof S]: FieldValue<S[K]>; };
1090
- /** Value of a selected field: of an expression, or of the nested rows of a query as the result of executing it, for each member of a union of them. */
1091
- type FieldValue<V> = V extends NestedQuery ? QueryResult<V["types"]> : ExpressionValue<V>;
1092
- /** Relations whose records the nested queries of a selection select. */
1093
- type SelectionUses<S extends Selection> = S[keyof S] extends (infer V) ? V extends NestedQuery ? V["types"]["uses"] : never : never;
1094
- /** Value of a selected expression. */
1095
- type ExpressionValue<E> = E extends AnyExpression<infer T> ? T : never;
1096
- /** Values that the type of an expression encodes, such as in place of its value. */
1097
- type ExpressionInput<E> = E extends AnyExpression<unknown, infer I> ? I : never;
1098
- declare const helperFields: unique symbol;
1099
- /** Marker of the input fields of a helper, carrying the keys selected by its callback. */
1100
- interface HelperFields<Keys extends PropertyKey = PropertyKey> {
1101
- readonly [helperFields]: Keys;
1210
+ /** Key of the method of a query of a table that returns its node as the values of `in`, or rejects a query of records. */
1211
+ declare const valuesQueryNode: unique symbol;
1212
+ /** Signature of `in`: membership in a list of operands of the expression type, or in the values of a query, such as of `pluck`; an empty list or query yields `FALSE`. */
1213
+ interface InSignature extends OperatorSignature {
1214
+ readonly method: <const L extends readonly Operand<this["T"], this["I"]>[] | ValuesQuery<NonNullable<this["T"]> | null>>(list: L) => Expression<L extends readonly unknown[] ? L extends readonly [] ? boolean : BooleanResult<this["T"] | OperandValue<L[number]>> : BooleanResult<this["T"] | (L extends ValuesQuery ? ValuesQueryValue<L> : never)>>;
1102
1215
  }
1103
- /** Records with `Fields` added or replaced, for each branch of either record type; `any` stays `any`. */
1104
- type MergeSelection<Previous, Fields> = Previous extends unknown ? Fields extends unknown ? MergeFields<RecordFields<Previous>, RecordFields<Fields>> & (IsAny<Previous> extends true ? Previous : unknown) : never : never;
1105
- /** Fields with numeric keys represented as the string keys used in result records. */
1106
- type RecordFields<Fields> = Fields extends unknown ? [Extract<keyof Fields, number>] extends [never] ? Fields : { [K in keyof Fields as K extends number ? `${K}` : K]: Fields[K]; } : never;
1107
- /** Merge of normalized fields, retaining the previous value when an optional replacement is absent. */
1108
- type MergeFields<Previous, Fields> = Simplify<{ [K in keyof Previous as K extends keyof Fields ? ({} extends Pick<Fields, K> ? K : never) : K]: K extends typeof helperFields // A branch selecting extra keys must not be reduced to one selecting fewer fields or none.
1109
- ? Previous[K] | keyof Fields : K extends keyof Fields // A decoder can return undefined, so it cannot be excluded as merely an absent property.
1110
- ? Previous[K] | Fields[K] : Previous[K]; } & { [K in keyof Fields as K extends keyof Previous ? ({} extends Pick<Fields, K> ? never : K) : K]: Fields[K]; }>;
1216
+ /** Operators of `equalityOperators`. */
1217
+ type EqualityOperators = {
1218
+ eq: EqualityOperator<ComparisonSignature>;
1219
+ ne: EqualityOperator<ComparisonSignature>;
1220
+ in: EqualityOperator<InSignature>;
1221
+ };
1222
+ /** Tells whether operators `O` include an operator of `equalityOperators`, so that their type has SQL `=`. */
1223
+ type HasEquality<O> = true extends { [K in keyof O]: O[K] extends {
1224
+ readonly [equalityBrand]: true;
1225
+ } ? true : false; }[keyof O] ? true : false;
1226
+ /**
1227
+ * Operators of SQL equality: `eq`, `ne`, and `in`; `orderingOperators` include them.
1228
+ *
1229
+ * A type has SQL `=` only with these operators, so that an array of it has them too; another operator named `eq` does not give it `=`.
1230
+ */
1231
+ declare const equalityOperators: EqualityOperators;
1111
1232
  /** State of a query of `$select` in types: one record `R`, whose nested queries select records of relations `U`. */
1112
1233
  interface RecordQueryState<R = unknown, U extends UsedRelation = UsedRelation> extends QueryState {
1113
1234
  readonly result: R;
@@ -1137,6 +1258,8 @@ declare class RecordQuery<out S extends RecordQueryState, out Kind extends Selec
1137
1258
  * A query bound to a `Db` compiles as the `Db` executes it, with the PostgreSQL schema of the `Db`, and rejects options.
1138
1259
  */
1139
1260
  toSQL(...args: ToSQLArgs<Kind>): SqlStatement;
1261
+ /** Rejects the query as an operand of an expression, which takes a query of one value of a table. */
1262
+ [operandNode](): never;
1140
1263
  }
1141
1264
  /** Query of `$select` of any state and kind. */
1142
1265
  type AnyRecordQuery = RecordQuery<any, SelectQueryKind>;
@@ -1456,6 +1579,8 @@ declare class MutationQuery<out S extends MutationQueryState, out Kind extends S
1456
1579
  * A query bound to a `Db` compiles as the `Db` executes it, with the PostgreSQL schema of the `Db`, and rejects options.
1457
1580
  */
1458
1581
  toSQL(...args: ToSQLArgs<Kind>): SqlStatement;
1582
+ /** Rejects the query as an operand of an expression, which takes a query of one value of a table. */
1583
+ [operandNode](): never;
1459
1584
  /** Creates a mutation of the same kind and `Db` with the node changes applied. */
1460
1585
  private derive;
1461
1586
  /** Creates the mutation that returns the value of `arg` of `method`, a column key or a callback that receives the columns and returns an expression, of each changed row. */
@@ -1580,6 +1705,8 @@ declare class SqlQuery<out S extends SqlQueryState> {
1580
1705
  nullable<S extends OneRecordSqlQueryState>(this: SqlQuery<S>): SqlQuery<RowsState<S, "nullable">>;
1581
1706
  /** Compiles the query into SQL text and parameters, as its `Db` executes it. */
1582
1707
  toSQL(): SqlStatement;
1708
+ /** Rejects the query as an operand of an expression, which takes a query of one value of a table. */
1709
+ [operandNode](): never;
1583
1710
  /** Creates a query of the same `Db` with the node changes applied. */
1584
1711
  private derive;
1585
1712
  /** Creates the query that returns the value of the only column of each row in rows mode `rows`, decoded by `type` of `method`. */
@@ -1685,6 +1812,19 @@ declare class TransactionCoordinator {
1685
1812
  * A failed cleanup after an error rejects with a `SuppressedError` that keeps the original error in its `suppressed` chain.
1686
1813
  */
1687
1814
  transaction<T>(callback: () => Promise<T>, options?: TransactionOptions): Promise<T>;
1815
+ /**
1816
+ * Runs `callback` in the current transaction, or in a new transaction outside of one.
1817
+ *
1818
+ * Joining starts no savepoint, so a rejection of `callback` does not undo its changes.
1819
+ * It rejects without calling `callback` when the current level accepts no statements, as a nested transaction would.
1820
+ */
1821
+ ensureTransaction<T>(callback: () => Promise<T>): Promise<T>;
1822
+ /**
1823
+ * Tells whether the current async context runs in a transaction of `transaction`.
1824
+ *
1825
+ * A test transaction and the seed of a test fixture are not transactions, unless they run inside one, so that code under test behaves as in production.
1826
+ */
1827
+ isInTransaction(): boolean;
1688
1828
  /**
1689
1829
  * Runs `callback` in a transaction that always rolls back, on a coordinator created for tests.
1690
1830
  *
@@ -1755,6 +1895,22 @@ interface Database extends AsyncDisposable {
1755
1895
  * Inside an existing transaction, it starts a nested transaction.
1756
1896
  */
1757
1897
  transaction<T>(callback: () => Promise<T>, options?: TransactionOptions): Promise<T>;
1898
+ /**
1899
+ * Runs `callback` in the current transaction without a nested transaction, or in a new transaction outside of one.
1900
+ *
1901
+ * A rejection of a callback that joined a transaction does not undo its changes: the enclosing transaction commits them unless it fails too.
1902
+ * A test transaction is not a transaction to join: there, it starts a nested transaction where it starts a transaction in production.
1903
+ */
1904
+ ensureTransaction<T>(callback: () => Promise<T>): Promise<T>;
1905
+ /** Tells whether the code runs in a transaction, not counting test transactions, so that code under test sees what it sees in production. */
1906
+ isInTransaction(): boolean;
1907
+ /**
1908
+ * Takes the advisory lock of `key` until the transaction ends, waiting while another transaction holds it, such as to keep processes from running the same job at once.
1909
+ *
1910
+ * It rejects where `isInTransaction()` is `false`, since outside a transaction the lock would end with its statement.
1911
+ * A nested transaction that rolls back releases the locks it took.
1912
+ */
1913
+ lock(key: string): Promise<void>;
1758
1914
  /** Rolls back the open test fixtures and closes the connections of the driver once the running transactions end. */
1759
1915
  close(): Promise<void>;
1760
1916
  }
@@ -1830,7 +1986,7 @@ interface DbMethods<T extends Tables, R extends SchemaRelations> {
1830
1986
  /**
1831
1987
  * Starts a query of the SQL statement of the template, which resolves to the number of the rows of its command tag when awaited, such as the rows that an `UPDATE` changes; `select`, `get`, and `pluck` return the fields of its rows instead.
1832
1988
  *
1833
- * Interpolated values become query parameters, `sql` fragments and expressions stay SQL, and a table of the `Db`, such as `db.form`, becomes its name, qualified by the PostgreSQL schema of the `Db`.
1989
+ * Interpolated values become query parameters, `sql` fragments and expressions stay SQL, a table of the `Db`, such as `db.form`, becomes its name, qualified by the PostgreSQL schema of the `Db`, and another query becomes a subquery, as in `sql`.
1834
1990
  */
1835
1991
  $query(strings: TemplateStringsArray, ...values: unknown[]): SqlQuery<InitialSqlQueryState>;
1836
1992
  /**
@@ -1842,7 +1998,7 @@ interface DbMethods<T extends Tables, R extends SchemaRelations> {
1842
1998
  /**
1843
1999
  * Executes the script of the template as `$script` of its text does.
1844
2000
  *
1845
- * It interpolates tables of the `Db`, such as `db.form`, and `sql` fragments without values; it rejects values, since a script has no parameters.
2001
+ * It interpolates tables of the `Db`, such as `db.form`, and queries and `sql` fragments without parameters; it rejects values, since a script has no parameters.
1846
2002
  */
1847
2003
  $script(strings: TemplateStringsArray, ...values: unknown[]): Promise<void>;
1848
2004
  /**
@@ -1851,6 +2007,22 @@ interface DbMethods<T extends Tables, R extends SchemaRelations> {
1851
2007
  * Inside an existing transaction, it starts a nested transaction.
1852
2008
  */
1853
2009
  $transaction<Result>(callback: () => Promise<Result>, options?: TransactionOptions): Promise<Result>;
2010
+ /**
2011
+ * Runs `callback` in the current transaction without a nested transaction, or in a new transaction of the database outside of one.
2012
+ *
2013
+ * A rejection of a callback that joined a transaction does not undo its changes: the enclosing transaction commits them unless it fails too.
2014
+ * A test transaction is not a transaction to join: there, it starts a nested transaction where it starts a transaction in production.
2015
+ */
2016
+ $ensureTransaction<Result>(callback: () => Promise<Result>): Promise<Result>;
2017
+ /** Tells whether the code runs in a transaction of the database, not counting test transactions, so that code under test sees what it sees in production. */
2018
+ $isInTransaction(): boolean;
2019
+ /**
2020
+ * Takes the advisory lock of `key` until the transaction of the database ends, waiting while another transaction holds it, such as to keep processes from running the same job at once.
2021
+ *
2022
+ * It rejects where `$isInTransaction()` is `false`, since outside a transaction the lock would end with its statement.
2023
+ * A nested transaction that rolls back releases the locks it took.
2024
+ */
2025
+ $lock(key: string): Promise<void>;
1854
2026
  }
1855
2027
  /**
1856
2028
  * `Db` of schema `S`, such as the type of a parameter of code shared by several schemas.
@@ -1927,6 +2099,19 @@ interface ValuesNode {
1927
2099
  readonly kind: "values";
1928
2100
  readonly values: Readonly<Record<string, unknown>>;
1929
2101
  }
2102
+ /**
2103
+ * Query of a table in an expression, such as of `exists` in a condition, which lowering replaces with the SQL of its value before compilation.
2104
+ *
2105
+ * A query interpolated into SQL text may be of records or of rows `many`, which lowering replaces with its statement.
2106
+ */
2107
+ interface NestedQueryNode {
2108
+ readonly kind: "nestedQuery";
2109
+ readonly query: QueryNode;
2110
+ /** `Db` that the query is bound to, which must be the `Db` that runs the statement. */
2111
+ readonly db: AnyDb | undefined;
2112
+ /** Selected field of an aggregate or of `exists` whose value the node is, in a reference of the callback of `orderBy`, by which lowering sorts by the projection of the field. */
2113
+ readonly field?: NestedSelectionNode;
2114
+ }
1930
2115
  interface ComparisonNode {
1931
2116
  readonly kind: "comparison";
1932
2117
  readonly operator: "=" | "<>" | "<" | "<=" | ">" | ">=" | "LIKE" | "ILIKE";
@@ -1939,6 +2124,13 @@ interface InNode {
1939
2124
  /** Never empty: an empty list is represented as a `FALSE` boolean node. */
1940
2125
  readonly list: readonly ExpressionNode[];
1941
2126
  }
2127
+ /** `IN` of the values of a query, such as of `pluck`, whatever its rows. */
2128
+ interface InQueryNode {
2129
+ readonly kind: "inQuery";
2130
+ readonly operand: ExpressionNode;
2131
+ /** Query of the values: a query in an expression, which lowering replaces with its statement of one projection. */
2132
+ readonly query: NestedQueryNode | SelectNode;
2133
+ }
1942
2134
  interface IsNullNode {
1943
2135
  readonly kind: "isNull";
1944
2136
  readonly operand: ExpressionNode;
@@ -1966,6 +2158,11 @@ interface ExistsNode {
1966
2158
  readonly kind: "exists";
1967
2159
  readonly query: SelectNode;
1968
2160
  }
2161
+ /** Subquery interpolated into SQL text: its query in parentheses, of any fields and rows, which the text reads, such as with `EXISTS` or in `FROM`. */
2162
+ interface TextSubqueryNode {
2163
+ readonly kind: "textSubquery";
2164
+ readonly query: SelectNode;
2165
+ }
1969
2166
  /** Call of an aggregate function over the rows of its query, with the order of its input rows. */
1970
2167
  interface AggregateNode {
1971
2168
  readonly kind: "aggregate";
@@ -1976,7 +2173,7 @@ interface AggregateNode {
1976
2173
  readonly arguments: readonly ExpressionNode[];
1977
2174
  readonly orderBy: readonly OrderNode[];
1978
2175
  }
1979
- type ExpressionNode = ColumnRefNode | ParamNode | CastNode | BooleanNode | AndNode | OrNode | NotNode | ValuesNode | ComparisonNode | InNode | IsNullNode | RawSqlNode | TableNameNode | SubqueryNode | ExistsNode | AggregateNode;
2176
+ type ExpressionNode = ColumnRefNode | ParamNode | CastNode | BooleanNode | AndNode | OrNode | NotNode | ValuesNode | NestedQueryNode | ComparisonNode | InNode | InQueryNode | IsNullNode | RawSqlNode | TableNameNode | SubqueryNode | ExistsNode | TextSubqueryNode | AggregateNode;
1980
2177
  /**
1981
2178
  * Filters of a query, kept apart so that composing one kind never changes the others.
1982
2179
  *
@@ -2076,6 +2273,8 @@ interface TextStatementNode extends ResultMode {
2076
2273
  declare const valueType: unique symbol;
2077
2274
  declare const inputType: unique symbol;
2078
2275
  declare const typed: unique symbol;
2276
+ /** Key of the method of an expression and of every class of queries that returns its node as an operand of an expression, or rejects a query that cannot be one. */
2277
+ declare const operandNode: unique symbol;
2079
2278
  /** Expression of TypeScript type `T` accepting compared values of type `I`, whatever its operators. */
2080
2279
  interface AnyExpression<T = unknown, I = unknown> {
2081
2280
  readonly [valueType]: T;
@@ -2090,19 +2289,163 @@ type ExpressionWithOperators<T, O extends OperatorDefinitions, I> = AnyExpressio
2090
2289
  * It has `isNull` and the operators `O` of its type, which also decodes its values, so it can be selected.
2091
2290
  * The AST node behind it is internal.
2092
2291
  */
2093
- type Expression<T = unknown, O extends OperatorDefinitions = EqualityOperators, I = T> = ExpressionWithOperators<T, O, I> & TypedExpression<T>;
2292
+ type Expression<T = unknown, O extends OperatorDefinitions = EqualityOperators, I = T> = ExpressionWithOperators<T, O, I> & TypedExpression<T, O>;
2094
2293
  /**
2095
2294
  * Expression of TypeScript type `T` without a type, such as a fragment of `sql<T>`, with the operators of `equalityOperators`.
2096
2295
  *
2097
2296
  * Nothing decodes its values to `T`, so it cannot be selected.
2098
2297
  */
2099
2298
  type UntypedExpression<T = unknown> = ExpressionWithOperators<T, EqualityOperators, NoInfer<T>>;
2100
- /** Expression that has a type to decode its values, which `select`, `get`, and `pluck` require. */
2101
- type TypedExpression<T = unknown> = AnyExpression<T> & {
2102
- readonly [typed]: true;
2299
+ /** Expression that has a type to decode its values, which `select`, `get`, and `pluck` require, with the operators `O` of the type. */
2300
+ type TypedExpression<T = unknown, O extends OperatorDefinitions = any> = AnyExpression<T> & {
2301
+ readonly [typed]: O;
2103
2302
  };
2303
+ /** Operators of expression `E`. */
2304
+ type ExpressionOperators<E extends TypedExpression> = E[typeof typed];
2104
2305
  /** Operators of expressions of every type. */
2105
2306
  interface BaseOperators {
2106
2307
  isNull(): Expression<boolean>;
2107
2308
  }
2108
- export { many as $, BaseType as $n, Predicate as $t, SqlQuery as A, ColumnDefinitions as An, UpdateSet as At, Relation as B, defineTable as Bn, desc as Bt, createTestHelpers as C, ComparisonSignature as Cn, FilteredStateRows as Ct, DecodedFields as D, CompileOptions as Dn, from as Dt, AnySqlQuery as E, compare as En, TableOrQuery as Et, MutationQueryState as F, Selectable as Fn, OrderTerm as Ft, RelationKind as G, ResultRows as Gn, EqValue as Gt, RelationDeclarations as H, RequiredRelationError as Hn, KeyCheck as Ht, DeclaredRelations as I, Table as In, OrderTerms as It, SchemaRelations as J, DriverResult as Jn, WhereValues as Jt, RequiredMember as K, Connection as Kn, WhereCondition as Kt, MergeRelations as L, TableKeys as Ln, Ordering as Lt, AnyMutationQuery as M, ColumnShape as Mn, OrderColumns as Mt, InitialMutationState as N, ColumnValues as Nn, OrderDirection as Nt, FieldTypes as O, AnyTable as On, ColumnValue as Ot, MutationQuery as P, KeyColumns as Pn, OrderKey as Pt, UsedRelation as Q, AnyType as Qn, ConditionOperand as Qt, NoRelations as R, TableOptions as Rn, SelectedRefs as Rt, TestTransactionOptions as S, BooleanResult as Sn, ChangeState as St, SelectQueryKind as T, OperandValue as Tn, SelectQuery as Tt, RelationKey as U, ResultDecodeError as Un, NotAKey as Ut, RelationDeclaration as V, NotFoundError as Vn, orderBy as Vt, RelationKeys as W, ResultMode as Wn, PrimaryKeyValues as Wt, TableRelations as X, TransactionFailure as Xn, CombinedCondition as Xt, TableContext as Y, SqlStatement as Yn, defineFilter as Yt, UsableRelation as Z, createStatement as Zn, Condition as Zt, OpenedTestFixture as _, EqualityOperator as _n, GenericOperator as _r, Selection as _t, UntypedExpression as a, RelationRefs as an, TypeOutput as ar, SchemaTables as at, TestHelpers as b, InSignature as bn, defineGenericOperator as br, AnySelectQuery as bt, Db as c, OneValueRows as cn, AnyColumn as cr, AnyRecordQuery as ct, DbQueryState as d, ValueRows as dn, KeyKind as dr, SelectionState as dt, and as en, TextValue as er, one as et, Database as f, EmptyRecord as fn, ToColumn as fr, ExpressionInput as ft, TransactionCoordinator as g, SelectQueryState as gn, OperatorDefinitions as gr, NestedQuery as gt, createDatabase as h, QueryStateOf as hn, NoOperators as hr, MergeSelection as ht, TypedExpression as i, QueryContext as in, TypeOptions as ir, SchemaPartRelations as it, SqlQueryState as j, ColumnOperators as jn, UpdateValues as jt, InitialSqlQueryState as k, AnyTableKeys as kn, InsertValues as kt, DbMutationState as l, QueryResult as ln, Column as lr, RecordQuery as lt, TransactionOptions as m, QueryState as mn, MergeOperators as mr, HelperFields as mt, BaseOperators as n, or as nn, TypeInput as nr, Schema as nt, AnyDb as o, FilteredRows as on, TypeTransform as or, Tables as ot, DatabaseOptions as p, InitialQueryState as pn, BoundOperators as pr, ExpressionValue as pt, SchemaContext as q, Driver as qn, WhereFilter as qt, Expression as r, ColumnRefs as rn, TypeOperators as rr, SchemaPart as rt, BindOptions as s, OneRow as sn, defineType as sr, defineSchema as st, AnyExpression as t, not as tn, Type as tr, AnySchema as tt, DbOf as u, ResultByRows as un, ColumnAttributes as ur, RecordQueryState as ut, PendingTestFixture as v, EqualityOperators as vn, GenericOperatorImplementation as vr, SelectionResult as vt, AnyQuery as w, Operand as wn, ResultOf as wt, TestHooks as x, equalityOperators as xn, BoundSelectQuery as xt, TestFixture as y, HasEquality as yn, OperatorSignature as yr, SelectionUses as yt, OneRelationKeys as z, ToColumns as zn, asc as zt };
2309
+ /** Operators of ordered types: those of `equalityOperators`, and `lt`, `lte`, `gt`, and `gte` comparing with operands of the expression type. */
2310
+ declare const orderingOperators: {
2311
+ lt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
2312
+ lte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
2313
+ gt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
2314
+ gte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
2315
+ eq: EqualityOperator<ComparisonSignature>;
2316
+ ne: EqualityOperator<ComparisonSignature>;
2317
+ in: EqualityOperator<InSignature>;
2318
+ };
2319
+ /** Signature of pattern matching: patterns stay strings even when the text values are transformed. */
2320
+ interface PatternSignature extends OperatorSignature {
2321
+ readonly method: <V extends Operand<string>>(pattern: V) => Expression<BooleanResult<this["T"] | OperandValue<V>>>;
2322
+ }
2323
+ /**
2324
+ * Operators of text types: pattern matching with `LIKE` and `ILIKE`.
2325
+ *
2326
+ * A string pattern is sent as it is; `param(type, pattern)` encodes it with a type.
2327
+ */
2328
+ declare const textOperators: {
2329
+ like: GenericOperator<PatternSignature, AnyExpression<string | null, unknown>>;
2330
+ ilike: GenericOperator<PatternSignature, AnyExpression<string | null, unknown>>;
2331
+ };
2332
+ /**
2333
+ * State of the query that the callback of a helper of table `T` with schema context `C` receives: the fields of the query the helper is applied to, and all its rows.
2334
+ *
2335
+ * It is guaranteed, so that the state that the callback returns tells whether the callback ends the guarantee of the query the helper is applied to.
2336
+ */
2337
+ interface HelperState<T extends AnyTable, C extends SchemaContext> extends QueryStateOf<T, C> {
2338
+ readonly result: HelperFields<never>;
2339
+ readonly valueType: never;
2340
+ readonly rows: "many";
2341
+ readonly value: false;
2342
+ readonly uses: never;
2343
+ readonly guaranteed: true;
2344
+ readonly aggregate: false;
2345
+ }
2346
+ /**
2347
+ * Effect of a helper: the fields it selects, its rows mode on a query of many rows, `one` after `take` or `required` and `nullable` or `optional` after the method of the same name, the relations it selects records of, and whether it keeps the guarantee of the row of a query of a required relation.
2348
+ *
2349
+ * `reads` are the relations of the schema of the helper among them, which its callback may read from the references of the query it is applied to, and `key` is the key of its table there.
2350
+ */
2351
+ interface HelperEffect {
2352
+ readonly fields: object;
2353
+ readonly rows: ResultRows;
2354
+ readonly uses: UsedRelation;
2355
+ readonly reads: UsedRelation;
2356
+ readonly key: string;
2357
+ readonly guaranteed: boolean;
2358
+ }
2359
+ /** Effect of a helper whose callback returns a query of state `S`, for each state of a union. */
2360
+ type ReadEffect<S extends SelectQueryState> = S extends SelectQueryState ? {
2361
+ readonly fields: { [K in keyof S["result"] as K extends keyof HelperFields ? never : K]: S["result"][K]; };
2362
+ readonly rows: S["rows"];
2363
+ readonly uses: S["uses"];
2364
+ readonly reads: Extract<UsableRelation<S["schema"]["relations"]>, S["uses"]>;
2365
+ readonly key: S["schema"]["key"];
2366
+ readonly guaranteed: S["guaranteed"];
2367
+ } : never;
2368
+ /** Error of a helper that a query does not accept, or whose callback returns a query it does not accept. */
2369
+ interface HelperError<Message extends string> {
2370
+ readonly error: Message;
2371
+ }
2372
+ /** `unknown` when every result state retains the input marker and returns records, or the error. */
2373
+ type CheckResult<S extends SelectQueryState> = [S] extends [{
2374
+ readonly result: HelperFields;
2375
+ readonly value: false;
2376
+ }] ? unknown : HelperError<"A helper can filter, select fields, and take one row, but cannot clear the selection or use get, pluck, or aggregates">;
2377
+ /** State of a query over table `T` that accepts a helper of effect `E`. */
2378
+ type HelperInput<T extends AnyTable, E extends HelperEffect> = QueryStateOf<T, ReadsContext<E>> & ValueCheck<E>;
2379
+ /** Constraint of `value` of a query that accepts a helper of effect `E`. */
2380
+ type ValueCheck<E extends HelperEffect> = [E extends HelperEffect ? keyof E["fields"] : never] extends [never] ? [Extract<E["rows"], "nullable">] extends [never] ? unknown : RecordRows<"A helper cannot apply nullable to a query made by get, pluck, or an aggregate"> : RecordRows<"A helper cannot select fields on a query made by get, pluck, or an aggregate">;
2381
+ /** Constraint of a query whose rows are records, which a query of values fails with error `Message`. */
2382
+ interface RecordRows<Message extends string> {
2383
+ readonly value: false | HelperError<Message>;
2384
+ }
2385
+ /** Schema context of a query that has the relations of its schema that a helper of effect `E` may read. */
2386
+ type ReadsContext<E extends HelperEffect> = [E["reads"]] extends [never] ? SchemaContext : SchemaContext<{ readonly [K in E["reads"]["key"]]: { readonly [N in Extract<E["reads"], {
2387
+ readonly key: K;
2388
+ }>["name"]]: Extract<E["reads"], {
2389
+ readonly key: K;
2390
+ readonly name: N;
2391
+ }>["relation"]; }; }, E["key"]>;
2392
+ /** State of a query of state `S` after a helper of effect `E`. */
2393
+ type ApplyEffect<S extends SelectQueryState, E extends HelperEffect> = ChangeState<S, {
2394
+ result: [keyof E["fields"]] extends [never] ? S["result"] : MergeSelection<S["result"], E["fields"]>;
2395
+ rows: E["rows"] extends "many" ? EffectRows<S, E> : E["rows"] extends "one" ? OneRow<EffectRows<S, E>> : E["rows"];
2396
+ uses: S["uses"] | E["uses"];
2397
+ guaranteed: E["guaranteed"] extends true ? S["guaranteed"] : false;
2398
+ }>;
2399
+ /** Rows mode of a query of state `S` after a helper of effect `E` that keeps the rows, before `take`: relaxed as after a filter when the helper ends the guarantee. */
2400
+ type EffectRows<S extends SelectQueryState, E extends HelperEffect> = E["guaranteed"] extends true ? S["rows"] : FilteredStateRows<S>;
2401
+ /**
2402
+ * Helper of `defineHelper` for queries over table `T`: it applies effect `E` to the query it receives with arguments `A` and returns a query of the same kind.
2403
+ *
2404
+ * Selected fields replace earlier fields under the same keys; a query made by `get`, `pluck`, or an aggregate method does not accept a helper that selects fields.
2405
+ */
2406
+ type Helper<T extends AnyTable, E extends HelperEffect, A extends unknown[]> = <S extends HelperInput<T, E>, Kind extends SelectQueryKind>(query: SelectQuery<S, Kind>, ...args: A) => E extends HelperEffect ? SelectQuery<ApplyEffect<S, E>, Kind> : never;
2407
+ /**
2408
+ * Defines a reusable helper of a table that filters, selects fields, and applies `take`, `optional`, `nullable`, and `required`, used with `use` or called with a query.
2409
+ *
2410
+ * `helper` receives the query it is applied to and any further arguments, and returns the query with its clauses.
2411
+ * Defined with a query of a schema, such as `schema.form`, it can select the relations of the table in that schema, and applies to queries whose schema has them.
2412
+ * The helper returns a query of the same kind as the one it is applied to, bound to the same `Db` if any.
2413
+ */
2414
+ declare function defineHelper<T extends AnyTable, R extends SelectQuery<any, SelectQueryKind>, A extends unknown[], C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, helper: (query: SelectQuery<HelperState<T, C>, SelectQueryKind>, ...args: A) => R & CheckResult<R["types"]>): Helper<T, ReadEffect<R["types"]>, A>;
2415
+ /** Tagged template building a SQL fragment of values `T` that accepts compared values `I`. */
2416
+ type SqlTemplate<T, O extends OperatorDefinitions, I = T> = (strings: TemplateStringsArray, ...values: unknown[]) => Expression<T, O, I>;
2417
+ /**
2418
+ * Builds a SQL fragment.
2419
+ *
2420
+ * Interpolated expressions such as column references stay structured, a query of a table without clauses, such as `db.form`, becomes the name of the table, and other values become query parameters.
2421
+ * Another query of a table becomes a subquery in parentheses, and a query of one value, such as of an aggregate or of `exists`, its value, as in a condition.
2422
+ * The type argument declares the TypeScript type of the fragment and does not convert values at runtime, so the fragment cannot be selected; the fragment has `isNull` and the operators of `equalityOperators` only.
2423
+ */
2424
+ declare function sql<T = unknown>(strings: TemplateStringsArray, ...values: unknown[]): UntypedExpression<T>;
2425
+ /**
2426
+ * Creates a template building SQL fragments of `type`.
2427
+ *
2428
+ * The fragments have the operators of the type and encode compared values with it; the type adds no SQL cast.
2429
+ */
2430
+ declare function sql<Output, Input, O extends OperatorDefinitions>(type: Type<Output, Input, O, any>): SqlTemplate<Output, O, Input>;
2431
+ /**
2432
+ * Creates a SQL fragment of a quoted name, such as of a table or a column known only at runtime, for the templates of `sql`, of `$query` and `$script` of a `Db`, and of `query` and `script` of a `Database`.
2433
+ *
2434
+ * Several names make a qualified name, such as `identifier(schema, table)` for `"schema"."table"`.
2435
+ * The fragment has no parameters, so a script takes it.
2436
+ * The name is not qualified by the PostgreSQL schema of the statement.
2437
+ */
2438
+ declare function identifier(...names: [string, ...string[]]): UntypedExpression;
2439
+ /**
2440
+ * Creates an expression of a query parameter encoded with a type, for a value interpolated into `sql` or compared on its own.
2441
+ *
2442
+ * With a type, the parameter is cast to it, such as `$1::integer`, so that PostgreSQL applies the operators of the type even where nothing else in the statement determines it.
2443
+ * The cast omits type parameters, such as `$1::numeric` for `numeric(10,2)`, so that their precision, scale, or length do not constrain the value.
2444
+ *
2445
+ * With an expression, such as `param(self, other)` in an operator definition, the type of the expression encodes the value, and the parameter is not cast: PostgreSQL types it by the expression it is used with.
2446
+ * `value` may then also be an expression, such as an operand of a generic operator, which is returned as it is, with its own type and nullability.
2447
+ * A query of one value becomes an expression with the runtime type of the first argument and the nullability of the query, typed as an `AnyExpression` of its value.
2448
+ */
2449
+ declare function param<Output, Input, O extends OperatorDefinitions>(type: Type<Output, Input, O, any>, value: Input): Expression<Output, O, Input>;
2450
+ declare function param<E extends AnyExpression, V extends (E extends AnyExpression<infer T, infer I> ? Operand<T, I> : never)>(type: E, value: V): V extends AnyExpression ? V : V extends ScalarQuery ? AnyExpression<ScalarQueryValue<V>> : E;
2451
+ export { RelationDeclarations as $, ToColumns as $n, SelectedRefs as $t, TestFixture as A, EmptyRecord as An, OperatorDefinitions as Ar, FilteredStateRows as At, InitialSqlQueryState as B, compare as Bn, ExpressionInput as Bt, Database as C, FilteredRows as Cn, Column as Cr, EqualityOperator as Ct, TransactionCoordinator as D, ResultByRows as Dn, BoundOperators as Dr, equalityOperators as Dt, createDatabase as E, QueryResult as En, ToColumn as Er, InSignature as Et, AnyQuery as F, SelectQueryState as Fn, from as Ft, MutationQuery as G, ColumnOperators as Gn, SelectionResult as Gt, SqlQueryState as H, AnyTable as Hn, MergeSelection as Ht, SelectQueryKind as I, BooleanResult as In, ColumnValue as It, MergeRelations as J, KeyColumns as Jn, OrderDirection as Jt, MutationQueryState as K, ColumnShape as Kn, SelectionUses as Kt, AnySqlQuery as L, ComparisonSignature as Ln, InsertValues as Lt, TestHooks as M, QueryState as Mn, GenericOperatorImplementation as Mr, ScalarQuery as Mt, TestTransactionOptions as N, QueryStateOf as Nn, OperatorSignature as Nr, SelectQuery as Nt, OpenedTestFixture as O, ValueRows as On, MergeOperators as Or, AnySelectQuery as Ot, createTestHelpers as P, QueryValueType as Pn, defineGenericOperator as Pr, ValuesQuery as Pt, RelationDeclaration as Q, TableOptions as Qn, Ordering as Qt, DecodedFields as R, Operand as Rn, UpdateSet as Rt, DbQueryState as S, RelationRefs as Sn, AnyColumn as Sr, SelectionState as St, TransactionOptions as T, OneValueRows as Tn, KeyKind as Tr, HasEquality as Tt, AnyMutationQuery as U, AnyTableKeys as Un, NestedQuery as Ut, SqlQuery as V, CompileOptions as Vn, ExpressionValue as Vt, InitialMutationState as W, ColumnDefinitions as Wn, Selection as Wt, OneRelationKeys as X, Table as Xn, OrderTerm as Xt, NoRelations as Y, Selectable as Yn, OrderKey as Yt, Relation as Z, TableKeys as Zn, OrderTerms as Zt, AnyDb as _, not as _n, TypeOperators as _r, Tables as _t, Helper as a, PrimaryKeyValues as an, ResultRows as ar, SchemaRelations as at, DbMutationState as b, ColumnRefs as bn, TypeTransform as br, RecordQuery as bt, PatternSignature as c, WhereCondition as cn, DriverResult as cr, UsableRelation as ct, AnyExpression as d, defineFilter as dn, createStatement as dr, one as dt, asc as en, defineTable as er, RelationKey as et, BaseOperators as f, CombinedCondition as fn, AnyType as fr, AnySchema as ft, UntypedExpression as g, and as gn, TypeInput as gr, SchemaTables as gt, TypedExpression as h, Predicate as hn, Type as hr, SchemaPartRelations as ht, sql as i, NotAKey as in, ResultMode as ir, SchemaContext as it, TestHelpers as j, InitialQueryState as jn, GenericOperator as jr, ResultOf as jt, PendingTestFixture as k, CountValueType as kn, NoOperators as kr, BoundSelectQuery as kt, textOperators as l, WhereFilter as ln, SqlStatement as lr, UsedRelation as lt, ExpressionOperators as m, ConditionOperand as mn, TextValue as mr, SchemaPart as mt, identifier as n, orderBy as nn, RequiredRelationError as nr, RelationKind as nt, HelperEffect as o, EqValue as on, Connection as or, TableContext as ot, Expression as p, Condition as pn, BaseType as pr, Schema as pt, DeclaredRelations as q, ColumnValues as qn, OrderColumns as qt, param as r, KeyCheck as rn, ResultDecodeError as rr, RequiredMember as rt, defineHelper as s, WhereCallback as sn, Driver as sr, TableRelations as st, SqlTemplate as t, desc as tn, NotFoundError as tr, RelationKeys as tt, orderingOperators as u, WhereValues as un, TransactionFailure as ur, many as ut, BindOptions as v, or as vn, TypeOptions as vr, defineSchema as vt, DatabaseOptions as w, OneRow as wn, ColumnAttributes as wr, EqualityOperators as wt, DbOf as x, QueryContext as xn, defineType as xr, RecordQueryState as xt, Db as y, ExistsValueType as yn, TypeOutput as yr, AnyRecordQuery as yt, FieldTypes as z, OperandValue as zn, UpdateValues as zt };