kern-orm 0.3.0 → 0.5.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.
- package/dist/database-BJ0hNYrF.mjs +3968 -0
- package/dist/{index-CNqYlONX.d.mts → index-Cag6_erK.d.mts} +709 -474
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +66 -3889
- package/dist/testing.d.mts +28 -2
- package/dist/testing.mjs +521 -1
- package/dist/{text-BUNl8wpl.mjs → text-BTFErHIi.mjs} +57 -10
- package/dist/types-D9LtZ9W-.mjs +248 -0
- package/dist/types.d.mts +47 -72
- package/dist/types.mjs +2 -253
- package/package.json +6 -2
|
@@ -209,7 +209,7 @@ interface SqlStatement {
|
|
|
209
209
|
declare function createStatement(text: string, parameters?: readonly TextValue[]): SqlStatement;
|
|
210
210
|
/** Result of a statement. */
|
|
211
211
|
interface DriverResult {
|
|
212
|
-
/** Command tag that PostgreSQL completed the statement with, such as `SELECT` or `ROLLBACK` for a `COMMIT` of a failed transaction
|
|
212
|
+
/** Command of the tag that PostgreSQL completed the statement with, such as `SELECT` or `ROLLBACK` for a `COMMIT` of a failed transaction; a driver may give only the first word of a tag of several words, such as `CREATE` of `CREATE TABLE`. */
|
|
213
213
|
readonly command: string;
|
|
214
214
|
/** Number of rows that the command tag reports, such as the rows that an `UPDATE` changes, also without `RETURNING`; `0` for a command without one, such as `BEGIN`. */
|
|
215
215
|
readonly count: number;
|
|
@@ -273,6 +273,11 @@ interface NestedField {
|
|
|
273
273
|
readonly key: string;
|
|
274
274
|
readonly nested: ResultPlan;
|
|
275
275
|
}
|
|
276
|
+
/** Field of a record in the template of a result plan: its key and its value before the values of a row are assigned. */
|
|
277
|
+
interface RecordTemplateField {
|
|
278
|
+
readonly key: string;
|
|
279
|
+
readonly value: unknown;
|
|
280
|
+
}
|
|
276
281
|
/**
|
|
277
282
|
* How a query returns its rows: `many` as an array; `one` as one row, rejecting without it; `nullable` as one row or `null` without it; `optional` as one row or `undefined` without it.
|
|
278
283
|
*
|
|
@@ -292,6 +297,12 @@ interface ResultPlan extends ResultMode {
|
|
|
292
297
|
readonly fields: readonly ResultField[];
|
|
293
298
|
/** Required relation that guarantees the row of nested rows `one`, such as `field.form`, whose missing row is a `RequiredRelationError` rather than a `NotFoundError`. */
|
|
294
299
|
readonly guaranteedBy?: string | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* Every field of a record in its order, with the values of its literals, which a row does not hold; `undefined` for a query without literals.
|
|
302
|
+
*
|
|
303
|
+
* A record starts from it, so its keys keep their order whichever of them a row holds.
|
|
304
|
+
*/
|
|
305
|
+
readonly recordTemplate?: readonly RecordTemplateField[] | undefined;
|
|
295
306
|
}
|
|
296
307
|
/** Error thrown when a query of one row finds no row, executed or nested, unless a required relation guarantees the row. */
|
|
297
308
|
declare class NotFoundError extends Error {
|
|
@@ -474,6 +485,87 @@ interface ComparisonSignature extends OperatorSignature {
|
|
|
474
485
|
* Operators of custom types build comparisons with it, such as `compare(self, "ILIKE", pattern)`.
|
|
475
486
|
*/
|
|
476
487
|
declare function compare<T, V>(self: AnyExpression<T>, operator: ComparisonNode["operator"], value: V): Expression<BooleanResult<T | OperandValue<V>>>;
|
|
488
|
+
/** Runtime mark of the operators of `equalityOperators`, which tell that a type has SQL `=`. */
|
|
489
|
+
declare const equalityBrand: unique symbol;
|
|
490
|
+
/** Generic operator of `equalityOperators`, which gives the type it is added to SQL `=`. */
|
|
491
|
+
interface EqualityOperator<S extends OperatorSignature> extends GenericOperator<S> {
|
|
492
|
+
readonly [equalityBrand]: true;
|
|
493
|
+
}
|
|
494
|
+
/** 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. */
|
|
495
|
+
declare const valuesQueryNode: unique symbol;
|
|
496
|
+
/** 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`. */
|
|
497
|
+
interface InSignature extends OperatorSignature {
|
|
498
|
+
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)>>;
|
|
499
|
+
}
|
|
500
|
+
/** Operators of `equalityOperators`. */
|
|
501
|
+
type EqualityOperators = {
|
|
502
|
+
eq: EqualityOperator<ComparisonSignature>;
|
|
503
|
+
ne: EqualityOperator<ComparisonSignature>;
|
|
504
|
+
in: EqualityOperator<InSignature>;
|
|
505
|
+
};
|
|
506
|
+
/** Tells whether operators `O` include an operator of `equalityOperators`, so that their type has SQL `=`. */
|
|
507
|
+
type HasEquality<O> = true extends { [K in keyof O]: O[K] extends {
|
|
508
|
+
readonly [equalityBrand]: true;
|
|
509
|
+
} ? true : false; }[keyof O] ? true : false;
|
|
510
|
+
/**
|
|
511
|
+
* Operators of SQL equality: `eq`, `ne`, and `in`; `orderingOperators` include them.
|
|
512
|
+
*
|
|
513
|
+
* 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 `=`.
|
|
514
|
+
*/
|
|
515
|
+
declare const equalityOperators: EqualityOperators;
|
|
516
|
+
/** Records of a query without selected fields. */
|
|
517
|
+
type EmptyRecord = Record<never, never>;
|
|
518
|
+
/** 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. */
|
|
519
|
+
interface QueryState extends ResultMode {
|
|
520
|
+
/** 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`. */
|
|
521
|
+
readonly result: unknown;
|
|
522
|
+
/** Relations whose records the query and the queries nested in it select, which a `Db` must have. */
|
|
523
|
+
readonly uses: UsedRelation;
|
|
524
|
+
}
|
|
525
|
+
/** 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. */
|
|
526
|
+
interface QueryValueType {
|
|
527
|
+
readonly input: unknown;
|
|
528
|
+
readonly operators: OperatorDefinitions;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* 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.
|
|
532
|
+
*
|
|
533
|
+
* Methods change only their own parts of the state.
|
|
534
|
+
*/
|
|
535
|
+
interface SelectQueryState extends QueryState {
|
|
536
|
+
readonly table: AnyTable;
|
|
537
|
+
readonly schema: SchemaContext;
|
|
538
|
+
/** Type of the value of a query of values, a `QueryValueType`; `never` for a query of records. */
|
|
539
|
+
readonly valueType: unknown;
|
|
540
|
+
/**
|
|
541
|
+
* Whether a required relation guarantees the row of the query, such as of `field.form`.
|
|
542
|
+
*
|
|
543
|
+
* The relation does not guarantee a record that also passes a filter, so `where`, `find`, and `findBy` end the guarantee and make rows `one` `nullable`, or `optional` for a query of values; `optional`, `nullable`, and `required` end it as well.
|
|
544
|
+
* The callback of a helper starts with it, so that the effect of the helper records whether the callback filters.
|
|
545
|
+
*/
|
|
546
|
+
readonly guaranteed: boolean;
|
|
547
|
+
/** 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. */
|
|
548
|
+
readonly aggregate: boolean;
|
|
549
|
+
}
|
|
550
|
+
/** State of a query over table `T` with schema context `C`, whatever its result. */
|
|
551
|
+
interface QueryStateOf<T extends AnyTable, C extends SchemaContext = SchemaContext> extends SelectQueryState {
|
|
552
|
+
readonly table: T;
|
|
553
|
+
readonly schema: C;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* State of a query that starts from table `T` with schema context `C`: rows as records without fields, all of them or of the records of relation `U` when given, in rows mode `Rows`, guaranteed by a required relation when `Guaranteed`.
|
|
557
|
+
*
|
|
558
|
+
* Without relations in `C`, it also types a query of the table in a schema that has relations of the table.
|
|
559
|
+
*/
|
|
560
|
+
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> {
|
|
561
|
+
readonly result: EmptyRecord;
|
|
562
|
+
readonly valueType: never;
|
|
563
|
+
readonly rows: Rows;
|
|
564
|
+
readonly value: false;
|
|
565
|
+
readonly uses: U;
|
|
566
|
+
readonly guaranteed: Guaranteed;
|
|
567
|
+
readonly aggregate: false;
|
|
568
|
+
}
|
|
477
569
|
/** Selection of the rows of a nested query as the value of the field `key`. */
|
|
478
570
|
interface NestedSelectionNode {
|
|
479
571
|
readonly key: string;
|
|
@@ -481,8 +573,15 @@ interface NestedSelectionNode {
|
|
|
481
573
|
/** `Db` that the nested query is bound to, which must be the `Db` that runs the statement. */
|
|
482
574
|
readonly db: AnyDb | undefined;
|
|
483
575
|
}
|
|
484
|
-
/**
|
|
485
|
-
|
|
576
|
+
/** Selection of a value from code as the field `key` of every record, which a statement does not select. */
|
|
577
|
+
interface LiteralSelectionNode {
|
|
578
|
+
readonly key: string;
|
|
579
|
+
readonly literal: unknown;
|
|
580
|
+
}
|
|
581
|
+
/** Field that a statement selects: an expression, or the rows of a nested query. */
|
|
582
|
+
type SqlSelectedNode = ProjectionNode | NestedSelectionNode;
|
|
583
|
+
/** Field selected by a query: one that its statement selects, or a literal. */
|
|
584
|
+
type SelectedNode = SqlSelectedNode | LiteralSelectionNode;
|
|
486
585
|
/** Select query of a table; its result mode applies when it is executed or its rows are nested. */
|
|
487
586
|
interface QueryNode extends ResultMode {
|
|
488
587
|
readonly kind: "query";
|
|
@@ -506,102 +605,344 @@ interface QueryNode extends ResultMode {
|
|
|
506
605
|
* Its result mode is the rows mode of the rows it changes and whether a row is the value of its only field.
|
|
507
606
|
*/
|
|
508
607
|
type MutationNode = MutationStatementNode<SelectedNode>;
|
|
509
|
-
/** Query of `$select` without a source: one record whose fields are the values of expressions
|
|
608
|
+
/** Query of `$select` without a source: one record whose fields are the values of expressions, the rows of independent queries, and literals. */
|
|
510
609
|
interface RecordQueryNode {
|
|
511
610
|
readonly kind: "record";
|
|
512
611
|
/** Fields in the order of the record, with unique keys. */
|
|
513
612
|
readonly projections: readonly SelectedNode[];
|
|
514
613
|
}
|
|
515
|
-
/**
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
readonly
|
|
614
|
+
/**
|
|
615
|
+
* Field of a selection whose value is `T`, made by `literal`.
|
|
616
|
+
*
|
|
617
|
+
* It is not an expression: it has no SQL, so only a selection takes it.
|
|
618
|
+
*/
|
|
619
|
+
declare class Literal<out T> {
|
|
620
|
+
/** Value of the field in every record, which the query returns as it is. */
|
|
621
|
+
readonly literal: T;
|
|
622
|
+
constructor(
|
|
623
|
+
/** Value of the field in every record, which the query returns as it is. */
|
|
624
|
+
literal: T);
|
|
625
|
+
/** Rejects the literal as an operand of an expression: a statement has no SQL of it. */
|
|
626
|
+
[operandNode](): never;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates a field of a selection with `value` in every record, without selecting anything in SQL: the query returns the value itself, not a copy of it, whatever it is.
|
|
630
|
+
*
|
|
631
|
+
* It lets a branch of a selection skip a column or a nested query, such as `withHint ? field.hint : literal(null)`.
|
|
632
|
+
* To use a value in SQL, such as in a condition, pass it through `param` instead.
|
|
633
|
+
*/
|
|
634
|
+
declare function literal<T extends {} | null | undefined>(value: T): Literal<T>;
|
|
635
|
+
/** 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. */
|
|
636
|
+
type RelationRows<Kind extends RelationKind, Required extends boolean> = Kind extends "many" ? "many" : Required extends true ? "one" : "nullable";
|
|
637
|
+
/** Rows mode after a filter of a query whose row a required relation guarantees: `one` becomes `nullable`, or `optional` for a query of values; other modes stay. */
|
|
638
|
+
type FilteredRows<Rows extends ResultRows, Value extends boolean> = Rows extends "one" ? Value extends true ? "optional" : "nullable" : Rows;
|
|
639
|
+
/** Rows mode after `take`: `many` becomes `one`; the modes of one row stay. */
|
|
640
|
+
type OneRow<Rows extends ResultRows> = Rows extends "many" ? "one" : Rows;
|
|
641
|
+
/** Rows mode after `pluck`: `nullable` becomes `optional`; the other modes stay. */
|
|
642
|
+
type ValueRows<Rows extends ResultRows> = Rows extends "nullable" ? "optional" : Rows;
|
|
643
|
+
/** Rows mode after `get`: `many` becomes `one` and `nullable` becomes `optional`; `one` and `optional` stay. */
|
|
644
|
+
type OneValueRows<Rows extends ResultRows> = Rows extends "many" ? "one" : Rows extends "nullable" ? "optional" : Rows;
|
|
645
|
+
/**
|
|
646
|
+
* Result of a query of state `S`, executed or nested: an array of records or values, or one of them, `null` or `undefined` when a query of rows `nullable` or `optional` finds no row.
|
|
647
|
+
*
|
|
648
|
+
* It is the union of the results of every state that `S` allows, such as of a union of rows modes.
|
|
649
|
+
*/
|
|
650
|
+
type QueryResult<S extends QueryState> = S extends QueryState ? ResultByRows<S["result"], S["rows"]> : never;
|
|
651
|
+
/** Result of rows of `Result` returned in rows mode `Rows`; a union of modes gives the union of their results. */
|
|
652
|
+
type ResultByRows<Result, Rows extends ResultRows> = Rows extends "many" ? Result[] : Rows extends "one" ? Result : Rows extends "nullable" ? Result | null : Result | undefined;
|
|
653
|
+
/** Expressions, nested queries, and literals selected under the keys of the result fields; a record has no symbol keys. */
|
|
654
|
+
interface Selection {
|
|
655
|
+
readonly [key: string]: TypedExpression | NestedQuery | Literal<unknown>;
|
|
656
|
+
readonly [key: symbol]: never;
|
|
657
|
+
}
|
|
658
|
+
/** 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. */
|
|
659
|
+
type NestedQuery = QueryOf<SelectQueryState>;
|
|
660
|
+
/** Record of the values of the expressions, of the nested rows, and of the literals of a selection. */
|
|
661
|
+
type SelectionResult<S extends Selection> = { [K in keyof S]: FieldValue<S[K]>; };
|
|
662
|
+
/** Value of a selected field: of an expression, of the nested rows of a query as the result of executing it, or of a literal, for each member of a union of them. */
|
|
663
|
+
type FieldValue<V> = V extends NestedQuery ? QueryResult<V["types"]> : V extends Literal<infer T> ? T : ExpressionValue<V>;
|
|
664
|
+
/** Relations whose records the nested queries of a selection select. */
|
|
665
|
+
type SelectionUses<S extends Selection> = S[keyof S] extends (infer V) ? V extends NestedQuery ? V["types"]["uses"] : never : never;
|
|
666
|
+
/** Value of a selected expression. */
|
|
667
|
+
type ExpressionValue<E> = E extends AnyExpression<infer T> ? T : never;
|
|
668
|
+
/** Values that the type of an expression encodes, such as in place of its value. */
|
|
669
|
+
type ExpressionInput<E> = E extends AnyExpression<unknown, infer I> ? I : never;
|
|
670
|
+
declare const helperFields: unique symbol;
|
|
671
|
+
/** Marker of the input fields of a helper, carrying the keys selected by its callback. */
|
|
672
|
+
interface HelperFields<Keys extends PropertyKey = PropertyKey> {
|
|
673
|
+
readonly [helperFields]: Keys;
|
|
674
|
+
}
|
|
675
|
+
/** Records with `Fields` added or replaced, for each branch of either record type; `any` stays `any`. */
|
|
676
|
+
type MergeSelection<Previous, Fields> = Previous extends unknown ? Fields extends unknown ? MergeFields<RecordFields<Previous>, RecordFields<Fields>> & (IsAny<Previous> extends true ? Previous : unknown) : never : never;
|
|
677
|
+
/** Fields with numeric keys represented as the string keys used in result records. */
|
|
678
|
+
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;
|
|
679
|
+
/** Merge of normalized fields, retaining the previous value when an optional replacement is absent. */
|
|
680
|
+
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.
|
|
681
|
+
? Previous[K] | keyof Fields : K extends keyof Fields // A decoder can return undefined, so it cannot be excluded as merely an absent property.
|
|
682
|
+
? Previous[K] | Fields[K] : Previous[K]; } & { [K in keyof Fields as K extends keyof Previous ? ({} extends Pick<Fields, K> ? never : K) : K]: Fields[K]; }>;
|
|
683
|
+
/** State of a query of `$select` in types: one record `R`, whose nested queries select records of relations `U`. */
|
|
684
|
+
interface RecordQueryState$1<R = unknown, U extends UsedRelation = UsedRelation> extends QueryState {
|
|
685
|
+
readonly result: R;
|
|
686
|
+
readonly rows: "one";
|
|
687
|
+
readonly value: false;
|
|
688
|
+
readonly uses: U;
|
|
689
|
+
}
|
|
690
|
+
/** State of the query of `$select` of `Sel`: the record of the values of its expressions and of its literals and the results of its queries. */
|
|
691
|
+
type SelectionState<Sel extends Selection> = RecordQueryState$1<MergeSelection<EmptyRecord, SelectionResult<Sel>>, SelectionUses<Sel>>;
|
|
692
|
+
/**
|
|
693
|
+
* Immutable query of `$select` of state `S`, unbound or bound to a `Db`: one record whose fields are the values of expressions and of literals and the results of independent queries, selected in one statement.
|
|
694
|
+
*
|
|
695
|
+
* An unbound query is not thenable, so it can be returned from async functions; it is compiled with `toSQL` or executed by a `Db`.
|
|
696
|
+
* A bound query executes on its `Db` when awaited.
|
|
697
|
+
*/
|
|
698
|
+
declare class RecordQuery<out S extends RecordQueryState$1, out Kind extends SelectQueryKind = "unbound"> {
|
|
699
|
+
readonly node: RecordQueryNode;
|
|
700
|
+
readonly types: S;
|
|
701
|
+
/** `Db` that executes the query when it is awaited; `undefined` for an unbound query. */
|
|
702
|
+
readonly db: QueryDb<Kind>;
|
|
703
|
+
/** Executes a bound query on its `Db`; `undefined` for an unbound query, so that it is not thenable. */
|
|
704
|
+
readonly then: QueryThen<S, Kind>;
|
|
705
|
+
constructor(node: RecordQueryNode, db?: AnyDb);
|
|
706
|
+
/**
|
|
707
|
+
* Compiles the query into SQL text and parameters; `schemaName` qualifies its tables.
|
|
708
|
+
*
|
|
709
|
+
* A query bound to a `Db` compiles as the `Db` executes it, with the PostgreSQL schema of the `Db`, and rejects options.
|
|
710
|
+
*/
|
|
711
|
+
toSQL(...args: ToSQLArgs<Kind>): SqlStatement;
|
|
712
|
+
/** Rejects the query as an operand of an expression, which takes a query of one value of a table. */
|
|
713
|
+
[operandNode](): never;
|
|
714
|
+
}
|
|
715
|
+
/** Query of `$select` of any state and kind. */
|
|
716
|
+
type AnyRecordQuery = RecordQuery<any, SelectQueryKind>;
|
|
717
|
+
declare const schemaBrand: unique symbol;
|
|
718
|
+
/** Key of the relation definitions of a schema, which composition reads. */
|
|
719
|
+
declare const schemaRelations: unique symbol;
|
|
720
|
+
/** Tables by their keys; a key must not start with `$`, which is reserved for schema and `Db` members. */
|
|
721
|
+
type Tables = Record<string, AnyTable>;
|
|
722
|
+
/**
|
|
723
|
+
* Immutable collection of tables and their relations with query entry points.
|
|
724
|
+
*
|
|
725
|
+
* A schema is not bound to a database, so queries built from it can be defined at module level.
|
|
726
|
+
* A `Db` can execute such a query if its schema contains the tables and the selected relations of the query and every bound nested query belongs to that `Db`.
|
|
727
|
+
*/
|
|
728
|
+
type Schema<T extends Tables, R extends SchemaRelations = EmptyRecord> = SchemaEntries<T, R> & SchemaMembers<T, R>;
|
|
729
|
+
/** Query entry points; each access starts a query over a new table occurrence. */
|
|
730
|
+
type SchemaEntries<T extends Tables, R extends SchemaRelations> = { readonly [K in keyof T]: SelectQuery<InitialQueryState<T[K], TableContext<R, K>>>; };
|
|
731
|
+
/** Members of a schema that composition reads: its tables and the relations of its tables. */
|
|
732
|
+
interface SchemaContents<T extends Tables, R extends SchemaRelations> {
|
|
733
|
+
readonly [schemaBrand]: true;
|
|
734
|
+
/** Tables of the schema by their keys. */
|
|
735
|
+
readonly $tables: T;
|
|
736
|
+
/** Relation definitions by table key and relation name. */
|
|
737
|
+
readonly [schemaRelations]: R;
|
|
738
|
+
}
|
|
739
|
+
interface SchemaMembers<T extends Tables, R extends SchemaRelations> extends SchemaContents<T, R> {
|
|
740
|
+
/**
|
|
741
|
+
* Creates a schema of the same tables with the relations of `relations` added, declared with `many` and `one` by their names under the keys of their tables.
|
|
742
|
+
*
|
|
743
|
+
* A relation refers to a table of the schema by columns of SQL types that `=` compares; a relation that the schema already has is rejected.
|
|
744
|
+
*/
|
|
745
|
+
$relations<S extends AnySchema, D extends RelationDeclarations<S["$tables"]>>(this: S, relations: D & CheckDeclarations<S["$tables"], D>): Schema<S["$tables"], MergeRelations<S[typeof schemaRelations] & DeclaredRelations<S["$tables"], D>>>;
|
|
746
|
+
/**
|
|
747
|
+
* Starts an unbound query of one record whose fields are the values of the expressions and of the literals and the results of the queries of `selection`, selected in one statement.
|
|
748
|
+
*
|
|
749
|
+
* The value of the field of a query is the result it gives when executed, such as an array of records or one value.
|
|
750
|
+
*/
|
|
751
|
+
$select<Sel extends Selection>(selection: Sel): RecordQuery<SelectionState<Sel>>;
|
|
752
|
+
}
|
|
753
|
+
/** Schema of any tables and relations. */
|
|
754
|
+
type AnySchema = SchemaContents<Tables, SchemaRelations>;
|
|
755
|
+
/** Part of a schema definition: an object of tables by their keys, or a schema whose tables and relations it includes. */
|
|
756
|
+
type SchemaPart = Tables | AnySchema;
|
|
757
|
+
/**
|
|
758
|
+
* Tables of the parts of a schema definition by their keys.
|
|
759
|
+
*
|
|
760
|
+
* A part typed as a union gives a union of tables, and parts of an array of unknown length give no tables, since any of them may be missing.
|
|
761
|
+
*/
|
|
762
|
+
type SchemaTables<P extends readonly SchemaPart[]> = ComposeParts<P>["tables"] extends (infer T extends Tables) ? { [K in keyof T]: T[K]; } : never;
|
|
763
|
+
/** Relations of the parts of a schema definition by table key and relation name, read as `SchemaTables` reads the tables. */
|
|
764
|
+
type SchemaPartRelations<P extends readonly SchemaPart[]> = ComposeParts<P>["relations"] extends (infer R extends SchemaRelations) ? MergeRelations<R> : never;
|
|
765
|
+
/** Tables and relations of the parts of a schema definition, intersected. */
|
|
766
|
+
interface PartContents {
|
|
767
|
+
readonly tables: Tables;
|
|
768
|
+
readonly relations: SchemaRelations;
|
|
769
|
+
}
|
|
770
|
+
type ComposeParts<P extends readonly SchemaPart[], Composed extends PartContents = {
|
|
771
|
+
tables: EmptyRecord;
|
|
772
|
+
relations: EmptyRecord;
|
|
773
|
+
}> = P extends readonly [infer First extends SchemaPart, ...infer Rest extends readonly SchemaPart[]] ? ComposeParts<Rest, Composed & ReadPart<First>> : P extends readonly [...infer Rest extends readonly SchemaPart[], infer Last extends SchemaPart] ? ComposeParts<Rest, Composed & ReadPart<Last>> : Composed;
|
|
774
|
+
type ReadPart<P extends SchemaPart> = P extends SchemaContents<infer T, any> ? {
|
|
775
|
+
tables: T;
|
|
776
|
+
relations: P[typeof schemaRelations];
|
|
777
|
+
} : {
|
|
778
|
+
tables: P;
|
|
779
|
+
relations: EmptyRecord;
|
|
780
|
+
};
|
|
781
|
+
/**
|
|
782
|
+
* Defines a schema of the tables of `parts`, keyed by their names in queries.
|
|
783
|
+
*
|
|
784
|
+
* A part is an object of tables by their keys or another schema, whose tables and relations the new schema includes as they are, so queries built from that schema run on the new one.
|
|
785
|
+
* A key of two different tables, a table under two keys, and two different definitions of a relation of a table are rejected; the same table under the same key or the same relation in several parts is one.
|
|
786
|
+
*/
|
|
787
|
+
declare function defineSchema<P extends SchemaPart[]>(...parts: P): Schema<SchemaTables<P>, SchemaPartRelations<P>>;
|
|
788
|
+
declare const sourceTable: unique symbol;
|
|
789
|
+
declare const sourceKey: unique symbol;
|
|
790
|
+
/** Runtime mark of the declarations of `many` and `one`. */
|
|
791
|
+
declare const declarationBrand: unique symbol;
|
|
792
|
+
/** Kind of a relation: `many` related records, or `one` related record at most. */
|
|
793
|
+
type RelationKind = "many" | "one";
|
|
794
|
+
/** Relation of a table of a schema to the records of table `Target`, which has key `TargetKey` in the schema. */
|
|
795
|
+
interface Relation<Kind extends RelationKind = RelationKind, Target extends AnyTable = AnyTable, TargetKey extends string = string, Required extends boolean = boolean> {
|
|
796
|
+
readonly kind: Kind;
|
|
797
|
+
readonly target: Target;
|
|
798
|
+
readonly targetKey: TargetKey;
|
|
799
|
+
/** Whether every record of the table has its related record, so that a query of a relation `one` without a filter rejects without it rather than giving `null`; `false` for a relation `many`. */
|
|
800
|
+
readonly required: Required;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Relation of a table of a schema as `$relations` defines it: the columns of its keys, compared by SQL `=` in order.
|
|
804
|
+
*
|
|
805
|
+
* Composition includes a definition as it is, so a relation that several parts include is one definition.
|
|
806
|
+
*/
|
|
807
|
+
interface RelationDefinition extends Relation {
|
|
808
|
+
readonly name: string;
|
|
809
|
+
/** Key of the source table. */
|
|
810
|
+
readonly key: string;
|
|
811
|
+
readonly source: AnyTable;
|
|
812
|
+
readonly from: readonly string[];
|
|
813
|
+
readonly to: readonly string[];
|
|
814
|
+
}
|
|
815
|
+
/** Relation `N` of the table under key `K` of a schema, of type `R`, whose records a query selects. */
|
|
816
|
+
interface UsedRelation<K extends string = string, N extends string = string, R extends Relation = Relation> {
|
|
817
|
+
readonly key: K;
|
|
818
|
+
readonly name: N;
|
|
819
|
+
readonly relation: R;
|
|
820
|
+
}
|
|
821
|
+
/** Relations of schema relations `R` that the queries of a `Db` of the schema may select. */
|
|
822
|
+
type UsableRelation<R extends SchemaRelations> = { [K in keyof R & string]: { [N in keyof R[K] & string]: UsedRelation<K, N, R[K][N]>; }[keyof R[K] & string]; }[keyof R & string];
|
|
823
|
+
/** Relations of the tables of a schema by table key and relation name. */
|
|
824
|
+
type SchemaRelations = {
|
|
825
|
+
readonly [key: string]: TableRelations;
|
|
826
|
+
};
|
|
827
|
+
/** Relations of a table of a schema by relation name. */
|
|
828
|
+
type TableRelations = {
|
|
829
|
+
readonly [name: string]: Relation;
|
|
830
|
+
};
|
|
831
|
+
/**
|
|
832
|
+
* Declaration of a relation by `many` or `one`, which `$relations` of a schema defines for a table of type `Source` with key `From` of the source table.
|
|
833
|
+
*
|
|
834
|
+
* `Source` and `From` only type the keys of the source table.
|
|
835
|
+
*/
|
|
836
|
+
interface RelationDeclaration<Kind extends RelationKind, Source extends AnyTable, Target extends AnyTable, From = unknown, Required extends boolean = boolean> {
|
|
837
|
+
readonly [declarationBrand]: true;
|
|
838
|
+
readonly kind: Kind;
|
|
839
|
+
readonly target: Target;
|
|
840
|
+
readonly from: readonly string[];
|
|
841
|
+
readonly to: readonly string[];
|
|
842
|
+
readonly required: Required;
|
|
843
|
+
readonly [sourceTable]?: (source: Source) => void;
|
|
844
|
+
readonly [sourceKey]?: From;
|
|
845
|
+
}
|
|
846
|
+
/** Column key of table `T` whose type has SQL `=`, which a relation can compare. */
|
|
847
|
+
type EqualityKey<T extends AnyTable> = { [K in keyof T["columns"]]: HasEquality<ColumnOperators<T, K>> extends true ? K : never; }[keyof T["columns"]] & string;
|
|
848
|
+
/** Key of a relation in table `T`: a column key, or a non-empty list of them for a composite key. */
|
|
849
|
+
type RelationKey<T extends AnyTable> = EqualityKey<T> | readonly [EqualityKey<T>, ...EqualityKey<T>[]];
|
|
850
|
+
/** Key of table `T` with as many columns as key `From`. */
|
|
851
|
+
type MatchingKey<T extends AnyTable, From> = From extends string ? EqualityKey<T> : { readonly [I in keyof From]: EqualityKey<T>; };
|
|
852
|
+
/** Keys of a relation: the columns `from` of the source table equal the columns `to` of the target table, in order. */
|
|
853
|
+
interface RelationKeys<Target extends AnyTable, From> {
|
|
854
|
+
readonly from: From;
|
|
855
|
+
readonly to: MatchingKey<Target, From>;
|
|
856
|
+
}
|
|
857
|
+
/** Keys of a relation `one`, as in `RelationKeys`, and whether the relation is required. */
|
|
858
|
+
interface OneRelationKeys<From, To> {
|
|
859
|
+
readonly from: From;
|
|
860
|
+
readonly to: To;
|
|
861
|
+
/** Whether every record has its related record, such as by a foreign key on columns `from` that are not nullable, so that a query of the relation without a filter rejects without it rather than giving `null`. */
|
|
862
|
+
readonly required?: boolean;
|
|
863
|
+
}
|
|
864
|
+
/** Members of the keys `K` of a relation `one` with only `required` typed, so that a call infers `K` with `required` as optional as it is, and reports a wrong key at its own member. */
|
|
865
|
+
type RequiredMember<K> = { readonly [P in keyof K]: P extends "required" ? K[P] : unknown; };
|
|
866
|
+
/** Whether the keys `K` of a relation `one` make it required: only where they set `required` to `true`, and `boolean` where `required` may be `true` or missing, such as `required?: true`. */
|
|
867
|
+
type DeclaredRequiredOf<K> = K extends unknown ? "required" extends keyof K ? K extends {
|
|
868
|
+
readonly required: infer Required;
|
|
869
|
+
} ? IsTrue<Required> : IsTrue<K["required" & keyof K] | undefined> : false : never;
|
|
870
|
+
/** `true` for `true`, and `false` for other values, such as `false` and `undefined`; a union gives the union of their results. */
|
|
871
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
872
|
+
/** Declarations of `$relations` of a schema of tables `T`: relations by name, for tables by their keys. */
|
|
873
|
+
type RelationDeclarations<T extends Tables> = { readonly [K in keyof T]?: {
|
|
874
|
+
readonly [name: string]: RelationDeclaration<RelationKind, T[K], T[keyof T]>;
|
|
875
|
+
}; };
|
|
876
|
+
/**
|
|
877
|
+
* Declarations `D` of `$relations` checked by the names they use: relations of the tables of `T` under their keys, and no other keys.
|
|
878
|
+
*
|
|
879
|
+
* Declarations under the names of `D` get their source table from this type even where the index signature of `RelationDeclarations` gives way to a member of `Object`, such as for a relation named `toString`.
|
|
880
|
+
* A relation name must not be a column key of its table or start with `$`, since the references that the callback of `select` gets have both.
|
|
881
|
+
*/
|
|
882
|
+
type CheckDeclarations<T extends Tables, D> = { readonly [K in keyof D]: [TableKey<T, K>] extends [never] ? never : undefined extends D[K] ? D[K] : { readonly [N in keyof D[K]]: `${N & (string | number)}` extends ReservedName<T[TableKey<T, K>]> ? never : RelationDeclaration<RelationKind, T[TableKey<T, K>], T[keyof T], RelationKey<T[TableKey<T, K>]>>; }; };
|
|
883
|
+
/** Names that a relation of table `T` cannot have: the keys of its columns, and names starting with `$`. */
|
|
884
|
+
type ReservedName<T extends AnyTable> = `${keyof T["columns"] & (string | number)}` | `$${string}`;
|
|
885
|
+
/** Key of tables `T` written as key `K`, such as `1` for `"1"`, as object keys are strings at runtime. */
|
|
886
|
+
type TableKey<T extends Tables, K> = { [P in keyof T]: `${P & (string | number)}` extends `${K & (string | number)}` ? P : never; }[keyof T];
|
|
887
|
+
/** Relations that declarations `D` of a schema of tables `T` define, by table key and relation name, as strings like the keys of objects. */
|
|
888
|
+
type DeclaredRelations<T extends Tables, D> = { [K in keyof D as K extends number ? `${K}` : K]: { [N in keyof D[K] as N extends number ? `${N}` : N]: D[K][N] extends RelationDeclaration<infer Kind, never, infer Target, unknown, infer Required> ? Relation<Kind, Target, KeyOfTable<T, Target>, Required> : never; }; };
|
|
889
|
+
/** Column key of relation key `K`: the key itself, or a column of a composite key. */
|
|
890
|
+
type RelationColumn<K> = K extends readonly unknown[] ? K[number] : K;
|
|
891
|
+
/** Check of key `To` of a relation `one` that rejects it when its columns include no key of table `Target`, as far as the types tell. */
|
|
892
|
+
type TargetKeyCheck<Target extends AnyTable, To> = [ContainsKey<Target, RelationColumn<To>>] extends [false] ? {
|
|
893
|
+
readonly to: MissingKey<KeyOf<Target["keys"]>>;
|
|
894
|
+
} : unknown;
|
|
895
|
+
/** Type that a key `to` of a relation `one` without a key of its target is checked against, naming the keys of the target. */
|
|
896
|
+
interface MissingKey<Keys> {
|
|
897
|
+
readonly "columns to must include a key of the target": Keys;
|
|
523
898
|
}
|
|
524
|
-
/**
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
899
|
+
/** Key of table `Target` among tables `T`, as a string like the keys of objects. */
|
|
900
|
+
type KeyOfTable<T extends Tables, Target> = { [K in keyof T]: [T[K]] extends [Target] ? [Target] extends [T[K]] ? K extends number ? `${K}` : K & string : never : never; }[keyof T];
|
|
901
|
+
/** Relations of `R` by table key, with the relations under the same key merged. */
|
|
902
|
+
type MergeRelations<R> = { [K in keyof R]: { [N in keyof R[K]]: R[K][N]; }; };
|
|
903
|
+
/** Relations of the schema that a query starts from, by table key, and the key of the table of the query there. */
|
|
904
|
+
interface SchemaContext<R extends SchemaRelations = SchemaRelations, K extends string = string> {
|
|
905
|
+
readonly relations: R;
|
|
906
|
+
readonly key: K;
|
|
528
907
|
}
|
|
908
|
+
/** Schema context of a query whose table has no relations, such as one of `from(table)`. */
|
|
909
|
+
type NoRelations = SchemaContext<EmptyRecord, string>;
|
|
910
|
+
/** Schema context of the queries of the table under key `K` of a schema of relations `R`, whose keys are strings, as object keys are at runtime. */
|
|
911
|
+
type TableContext<R extends SchemaRelations, K> = K extends keyof R ? [keyof R[K]] extends [never] ? NoRelations : SchemaContext<R, K & string> : K extends number ? TableContext<R, `${K}`> : NoRelations;
|
|
529
912
|
/**
|
|
530
|
-
*
|
|
913
|
+
* Declares a relation of a table to the records of `target` whose columns `to` equal its columns `from`, for `$relations` of a schema.
|
|
531
914
|
*
|
|
532
|
-
*
|
|
915
|
+
* A composite key lists its columns in arrays of the same length.
|
|
533
916
|
*/
|
|
534
|
-
|
|
535
|
-
readonly table: AnyTable;
|
|
536
|
-
readonly schema: SchemaContext;
|
|
537
|
-
/** Type of the value of a query of values, a `QueryValueType`; `never` for a query of records. */
|
|
538
|
-
readonly valueType: unknown;
|
|
539
|
-
/**
|
|
540
|
-
* Whether a required relation guarantees the row of the query, such as of `field.form`.
|
|
541
|
-
*
|
|
542
|
-
* The relation does not guarantee a record that also passes a filter, so `where`, `find`, and `findBy` end the guarantee and make rows `one` `nullable`, or `optional` for a query of values; `optional`, `nullable`, and `required` end it as well.
|
|
543
|
-
* The callback of a helper starts with it, so that the effect of the helper records whether the callback filters.
|
|
544
|
-
*/
|
|
545
|
-
readonly guaranteed: boolean;
|
|
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. */
|
|
547
|
-
readonly aggregate: boolean;
|
|
548
|
-
}
|
|
549
|
-
/** State of a query over table `T` with schema context `C`, whatever its result. */
|
|
550
|
-
interface QueryStateOf<T extends AnyTable, C extends SchemaContext = SchemaContext> extends SelectQueryState {
|
|
551
|
-
readonly table: T;
|
|
552
|
-
readonly schema: C;
|
|
553
|
-
}
|
|
917
|
+
declare function many<Source extends AnyTable, Target extends AnyTable, const From extends RelationKey<Source>>(target: Target, keys: RelationKeys<Target, From>): RelationDeclaration<"many", Source, Target, From, false>;
|
|
554
918
|
/**
|
|
555
|
-
*
|
|
919
|
+
* Declares a relation of a table to the record of `target` whose columns `to` equal its columns `from`, for `$relations` of a schema.
|
|
556
920
|
*
|
|
557
|
-
*
|
|
921
|
+
* A composite key lists its columns in arrays of the same length.
|
|
922
|
+
* The columns `to` must include a key of `target`, primary or unique, so that they match at most one record.
|
|
923
|
+
* Without the record, a query of the relation gives `null`, and a query of a relation declared with `required: true` rejects unless it filters the record.
|
|
924
|
+
* Set `required: true` only where the database guarantees the record, such as by a foreign key on columns `from` that are not nullable.
|
|
558
925
|
*/
|
|
559
|
-
|
|
560
|
-
readonly result: EmptyRecord;
|
|
561
|
-
readonly valueType: never;
|
|
562
|
-
readonly rows: Rows;
|
|
563
|
-
readonly value: false;
|
|
564
|
-
readonly uses: U;
|
|
565
|
-
readonly guaranteed: Guaranteed;
|
|
566
|
-
readonly aggregate: false;
|
|
567
|
-
}
|
|
926
|
+
declare function one<Source extends AnyTable, Target extends AnyTable, const From extends RelationKey<Source>, const To extends MatchingKey<Target, From>, const Keys extends object = EmptyRecord>(target: Target, keys: OneRelationKeys<From, To> & RequiredMember<Keys> & TargetKeyCheck<Target, To>): RelationDeclaration<"one", Source, Target, From, NoInfer<DeclaredRequiredOf<Keys>>>;
|
|
568
927
|
/** Type of a count: a `bigint` of PostgreSQL decoded as a number, rejecting a count that a number cannot hold exactly. */
|
|
569
928
|
declare const countType: BaseType<number, number, MergeOperators<NoOperators, {
|
|
929
|
+
eq: EqualityOperator<ComparisonSignature>;
|
|
930
|
+
ne: EqualityOperator<ComparisonSignature>;
|
|
931
|
+
in: EqualityOperator<InSignature>;
|
|
570
932
|
lt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
571
933
|
lte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
572
934
|
gt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
573
935
|
gte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
574
|
-
eq: EqualityOperator<ComparisonSignature>;
|
|
575
|
-
ne: EqualityOperator<ComparisonSignature>;
|
|
576
|
-
in: EqualityOperator<InSignature>;
|
|
577
936
|
}>, undefined>;
|
|
578
937
|
/** Type of the value of a query of a count. */
|
|
579
938
|
interface CountValueType extends QueryValueType {
|
|
580
939
|
readonly input: TypeInput<typeof countType>;
|
|
581
940
|
readonly operators: TypeOperators<typeof countType>;
|
|
582
941
|
}
|
|
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. */
|
|
584
|
-
type RelationRows<Kind extends RelationKind, Required extends boolean> = Kind extends "many" ? "many" : Required extends true ? "one" : "nullable";
|
|
585
|
-
/** Rows mode after a filter of a query whose row a required relation guarantees: `one` becomes `nullable`, or `optional` for a query of values; other modes stay. */
|
|
586
|
-
type FilteredRows<Rows extends ResultRows, Value extends boolean> = Rows extends "one" ? Value extends true ? "optional" : "nullable" : Rows;
|
|
587
|
-
/** Rows mode after `take`: `many` becomes `one`; the modes of one row stay. */
|
|
588
|
-
type OneRow<Rows extends ResultRows> = Rows extends "many" ? "one" : Rows;
|
|
589
|
-
/** Rows mode after `pluck`: `nullable` becomes `optional`; the other modes stay. */
|
|
590
|
-
type ValueRows<Rows extends ResultRows> = Rows extends "nullable" ? "optional" : Rows;
|
|
591
|
-
/** Rows mode after `get`: `many` becomes `one` and `nullable` becomes `optional`; `one` and `optional` stay. */
|
|
592
|
-
type OneValueRows<Rows extends ResultRows> = Rows extends "many" ? "one" : Rows extends "nullable" ? "optional" : Rows;
|
|
593
|
-
/**
|
|
594
|
-
* Result of a query of state `S`, executed or nested: an array of records or values, or one of them, `null` or `undefined` when a query of rows `nullable` or `optional` finds no row.
|
|
595
|
-
*
|
|
596
|
-
* It is the union of the results of every state that `S` allows, such as of a union of rows modes.
|
|
597
|
-
*/
|
|
598
|
-
type QueryResult<S extends QueryState> = S extends QueryState ? ResultByRows<S["result"], S["rows"]> : never;
|
|
599
|
-
/** Result of rows of `Result` returned in rows mode `Rows`; a union of modes gives the union of their results. */
|
|
600
|
-
type ResultByRows<Result, Rows extends ResultRows> = Rows extends "many" ? Result[] : Rows extends "one" ? Result : Rows extends "nullable" ? Result | null : Result | undefined;
|
|
601
942
|
/** References to the columns of the query source, passed to query callbacks. */
|
|
602
943
|
type ColumnRefs<T extends AnyTable> = { readonly [K in keyof T["columns"]]: Expression<Selectable<T>[K], ColumnOperators<T, K>, ColumnValues<T>[K]>; };
|
|
603
944
|
/**
|
|
604
|
-
* Queries of the records of the relations of the table of schema context `C`, by relation name, which the callbacks of
|
|
945
|
+
* Queries of the records of the relations of the table of schema context `C`, by relation name, which the callbacks of queries receive beside the columns.
|
|
605
946
|
*
|
|
606
947
|
* A relation name is never a column key of its table.
|
|
607
948
|
* A context whose table key is not known, such as one of a query of any schema, has no relations.
|
|
@@ -612,7 +953,7 @@ type RelationQueries<R extends SchemaContext["relations"], K extends keyof R & s
|
|
|
612
953
|
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"]>>;
|
|
613
954
|
/** Runtime context of the queries of a table in the schema they start from. */
|
|
614
955
|
interface QueryContext {
|
|
615
|
-
/** Getters of the queries of the relations of the table, which the references of the callbacks of
|
|
956
|
+
/** Getters of the queries of the relations of the table, which the references of the callbacks of queries have as their own properties and which read the key columns from them. */
|
|
616
957
|
readonly relations: PropertyDescriptorMap;
|
|
617
958
|
}
|
|
618
959
|
/** Type of the value of a query of `exists`. */
|
|
@@ -668,20 +1009,12 @@ type WhereCallback<T extends AnyTable, C extends SchemaContext = NoRelations> =
|
|
|
668
1009
|
/** 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
1010
|
type WhereFilter<T extends AnyTable, C extends SchemaContext = NoRelations> = WhereCondition<T> | WhereCallback<T, C>;
|
|
670
1011
|
/**
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
* The condition can be combined further with `and`, `or`, and `not`.
|
|
674
|
-
*/
|
|
675
|
-
declare function defineFilter<T extends AnyTable, C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, filter: NoInfer<WhereCondition<T>>): WhereCondition<T>;
|
|
676
|
-
/**
|
|
677
|
-
* Defines a reusable callback of `where` for queries over a table, checking its objects of column values against the columns.
|
|
1012
|
+
* Argument of `where` of a query of state `S`: a `WhereFilter` of its table and schema, which TypeScript resolves with what it has inferred for `S` before it checks a callback in it.
|
|
678
1013
|
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
1014
|
+
* TypeScript types the body of a callback once, for every overload, and a plain `WhereFilter` leaves `S` unresolved there, so the body would widen a literal, such as of an enum column, to `string`.
|
|
1015
|
+
* It reads the filter only in its branch: a general alias that takes the filter as an argument resolves it on every call, which takes about 25 more instantiations.
|
|
681
1016
|
*/
|
|
682
|
-
|
|
683
|
-
/** Defines a reusable filter of `where` for queries over a table, either a condition or a callback. */
|
|
684
|
-
declare function defineFilter<T extends AnyTable, C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, filter: NoInfer<WhereFilter<T, C>>): WhereFilter<T, C>;
|
|
1017
|
+
type QueryWhereFilter<S extends SelectQueryState> = [S] extends [unknown] ? WhereFilter<S["table"], S["schema"]> : never;
|
|
685
1018
|
/**
|
|
686
1019
|
* 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.
|
|
687
1020
|
*
|
|
@@ -718,7 +1051,7 @@ type OrderTerm = AnyExpression | ScalarQuery | Ordering;
|
|
|
718
1051
|
/**
|
|
719
1052
|
* References of the callback of `orderBy` to the fields of records `R` selected by a query: their expressions by key.
|
|
720
1053
|
*
|
|
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.
|
|
1054
|
+
* A field of nested rows or of a literal is among them in types, but reading it throws; a field of an aggregate or of `exists` sorts by its value.
|
|
722
1055
|
*/
|
|
723
1056
|
type SelectedRefs<R> = { readonly [K in keyof R & string]: AnyExpression<R[K]>; };
|
|
724
1057
|
/** Sort keys returned by the callback of `orderBy`: one or an array of them. */
|
|
@@ -729,46 +1062,20 @@ declare function asc(value: AnyExpression | ScalarQuery): Ordering;
|
|
|
729
1062
|
declare function desc(value: AnyExpression | ScalarQuery): Ordering;
|
|
730
1063
|
/** Sorts by `value`, an expression or a query of one value, in `direction`, such as `"desc nulls last"`, in the callback of `orderBy`. */
|
|
731
1064
|
declare function orderBy(value: AnyExpression | ScalarQuery, direction: OrderDirection): Ordering;
|
|
732
|
-
/**
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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]; }>;
|
|
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. */
|
|
763
|
-
type ColumnValue<T extends AnyTable, K extends keyof T["columns"]> = ColumnValues<T>[K] | AnyExpression<Selectable<T>[K]>;
|
|
1065
|
+
/**
|
|
1066
|
+
* 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, an expression of its values, or a query of one such value.
|
|
1067
|
+
*
|
|
1068
|
+
* A query may be `NULL` without its row, which PostgreSQL rejects for a column that is not nullable.
|
|
1069
|
+
*/
|
|
1070
|
+
type ColumnValue<T extends AnyTable, K extends keyof T["columns"]> = ColumnValues<T>[K] | AnyExpression<Selectable<T>[K]> | ScalarQuery<Selectable<T>[K] | null>;
|
|
764
1071
|
/** 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. */
|
|
765
1072
|
type OptionalColumnKey<T extends AnyTable> = { [K in keyof T["columns"]]: T["columns"][K]["attributes"]["hasDefault"] extends true ? K : null extends ColumnValues<T>[K] ? K : never; }[keyof T["columns"]];
|
|
766
1073
|
/** Record of an insert into table `T`: the values of its columns, which may omit a column with a default or a nullable column, or give it as `undefined`. */
|
|
767
1074
|
type InsertValues<T extends AnyTable> = { readonly [K in keyof T["columns"] as K extends OptionalColumnKey<T> ? never : K]: ColumnValue<T, K>; } & { readonly [K in OptionalColumnKey<T>]?: ColumnValue<T, K> | undefined; };
|
|
768
1075
|
/** Values of the columns of table `T` that an update sets; a column omitted or given as `undefined` keeps its value. */
|
|
769
1076
|
type UpdateValues<T extends AnyTable> = { readonly [K in keyof T["columns"]]?: ColumnValue<T, K> | undefined; };
|
|
770
|
-
/** Argument of `update`: the values that it sets, or a callback that receives the columns of the changed rows and returns them. */
|
|
771
|
-
type UpdateSet<T extends AnyTable> = UpdateValues<T> | ((columns: ColumnRefs<T>) => UpdateValues<T>);
|
|
1077
|
+
/** Argument of `update` of table `T` with schema context `C`: the values that it sets, or a callback that receives the columns and the queries of the relations of the changed rows and returns them. */
|
|
1078
|
+
type UpdateSet<T extends AnyTable, C extends SchemaContext = NoRelations> = UpdateValues<T> | ((columns: ColumnRefs<T> & RelationRefs<C>) => UpdateValues<T>);
|
|
772
1079
|
/** State `S` with the parts of `Changes` replaced. */
|
|
773
1080
|
type ChangeState<S extends SelectQueryState, Changes extends Partial<SelectQueryState>> = { readonly [K in keyof SelectQueryState]: K extends keyof Changes ? Changes[K] : S[K]; } & {};
|
|
774
1081
|
/** Rows mode of a query of state `S` after a filter: `FilteredRows` of a query whose row is guaranteed, and the rows of other queries. */
|
|
@@ -801,6 +1108,8 @@ interface ScalarQuery<T = unknown> {
|
|
|
801
1108
|
}
|
|
802
1109
|
/** Value of query `Q` of one value in an expression. */
|
|
803
1110
|
type ScalarQueryValue<Q extends ScalarQuery> = Q[typeof scalarValue];
|
|
1111
|
+
/** Relations whose records `E`, an expression or a query of one value that a callback returns, selects: those of a query, as an expression does not carry the relations of its queries. */
|
|
1112
|
+
type OperandUses<E> = E extends ScalarQuery ? E["types"]["uses"] : never;
|
|
804
1113
|
/** State of a query of one value, which an expression takes. */
|
|
805
1114
|
interface ScalarQueryState extends SelectQueryState {
|
|
806
1115
|
readonly rows: "one" | "optional";
|
|
@@ -810,6 +1119,10 @@ interface ScalarQueryState extends SelectQueryState {
|
|
|
810
1119
|
interface ExpressionQueryState extends ScalarQueryState {
|
|
811
1120
|
readonly valueType: QueryValueType;
|
|
812
1121
|
}
|
|
1122
|
+
/** Query of one value of a table with the type of its value, such as of `get` or of an aggregate, which gives the expression of a function the decoding and the operators of its value. */
|
|
1123
|
+
interface TypedScalarQuery extends ScalarQuery {
|
|
1124
|
+
readonly types: ExpressionQueryState;
|
|
1125
|
+
}
|
|
813
1126
|
/** 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
1127
|
interface ValuesQuery<T = unknown> {
|
|
815
1128
|
readonly types: ValuesQueryState<T>;
|
|
@@ -823,7 +1136,7 @@ interface ValuesQueryState<T> extends SelectQueryState {
|
|
|
823
1136
|
readonly value: true;
|
|
824
1137
|
}
|
|
825
1138
|
/** State of a query whose rows are records, which `select` and `clearSelect` change. */
|
|
826
|
-
type RecordQueryState
|
|
1139
|
+
type RecordQueryState = SelectQueryState & {
|
|
827
1140
|
readonly value: false;
|
|
828
1141
|
};
|
|
829
1142
|
/** State of a query whose row no relation guarantees, which a filter keeps. */
|
|
@@ -849,10 +1162,10 @@ type ColumnValueType<T extends AnyTable, K extends keyof T["columns"]> = {
|
|
|
849
1162
|
readonly input: ColumnValues<T>[K];
|
|
850
1163
|
readonly operators: ColumnOperators<T, K>;
|
|
851
1164
|
};
|
|
852
|
-
/** Type of the value of a query of
|
|
853
|
-
type
|
|
854
|
-
readonly input:
|
|
855
|
-
readonly operators:
|
|
1165
|
+
/** Type of the value of a query of `E`, an expression or a query of one value that a callback returns. */
|
|
1166
|
+
type OperandValueType<E extends TypedOperand> = {
|
|
1167
|
+
readonly input: TypedOperandInput<E>;
|
|
1168
|
+
readonly operators: TypedOperandOperators<E>;
|
|
856
1169
|
};
|
|
857
1170
|
/** 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
1171
|
type AggregateState<S extends SelectQueryState, V, Type extends QueryValueType> = ChangeState<S, {
|
|
@@ -863,12 +1176,22 @@ type AggregateState<S extends SelectQueryState, V, Type extends QueryValueType>
|
|
|
863
1176
|
guaranteed: false;
|
|
864
1177
|
aggregate: true;
|
|
865
1178
|
}>;
|
|
1179
|
+
/** State of a query of the value `V` of type `Type` of an aggregate over the rows of a query of state `S`, whose argument is `E`, an expression or a query of one value that a callback returns. */
|
|
1180
|
+
type OperandAggregateState<S extends SelectQueryState, V, Type extends QueryValueType, E> = ChangeState<S, {
|
|
1181
|
+
result: V;
|
|
1182
|
+
valueType: Type;
|
|
1183
|
+
rows: "one";
|
|
1184
|
+
value: true;
|
|
1185
|
+
guaranteed: false;
|
|
1186
|
+
aggregate: true;
|
|
1187
|
+
uses: S["uses"] | OperandUses<E>;
|
|
1188
|
+
}>;
|
|
866
1189
|
/** State of a query of the number of rows or of values among the rows of a query of state `S`. */
|
|
867
1190
|
type CountState<S extends SelectQueryState> = AggregateState<S, number, CountValueType>;
|
|
868
1191
|
/** 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
1192
|
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
|
|
871
|
-
type
|
|
1193
|
+
/** State of a query of an aggregate of the values of `E`, an expression or a query of one value that a callback returns, over the rows of a query of state `S`, `NULL` without values other than `NULL`. */
|
|
1194
|
+
type OperandValueAggregateState<S extends SelectQueryState, E extends TypedOperand> = OperandAggregateState<S, OperandValue<E> | null, OperandValueType<E>, E>;
|
|
872
1195
|
/** Value `V` of a query of values whose `NULL` `coalesce` replaces with fallback `F`. */
|
|
873
1196
|
type CoalescedValue<V, F> = Exclude<V, null> | Extract<OperandValue<F>, null>;
|
|
874
1197
|
/** State of a query of many rows, which `limit` and `offset` apply to. */
|
|
@@ -893,7 +1216,7 @@ type OneRecordQueryState = OneRowQueryState & {
|
|
|
893
1216
|
declare class SelectQuery<out S extends SelectQueryState, out Kind extends SelectQueryKind = "unbound"> {
|
|
894
1217
|
readonly table: S["table"];
|
|
895
1218
|
readonly node: QueryNode;
|
|
896
|
-
/** Relations of the table in the schema the query starts from, which
|
|
1219
|
+
/** Relations of the table in the schema the query starts from, which its callbacks receive. */
|
|
897
1220
|
readonly context: QueryContext;
|
|
898
1221
|
readonly types: S;
|
|
899
1222
|
/** Value of the query in an expression, for types only. */
|
|
@@ -903,22 +1226,22 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
903
1226
|
/** Executes a bound query on its `Db`; `undefined` for an unbound query, so that it is not thenable. */
|
|
904
1227
|
readonly then: QueryThen<S, Kind>;
|
|
905
1228
|
constructor(table: S["table"], node: QueryNode,
|
|
906
|
-
/** Relations of the table in the schema the query starts from, which
|
|
1229
|
+
/** Relations of the table in the schema the query starts from, which its callbacks receive. */
|
|
907
1230
|
context: QueryContext, db?: AnyDb);
|
|
908
1231
|
/** 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:
|
|
1232
|
+
where<Q extends QueryOf<UnguaranteedQueryState>>(this: Q, filter: QueryWhereFilter<Q["types"]>): Q;
|
|
910
1233
|
/**
|
|
911
1234
|
* Adds a filter combined with `AND` with the previous ones; a callback receives the columns and the queries of the relations of the table.
|
|
912
1235
|
*
|
|
913
1236
|
* 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`.
|
|
914
1237
|
*/
|
|
915
|
-
where<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, filter:
|
|
1238
|
+
where<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, filter: QueryWhereFilter<S>): SelectQuery<FilteredState<S>, Kind>;
|
|
916
1239
|
/** Selects all columns of the table, replacing fields under their keys. */
|
|
917
|
-
select<S extends RecordQueryState
|
|
1240
|
+
select<S extends RecordQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, all: "*"): SelectQuery<ChangeState<S, {
|
|
918
1241
|
result: MergeSelection<S["result"], Selectable<S["table"]>>;
|
|
919
1242
|
}>, Kind>;
|
|
920
1243
|
/** Selects the listed columns, replacing fields under their keys. */
|
|
921
|
-
select<S extends RecordQueryState
|
|
1244
|
+
select<S extends RecordQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, ...keys: K[]): SelectQuery<ChangeState<S, {
|
|
922
1245
|
result: MergeSelection<S["result"], Pick<Selectable<S["table"]>, K>>;
|
|
923
1246
|
}>, Kind>;
|
|
924
1247
|
/**
|
|
@@ -928,12 +1251,12 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
928
1251
|
* Each expression is decoded with its type, so it must have one: a column, an operator result, or a fragment of `sql(type)`, but not of `sql<T>`.
|
|
929
1252
|
* A nested query is unbound, such as a query of a relation, or bound to the `Db` that runs the query; its rows become the value of its field as they become the result of an executed query.
|
|
930
1253
|
*/
|
|
931
|
-
select<S extends RecordQueryState
|
|
1254
|
+
select<S extends RecordQueryState, Kind extends SelectQueryKind, Sel extends Selection>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => Sel): SelectQuery<ChangeState<S, {
|
|
932
1255
|
result: MergeSelection<S["result"], SelectionResult<Sel>>;
|
|
933
1256
|
uses: S["uses"] | SelectionUses<Sel>;
|
|
934
1257
|
}>, Kind>;
|
|
935
1258
|
/** Removes all selected fields and keeps the other clauses. */
|
|
936
|
-
clearSelect<S extends RecordQueryState
|
|
1259
|
+
clearSelect<S extends RecordQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>): SelectQuery<ChangeState<S, {
|
|
937
1260
|
result: EmptyRecord;
|
|
938
1261
|
}>, Kind>;
|
|
939
1262
|
/**
|
|
@@ -975,15 +1298,18 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
975
1298
|
/**
|
|
976
1299
|
* Replaces the selected fields with the expression returned by `callback`, limits the query to one row, and returns the value of the expression instead of a record.
|
|
977
1300
|
*
|
|
1301
|
+
* `callback` receives the columns and the queries of the relations of the table.
|
|
1302
|
+
* It may return a query of one value, such as of an aggregate of related records, which gives `NULL` without its row.
|
|
978
1303
|
* Without a row, it rejects with `NotFoundError`, or with `RequiredRelationError` when a required relation still guarantees the row, such as of `field.form`.
|
|
979
1304
|
* An optional or nullable query resolves to `undefined` without a row instead.
|
|
980
1305
|
* A `NULL` value is `null`.
|
|
981
1306
|
*/
|
|
982
|
-
get<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends
|
|
983
|
-
result:
|
|
984
|
-
valueType:
|
|
1307
|
+
get<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<ChangeState<S, {
|
|
1308
|
+
result: OperandValue<E>;
|
|
1309
|
+
valueType: OperandValueType<E>;
|
|
985
1310
|
rows: OneValueRows<S["rows"]>;
|
|
986
1311
|
value: true;
|
|
1312
|
+
uses: S["uses"] | OperandUses<E>;
|
|
987
1313
|
}>, Kind>;
|
|
988
1314
|
/**
|
|
989
1315
|
* Replaces the selected fields with a column and returns the value of the column of each row instead of a record.
|
|
@@ -999,13 +1325,16 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
999
1325
|
/**
|
|
1000
1326
|
* Replaces the selected fields with the expression returned by `callback` and returns the value of the expression for each row instead of a record.
|
|
1001
1327
|
*
|
|
1328
|
+
* `callback` receives the columns and the queries of the relations of the table.
|
|
1329
|
+
* It may return a query of one value, such as of an aggregate of related records, which gives `NULL` without its row.
|
|
1002
1330
|
* It keeps whether the query returns an array or one value, such as after `take`, and how it handles a missing row, except that a nullable query resolves to `undefined` without a row.
|
|
1003
1331
|
*/
|
|
1004
|
-
pluck<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends
|
|
1005
|
-
result:
|
|
1006
|
-
valueType:
|
|
1332
|
+
pluck<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<ChangeState<S, {
|
|
1333
|
+
result: OperandValue<E>;
|
|
1334
|
+
valueType: OperandValueType<E>;
|
|
1007
1335
|
rows: ValueRows<S["rows"]>;
|
|
1008
1336
|
value: true;
|
|
1337
|
+
uses: S["uses"] | OperandUses<E>;
|
|
1009
1338
|
}>, Kind>;
|
|
1010
1339
|
/**
|
|
1011
1340
|
* Replaces the selected fields with the number of rows of the query and returns the number instead of the rows.
|
|
@@ -1015,40 +1344,76 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
1015
1344
|
count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>): SelectQuery<CountState<S>, Kind>;
|
|
1016
1345
|
/** 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. */
|
|
1017
1346
|
count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<CountState<S>, Kind>;
|
|
1018
|
-
/**
|
|
1019
|
-
|
|
1347
|
+
/**
|
|
1348
|
+
* 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.
|
|
1349
|
+
*
|
|
1350
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1351
|
+
*/
|
|
1352
|
+
count<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandAggregateState<S, number, CountValueType, E>, Kind>;
|
|
1020
1353
|
/** 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. */
|
|
1021
1354
|
countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: SelectQuery<S, Kind>, key: K): SelectQuery<CountState<S>, Kind>;
|
|
1022
|
-
/**
|
|
1023
|
-
|
|
1355
|
+
/**
|
|
1356
|
+
* 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.
|
|
1357
|
+
*
|
|
1358
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1359
|
+
*/
|
|
1360
|
+
countDistinct<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandAggregateState<S, number, CountValueType, E>, Kind>;
|
|
1024
1361
|
/** 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`. */
|
|
1025
1362
|
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>;
|
|
1026
|
-
/**
|
|
1027
|
-
|
|
1363
|
+
/**
|
|
1364
|
+
* 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`.
|
|
1365
|
+
*
|
|
1366
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1367
|
+
*/
|
|
1368
|
+
min<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1028
1369
|
/** 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`. */
|
|
1029
1370
|
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>;
|
|
1030
|
-
/**
|
|
1031
|
-
|
|
1371
|
+
/**
|
|
1372
|
+
* 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`.
|
|
1373
|
+
*
|
|
1374
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1375
|
+
*/
|
|
1376
|
+
max<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1032
1377
|
/** 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`. */
|
|
1033
1378
|
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>;
|
|
1034
|
-
/**
|
|
1035
|
-
|
|
1379
|
+
/**
|
|
1380
|
+
* 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`.
|
|
1381
|
+
*
|
|
1382
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1383
|
+
*/
|
|
1384
|
+
sum<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1036
1385
|
/** 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. */
|
|
1037
1386
|
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>;
|
|
1038
|
-
/**
|
|
1039
|
-
|
|
1387
|
+
/**
|
|
1388
|
+
* 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.
|
|
1389
|
+
*
|
|
1390
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1391
|
+
*/
|
|
1392
|
+
avg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1040
1393
|
/** 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. */
|
|
1041
1394
|
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>;
|
|
1042
|
-
/**
|
|
1043
|
-
|
|
1395
|
+
/**
|
|
1396
|
+
* 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.
|
|
1397
|
+
*
|
|
1398
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1399
|
+
*/
|
|
1400
|
+
every<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1044
1401
|
/** 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`. */
|
|
1045
1402
|
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>;
|
|
1046
|
-
/**
|
|
1047
|
-
|
|
1403
|
+
/**
|
|
1404
|
+
* 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`.
|
|
1405
|
+
*
|
|
1406
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1407
|
+
*/
|
|
1408
|
+
some<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1048
1409
|
/** 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. */
|
|
1049
1410
|
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>;
|
|
1050
|
-
/**
|
|
1051
|
-
|
|
1411
|
+
/**
|
|
1412
|
+
* 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.
|
|
1413
|
+
*
|
|
1414
|
+
* `callback` receives the columns and the queries of the relations of the table and returns an expression or a query of one value.
|
|
1415
|
+
*/
|
|
1416
|
+
stringAgg<S extends UnaggregatedQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: SelectQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E, delimiter: string): SelectQuery<OperandValueAggregateState<S, E>, Kind>;
|
|
1052
1417
|
/**
|
|
1053
1418
|
* 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
1419
|
*
|
|
@@ -1077,7 +1442,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
1077
1442
|
* 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
1443
|
* 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.
|
|
1079
1444
|
*/
|
|
1080
|
-
orderBy<Q extends QueryOf<RecordQueryState
|
|
1445
|
+
orderBy<Q extends QueryOf<RecordQueryState>>(this: Q, callback: (columns: ColumnRefs<Q["types"]["table"]> & RelationRefs<Q["types"]["schema"]>, selected: SelectedRefs<Q["types"]["result"]>) => OrderTerms): Q;
|
|
1081
1446
|
/**
|
|
1082
1447
|
* 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.
|
|
1083
1448
|
*
|
|
@@ -1114,7 +1479,7 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
1114
1479
|
* Inserts a record into the table of a query without clauses, such as a table of a `Db`, and resolves to the number of the inserted rows, `1`.
|
|
1115
1480
|
*
|
|
1116
1481
|
* A column omitted or given as `undefined` gets its default, so only columns marked with `hasDefault` and nullable columns may be omitted.
|
|
1117
|
-
* A value is what the type of its column takes, `null` for `NULL`,
|
|
1482
|
+
* A value is what the type of its column takes, `null` for `NULL`, an expression, such as a `sql` fragment, or a query of one value, which gives `NULL` without its row.
|
|
1118
1483
|
* Select the fields that it returns after it, such as `insert(values).get("id")`.
|
|
1119
1484
|
*/
|
|
1120
1485
|
insert<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, values: InsertValues<S["table"]>): MutationQuery<InitialMutationState<S["table"], S["schema"], "one">, Kind>;
|
|
@@ -1125,15 +1490,26 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
1125
1490
|
* Select the fields that it returns for the inserted rows after it, such as `insertMany(records).select("id", "email")`, and match them to the records by a key rather than by their order, which PostgreSQL does not guarantee.
|
|
1126
1491
|
*/
|
|
1127
1492
|
insertMany<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, records: readonly InsertValues<S["table"]>[]): MutationQuery<InitialMutationState<S["table"], S["schema"], "many">, Kind>;
|
|
1493
|
+
/**
|
|
1494
|
+
* Updates the rows that the filters of the query choose with the values that `callback` returns, and resolves to the number of the updated rows.
|
|
1495
|
+
*
|
|
1496
|
+
* `callback` receives the columns and the queries of the relations of the changed rows, such as to set a column from another one or from related records, and returns the values of the columns to update; a column omitted or given as `undefined` keeps its value.
|
|
1497
|
+
* A value is what `insert` takes as a value, such as a query of an aggregate of related records.
|
|
1498
|
+
* A query of `find` or `findBy` rejects with `NotFoundError` without its row, unless `optional` or `nullable` allows it.
|
|
1499
|
+
* A query without a filter must call `all` to update every row.
|
|
1500
|
+
* Select the fields that it returns after it, with their values after the update, such as `update(callback).select("id")`.
|
|
1501
|
+
*/
|
|
1502
|
+
update<S extends SelectQueryState, Kind extends SelectQueryKind, F extends (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => UpdateValues<S["table"]>>(this: SelectQuery<S, Kind>, callback: F): MutationQuery<InitialMutationState<S["table"], S["schema"], S["rows"], OperandUses<ReturnType<F>[keyof ReturnType<F>]>>, Kind>;
|
|
1128
1503
|
/**
|
|
1129
1504
|
* Updates the rows that the filters of the query choose with the values of `set`, and resolves to the number of the updated rows.
|
|
1130
1505
|
*
|
|
1131
|
-
* `set` gives the values of the columns to update, or is a callback that
|
|
1506
|
+
* `set` gives the values of the columns to update, or is a callback that returns them; a column omitted or given as `undefined` keeps its value.
|
|
1507
|
+
* A value is what `insert` takes as a value.
|
|
1132
1508
|
* A query of `find` or `findBy` rejects with `NotFoundError` without its row, unless `optional` or `nullable` allows it.
|
|
1133
1509
|
* A query without a filter must call `all` to update every row.
|
|
1134
1510
|
* Select the fields that it returns after it, with their values after the update, such as `update(set).select("id")`.
|
|
1135
1511
|
*/
|
|
1136
|
-
update<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, set: UpdateSet<S["table"]>): MutationQuery<InitialMutationState<S["table"], S["schema"], S["rows"]>, Kind>;
|
|
1512
|
+
update<S extends SelectQueryState, Kind extends SelectQueryKind>(this: SelectQuery<S, Kind>, set: UpdateSet<S["table"], S["schema"]>): MutationQuery<InitialMutationState<S["table"], S["schema"], S["rows"]>, Kind>;
|
|
1137
1513
|
/**
|
|
1138
1514
|
* Deletes the rows that the filters of the query choose, and resolves to the number of the deleted rows.
|
|
1139
1515
|
*
|
|
@@ -1157,322 +1533,101 @@ declare class SelectQuery<out S extends SelectQueryState, out Kind extends Selec
|
|
|
1157
1533
|
*/
|
|
1158
1534
|
toSQL(...args: ToSQLArgs<Kind>): SqlStatement;
|
|
1159
1535
|
/**
|
|
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;
|
|
1171
|
-
/** Creates a query of the same kind and `Db` with the node changes applied. */
|
|
1172
|
-
private derive;
|
|
1173
|
-
/**
|
|
1174
|
-
* Creates a query of the same kind and `Db` with the node changes applied and then those of `take`, in one derived query.
|
|
1175
|
-
*
|
|
1176
|
-
* It adds the changes of `take` to `changes`, which must leave the limit as it is.
|
|
1177
|
-
*/
|
|
1178
|
-
private deriveTaken;
|
|
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. */
|
|
1180
|
-
private deriveAggregate;
|
|
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`. */
|
|
1182
|
-
private aggregateBy;
|
|
1183
|
-
/** Returns the changes of the node that add `filter` with `AND`, ending the guarantee of the row as `FilteredState` does in types. */
|
|
1184
|
-
private addFilter;
|
|
1185
|
-
/** Creates the query of `find` and `findBy`: `where` of `values`, an object of column values, returning one row like `take`. */
|
|
1186
|
-
private takeWhere;
|
|
1187
|
-
/** Creates the query of one row with rows mode `rows` that `method` returns, rejecting a query of many rows. */
|
|
1188
|
-
private changeOneRow;
|
|
1189
|
-
/** Rejects a change of the selection by `method` of a query made by `get`, `pluck`, or an aggregate method. */
|
|
1190
|
-
private rejectValue;
|
|
1191
|
-
/** Rejects `method`, which replaces the value or the selection, on a query made by an aggregate method or `exists`. */
|
|
1192
|
-
private rejectAggregate;
|
|
1193
|
-
}
|
|
1194
|
-
/** Select query bound to a `Db`, executed by awaiting it; every method returns a query bound to the same `Db`. */
|
|
1195
|
-
type BoundSelectQuery<S extends SelectQueryState> = SelectQuery<S, "bound">;
|
|
1196
|
-
/** Select query of any state and kind. */
|
|
1197
|
-
type AnySelectQuery = SelectQuery<any, SelectQueryKind>;
|
|
1198
|
-
/** Type of a record of a query result, or of its value for a query made by `get`, `pluck`, or an aggregate method. */
|
|
1199
|
-
type ResultOf<Q extends AnyQuery> = Q["types"]["result"];
|
|
1200
|
-
/** Table of a definition such as `defineFilter`: the table itself or a query over it with schema context `C`, such as `schema.form`. */
|
|
1201
|
-
type TableOrQuery<T extends AnyTable, C extends SchemaContext = SchemaContext> = T | QueryOf<QueryStateOf<T, C>>;
|
|
1202
|
-
/** Starts a query over a new occurrence of the table. */
|
|
1203
|
-
declare function from<T extends AnyTable>(table: T): SelectQuery<InitialQueryState<T>>;
|
|
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;
|
|
1209
|
-
}
|
|
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)>>;
|
|
1215
|
-
}
|
|
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;
|
|
1232
|
-
/** State of a query of `$select` in types: one record `R`, whose nested queries select records of relations `U`. */
|
|
1233
|
-
interface RecordQueryState<R = unknown, U extends UsedRelation = UsedRelation> extends QueryState {
|
|
1234
|
-
readonly result: R;
|
|
1235
|
-
readonly rows: "one";
|
|
1236
|
-
readonly value: false;
|
|
1237
|
-
readonly uses: U;
|
|
1238
|
-
}
|
|
1239
|
-
/** State of the query of `$select` of `Sel`: the record of the values of its expressions and the results of its queries. */
|
|
1240
|
-
type SelectionState<Sel extends Selection> = RecordQueryState<MergeSelection<EmptyRecord, SelectionResult<Sel>>, SelectionUses<Sel>>;
|
|
1241
|
-
/**
|
|
1242
|
-
* Immutable query of `$select` of state `S`, unbound or bound to a `Db`: one record whose fields are the values of expressions and the results of independent queries, selected in one statement.
|
|
1243
|
-
*
|
|
1244
|
-
* An unbound query is not thenable, so it can be returned from async functions; it is compiled with `toSQL` or executed by a `Db`.
|
|
1245
|
-
* A bound query executes on its `Db` when awaited.
|
|
1246
|
-
*/
|
|
1247
|
-
declare class RecordQuery<out S extends RecordQueryState, out Kind extends SelectQueryKind = "unbound"> {
|
|
1248
|
-
readonly node: RecordQueryNode;
|
|
1249
|
-
readonly types: S;
|
|
1250
|
-
/** `Db` that executes the query when it is awaited; `undefined` for an unbound query. */
|
|
1251
|
-
readonly db: QueryDb<Kind>;
|
|
1252
|
-
/** Executes a bound query on its `Db`; `undefined` for an unbound query, so that it is not thenable. */
|
|
1253
|
-
readonly then: QueryThen<S, Kind>;
|
|
1254
|
-
constructor(node: RecordQueryNode, db?: AnyDb);
|
|
1255
|
-
/**
|
|
1256
|
-
* Compiles the query into SQL text and parameters; `schemaName` qualifies its tables.
|
|
1536
|
+
* 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`.
|
|
1257
1537
|
*
|
|
1258
|
-
*
|
|
1538
|
+
* It rejects a query of records or of rows `many`, which `ScalarQuery` rejects in types.
|
|
1259
1539
|
*/
|
|
1260
|
-
|
|
1261
|
-
/** Rejects the query as an operand of an expression, which takes a query of one value of a table. */
|
|
1262
|
-
[operandNode](): never;
|
|
1263
|
-
}
|
|
1264
|
-
/** Query of `$select` of any state and kind. */
|
|
1265
|
-
type AnyRecordQuery = RecordQuery<any, SelectQueryKind>;
|
|
1266
|
-
declare const schemaBrand: unique symbol;
|
|
1267
|
-
/** Key of the relation definitions of a schema, which composition reads. */
|
|
1268
|
-
declare const schemaRelations: unique symbol;
|
|
1269
|
-
/** Tables by their keys; a key must not start with `$`, which is reserved for schema and `Db` members. */
|
|
1270
|
-
type Tables = Record<string, AnyTable>;
|
|
1271
|
-
/**
|
|
1272
|
-
* Immutable collection of tables and their relations with query entry points.
|
|
1273
|
-
*
|
|
1274
|
-
* A schema is not bound to a database, so queries built from it can be defined at module level.
|
|
1275
|
-
* A `Db` can execute such a query if its schema contains the tables and the selected relations of the query and every bound nested query belongs to that `Db`.
|
|
1276
|
-
*/
|
|
1277
|
-
type Schema<T extends Tables, R extends SchemaRelations = EmptyRecord> = SchemaEntries<T, R> & SchemaMembers<T, R>;
|
|
1278
|
-
/** Query entry points; each access starts a query over a new table occurrence. */
|
|
1279
|
-
type SchemaEntries<T extends Tables, R extends SchemaRelations> = { readonly [K in keyof T]: SelectQuery<InitialQueryState<T[K], TableContext<R, K>>>; };
|
|
1280
|
-
/** Members of a schema that composition reads: its tables and the relations of its tables. */
|
|
1281
|
-
interface SchemaContents<T extends Tables, R extends SchemaRelations> {
|
|
1282
|
-
readonly [schemaBrand]: true;
|
|
1283
|
-
/** Tables of the schema by their keys. */
|
|
1284
|
-
readonly $tables: T;
|
|
1285
|
-
/** Relation definitions by table key and relation name. */
|
|
1286
|
-
readonly [schemaRelations]: R;
|
|
1287
|
-
}
|
|
1288
|
-
interface SchemaMembers<T extends Tables, R extends SchemaRelations> extends SchemaContents<T, R> {
|
|
1540
|
+
[operandNode](): ExpressionNode;
|
|
1289
1541
|
/**
|
|
1290
|
-
*
|
|
1542
|
+
* Returns the node of the query as the values of `in`, which lowering replaces with its statement.
|
|
1291
1543
|
*
|
|
1292
|
-
*
|
|
1544
|
+
* It rejects a query of records, which `ValuesQuery` rejects in types.
|
|
1293
1545
|
*/
|
|
1294
|
-
|
|
1546
|
+
[valuesQueryNode](): NestedQueryNode;
|
|
1547
|
+
/** Creates a query of the same kind and `Db` with the node changes applied. */
|
|
1548
|
+
private derive;
|
|
1295
1549
|
/**
|
|
1296
|
-
*
|
|
1550
|
+
* Creates a query of the same kind and `Db` with the node changes applied and then those of `take`, in one derived query.
|
|
1297
1551
|
*
|
|
1298
|
-
*
|
|
1552
|
+
* It adds the changes of `take` to `changes`, which must leave the limit as it is.
|
|
1299
1553
|
*/
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
interface PartContents {
|
|
1316
|
-
readonly tables: Tables;
|
|
1317
|
-
readonly relations: SchemaRelations;
|
|
1318
|
-
}
|
|
1319
|
-
type ComposeParts<P extends readonly SchemaPart[], Composed extends PartContents = {
|
|
1320
|
-
tables: EmptyRecord;
|
|
1321
|
-
relations: EmptyRecord;
|
|
1322
|
-
}> = P extends readonly [infer First extends SchemaPart, ...infer Rest extends readonly SchemaPart[]] ? ComposeParts<Rest, Composed & ReadPart<First>> : P extends readonly [...infer Rest extends readonly SchemaPart[], infer Last extends SchemaPart] ? ComposeParts<Rest, Composed & ReadPart<Last>> : Composed;
|
|
1323
|
-
type ReadPart<P extends SchemaPart> = P extends SchemaContents<infer T, any> ? {
|
|
1324
|
-
tables: T;
|
|
1325
|
-
relations: P[typeof schemaRelations];
|
|
1326
|
-
} : {
|
|
1327
|
-
tables: P;
|
|
1328
|
-
relations: EmptyRecord;
|
|
1329
|
-
};
|
|
1330
|
-
/**
|
|
1331
|
-
* Defines a schema of the tables of `parts`, keyed by their names in queries.
|
|
1332
|
-
*
|
|
1333
|
-
* A part is an object of tables by their keys or another schema, whose tables and relations the new schema includes as they are, so queries built from that schema run on the new one.
|
|
1334
|
-
* A key of two different tables, a table under two keys, and two different definitions of a relation of a table are rejected; the same table under the same key or the same relation in several parts is one.
|
|
1335
|
-
*/
|
|
1336
|
-
declare function defineSchema<P extends SchemaPart[]>(...parts: P): Schema<SchemaTables<P>, SchemaPartRelations<P>>;
|
|
1337
|
-
declare const sourceTable: unique symbol;
|
|
1338
|
-
declare const sourceKey: unique symbol;
|
|
1339
|
-
/** Runtime mark of the declarations of `many` and `one`. */
|
|
1340
|
-
declare const declarationBrand: unique symbol;
|
|
1341
|
-
/** Kind of a relation: `many` related records, or `one` related record at most. */
|
|
1342
|
-
type RelationKind = "many" | "one";
|
|
1343
|
-
/** Relation of a table of a schema to the records of table `Target`, which has key `TargetKey` in the schema. */
|
|
1344
|
-
interface Relation<Kind extends RelationKind = RelationKind, Target extends AnyTable = AnyTable, TargetKey extends string = string, Required extends boolean = boolean> {
|
|
1345
|
-
readonly kind: Kind;
|
|
1346
|
-
readonly target: Target;
|
|
1347
|
-
readonly targetKey: TargetKey;
|
|
1348
|
-
/** Whether every record of the table has its related record, so that a query of a relation `one` without a filter rejects without it rather than giving `null`; `false` for a relation `many`. */
|
|
1349
|
-
readonly required: Required;
|
|
1554
|
+
private deriveTaken;
|
|
1555
|
+
/** 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. */
|
|
1556
|
+
private deriveAggregate;
|
|
1557
|
+
/** Creates the query of the aggregate of `method` over `arg`, a column key or a callback that receives the columns and the relations and returns an expression or a query of one value; `delimiter` is the delimiter of `stringAgg`. */
|
|
1558
|
+
private aggregateBy;
|
|
1559
|
+
/** Returns the changes of the node that add `filter` with `AND`, ending the guarantee of the row as `FilteredState` does in types. */
|
|
1560
|
+
private addFilter;
|
|
1561
|
+
/** Creates the query of `find` and `findBy`: `where` of `values`, an object of column values, returning one row like `take`. */
|
|
1562
|
+
private takeWhere;
|
|
1563
|
+
/** Creates the query of one row with rows mode `rows` that `method` returns, rejecting a query of many rows. */
|
|
1564
|
+
private changeOneRow;
|
|
1565
|
+
/** Rejects a change of the selection by `method` of a query made by `get`, `pluck`, or an aggregate method. */
|
|
1566
|
+
private rejectValue;
|
|
1567
|
+
/** Rejects `method`, which replaces the value or the selection, on a query made by an aggregate method or `exists`. */
|
|
1568
|
+
private rejectAggregate;
|
|
1350
1569
|
}
|
|
1570
|
+
/** Select query bound to a `Db`, executed by awaiting it; every method returns a query bound to the same `Db`. */
|
|
1571
|
+
type BoundSelectQuery<S extends SelectQueryState> = SelectQuery<S, "bound">;
|
|
1572
|
+
/** Select query of any state and kind. */
|
|
1573
|
+
type AnySelectQuery = SelectQuery<any, SelectQueryKind>;
|
|
1574
|
+
/** Type of a record of a query result, or of its value for a query made by `get`, `pluck`, or an aggregate method. */
|
|
1575
|
+
type ResultOf<Q extends AnyQuery> = Q["types"]["result"];
|
|
1576
|
+
/** Table of a definition such as `defineExpression`: the table itself or a query over it with schema context `C`, such as `schema.form`. */
|
|
1577
|
+
type TableOrQuery<T extends AnyTable, C extends SchemaContext = SchemaContext> = T | QueryOf<QueryStateOf<T, C>>;
|
|
1578
|
+
/** Starts a query over a new occurrence of the table. */
|
|
1579
|
+
declare function from<T extends AnyTable>(table: T): SelectQuery<InitialQueryState<T>>;
|
|
1580
|
+
/** First operand of `coalesce`, `greatest`, and `least`: an expression with a type, or a query of one value, such as of an aggregate, whose type decodes the result and gives it its operators. */
|
|
1581
|
+
type TypedOperand = TypedExpression | TypedScalarQuery;
|
|
1582
|
+
/** Values that the type of the first operand `F` encodes. */
|
|
1583
|
+
type TypedOperandInput<F> = F extends TypedScalarQuery ? F["types"]["valueType"]["input"] : ExpressionInput<F>;
|
|
1584
|
+
/** Operators of the type of the first operand `F`. */
|
|
1585
|
+
type TypedOperandOperators<F> = F extends TypedScalarQuery ? F["types"]["valueType"]["operators"] : F extends TypedExpression ? ExpressionOperators<F> : never;
|
|
1586
|
+
/** Operand of `coalesce`, `greatest`, and `least` after the first operand `F`: a value that its type encodes, or an expression or a query of one value of its values. */
|
|
1587
|
+
type FollowingOperand<F> = Operand<OperandValue<F>, TypedOperandInput<F>>;
|
|
1588
|
+
/** `null` when every operand can be `NULL`: the first operand `F` and the following operands `R`. */
|
|
1589
|
+
type NullOfEveryOperand<F, R extends readonly unknown[]> = null extends OperandValue<F> ? number extends R["length"] ? null : { [K in keyof R]: null extends OperandValue<R[K]> ? never : true; }[number] extends never ? null : never : never;
|
|
1590
|
+
/** Result of a function of the first operand `F` and the following operands `R` that is `NULL` only when every operand is, whose operands all have the values of `F`. */
|
|
1591
|
+
type NullSkippingResult<F, R extends readonly unknown[]> = Expression<Exclude<OperandValue<F>, null> | NullOfEveryOperand<F, R>, TypedOperandOperators<F>, TypedOperandInput<F>>;
|
|
1351
1592
|
/**
|
|
1352
|
-
*
|
|
1593
|
+
* Returns the first of its operands other than `NULL`, such as `coalesce(field.hint, "")`, as an expression usable wherever a column is.
|
|
1353
1594
|
*
|
|
1354
|
-
*
|
|
1595
|
+
* `first` is an expression with a type or a query of one value; its type decodes the result and gives it its operators, and encodes plain values among `rest`.
|
|
1596
|
+
* A query without its row is `NULL` here, unlike with the method `coalesce` of a query, which keeps a missing row missing.
|
|
1355
1597
|
*/
|
|
1356
|
-
|
|
1357
|
-
readonly name: string;
|
|
1358
|
-
/** Key of the source table. */
|
|
1359
|
-
readonly key: string;
|
|
1360
|
-
readonly source: AnyTable;
|
|
1361
|
-
readonly from: readonly string[];
|
|
1362
|
-
readonly to: readonly string[];
|
|
1363
|
-
}
|
|
1364
|
-
/** Relation `N` of the table under key `K` of a schema, of type `R`, whose records a query selects. */
|
|
1365
|
-
interface UsedRelation<K extends string = string, N extends string = string, R extends Relation = Relation> {
|
|
1366
|
-
readonly key: K;
|
|
1367
|
-
readonly name: N;
|
|
1368
|
-
readonly relation: R;
|
|
1369
|
-
}
|
|
1370
|
-
/** Relations of schema relations `R` that the queries of a `Db` of the schema may select. */
|
|
1371
|
-
type UsableRelation<R extends SchemaRelations> = { [K in keyof R & string]: { [N in keyof R[K] & string]: UsedRelation<K, N, R[K][N]>; }[keyof R[K] & string]; }[keyof R & string];
|
|
1372
|
-
/** Relations of the tables of a schema by table key and relation name. */
|
|
1373
|
-
type SchemaRelations = {
|
|
1374
|
-
readonly [key: string]: TableRelations;
|
|
1375
|
-
};
|
|
1376
|
-
/** Relations of a table of a schema by relation name. */
|
|
1377
|
-
type TableRelations = {
|
|
1378
|
-
readonly [name: string]: Relation;
|
|
1379
|
-
};
|
|
1598
|
+
declare function coalesce<F extends TypedOperand, const R extends readonly FollowingOperand<F>[]>(first: F, ...rest: R): NullSkippingResult<F, R>;
|
|
1380
1599
|
/**
|
|
1381
|
-
*
|
|
1600
|
+
* Returns the largest of its operands, skipping `NULL`, which is the result only when every operand is `NULL`.
|
|
1382
1601
|
*
|
|
1383
|
-
* `
|
|
1602
|
+
* `first` is an expression with a type or a query of one value; its type decodes the result and gives it its operators, and encodes plain values among `rest`.
|
|
1384
1603
|
*/
|
|
1385
|
-
|
|
1386
|
-
readonly [declarationBrand]: true;
|
|
1387
|
-
readonly kind: Kind;
|
|
1388
|
-
readonly target: Target;
|
|
1389
|
-
readonly from: readonly string[];
|
|
1390
|
-
readonly to: readonly string[];
|
|
1391
|
-
readonly required: Required;
|
|
1392
|
-
readonly [sourceTable]?: (source: Source) => void;
|
|
1393
|
-
readonly [sourceKey]?: From;
|
|
1394
|
-
}
|
|
1395
|
-
/** Column key of table `T` whose type has SQL `=`, which a relation can compare. */
|
|
1396
|
-
type EqualityKey<T extends AnyTable> = { [K in keyof T["columns"]]: HasEquality<ColumnOperators<T, K>> extends true ? K : never; }[keyof T["columns"]] & string;
|
|
1397
|
-
/** Key of a relation in table `T`: a column key, or a non-empty list of them for a composite key. */
|
|
1398
|
-
type RelationKey<T extends AnyTable> = EqualityKey<T> | readonly [EqualityKey<T>, ...EqualityKey<T>[]];
|
|
1399
|
-
/** Key of table `T` with as many columns as key `From`. */
|
|
1400
|
-
type MatchingKey<T extends AnyTable, From> = From extends string ? EqualityKey<T> : { readonly [I in keyof From]: EqualityKey<T>; };
|
|
1401
|
-
/** Keys of a relation: the columns `from` of the source table equal the columns `to` of the target table, in order. */
|
|
1402
|
-
interface RelationKeys<Target extends AnyTable, From> {
|
|
1403
|
-
readonly from: From;
|
|
1404
|
-
readonly to: MatchingKey<Target, From>;
|
|
1405
|
-
}
|
|
1406
|
-
/** Keys of a relation `one`, as in `RelationKeys`, and whether the relation is required. */
|
|
1407
|
-
interface OneRelationKeys<From, To> {
|
|
1408
|
-
readonly from: From;
|
|
1409
|
-
readonly to: To;
|
|
1410
|
-
/** Whether every record has its related record, such as by a foreign key on columns `from` that are not nullable, so that a query of the relation without a filter rejects without it rather than giving `null`. */
|
|
1411
|
-
readonly required?: boolean;
|
|
1412
|
-
}
|
|
1413
|
-
/** Members of the keys `K` of a relation `one` with only `required` typed, so that a call infers `K` with `required` as optional as it is, and reports a wrong key at its own member. */
|
|
1414
|
-
type RequiredMember<K> = { readonly [P in keyof K]: P extends "required" ? K[P] : unknown; };
|
|
1415
|
-
/** Whether the keys `K` of a relation `one` make it required: only where they set `required` to `true`, and `boolean` where `required` may be `true` or missing, such as `required?: true`. */
|
|
1416
|
-
type DeclaredRequiredOf<K> = K extends unknown ? "required" extends keyof K ? K extends {
|
|
1417
|
-
readonly required: infer Required;
|
|
1418
|
-
} ? IsTrue<Required> : IsTrue<K["required" & keyof K] | undefined> : false : never;
|
|
1419
|
-
/** `true` for `true`, and `false` for other values, such as `false` and `undefined`; a union gives the union of their results. */
|
|
1420
|
-
type IsTrue<T> = T extends true ? true : false;
|
|
1421
|
-
/** Declarations of `$relations` of a schema of tables `T`: relations by name, for tables by their keys. */
|
|
1422
|
-
type RelationDeclarations<T extends Tables> = { readonly [K in keyof T]?: {
|
|
1423
|
-
readonly [name: string]: RelationDeclaration<RelationKind, T[K], T[keyof T]>;
|
|
1424
|
-
}; };
|
|
1604
|
+
declare function greatest<F extends TypedOperand, const R extends readonly FollowingOperand<F>[]>(first: F, ...rest: R): NullSkippingResult<F, R>;
|
|
1425
1605
|
/**
|
|
1426
|
-
*
|
|
1606
|
+
* Returns the smallest of its operands, skipping `NULL`, which is the result only when every operand is `NULL`.
|
|
1427
1607
|
*
|
|
1428
|
-
*
|
|
1429
|
-
* A relation name must not be a column key of its table or start with `$`, since the references that the callback of `select` gets have both.
|
|
1608
|
+
* `first` is an expression with a type or a query of one value; its type decodes the result and gives it its operators, and encodes plain values among `rest`.
|
|
1430
1609
|
*/
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
type
|
|
1434
|
-
/**
|
|
1435
|
-
type
|
|
1436
|
-
/**
|
|
1437
|
-
type
|
|
1438
|
-
/**
|
|
1439
|
-
type
|
|
1440
|
-
/** Check of key `To` of a relation `one` that rejects it when its columns include no key of table `Target`, as far as the types tell. */
|
|
1441
|
-
type TargetKeyCheck<Target extends AnyTable, To> = [ContainsKey<Target, RelationColumn<To>>] extends [false] ? {
|
|
1442
|
-
readonly to: MissingKey<KeyOf<Target["keys"]>>;
|
|
1443
|
-
} : unknown;
|
|
1444
|
-
/** Type that a key `to` of a relation `one` without a key of its target is checked against, naming the keys of the target. */
|
|
1445
|
-
interface MissingKey<Keys> {
|
|
1446
|
-
readonly "columns to must include a key of the target": Keys;
|
|
1447
|
-
}
|
|
1448
|
-
/** Key of table `Target` among tables `T`, as a string like the keys of objects. */
|
|
1449
|
-
type KeyOfTable<T extends Tables, Target> = { [K in keyof T]: [T[K]] extends [Target] ? [Target] extends [T[K]] ? K extends number ? `${K}` : K & string : never : never; }[keyof T];
|
|
1450
|
-
/** Relations of `R` by table key, with the relations under the same key merged. */
|
|
1451
|
-
type MergeRelations<R> = { [K in keyof R]: { [N in keyof R[K]]: R[K][N]; }; };
|
|
1452
|
-
/** Relations of the schema that a query starts from, by table key, and the key of the table of the query there. */
|
|
1453
|
-
interface SchemaContext<R extends SchemaRelations = SchemaRelations, K extends string = string> {
|
|
1454
|
-
readonly relations: R;
|
|
1455
|
-
readonly key: K;
|
|
1456
|
-
}
|
|
1457
|
-
/** Schema context of a query whose table has no relations, such as one of `from(table)`. */
|
|
1458
|
-
type NoRelations = SchemaContext<EmptyRecord, string>;
|
|
1459
|
-
/** Schema context of the queries of the table under key `K` of a schema of relations `R`, whose keys are strings, as object keys are at runtime. */
|
|
1460
|
-
type TableContext<R extends SchemaRelations, K> = K extends keyof R ? [keyof R[K]] extends [never] ? NoRelations : SchemaContext<R, K & string> : K extends number ? TableContext<R, `${K}`> : NoRelations;
|
|
1610
|
+
declare function least<F extends TypedOperand, const R extends readonly FollowingOperand<F>[]>(first: F, ...rest: R): NullSkippingResult<F, R>;
|
|
1611
|
+
/** Condition of a branch of `caseWhen`: a predicate, or a query of one Boolean value, such as of `exists`. */
|
|
1612
|
+
type CaseCondition = Predicate | ScalarQuery<boolean | null>;
|
|
1613
|
+
/** Value of a branch of `caseWhen` of a type of values `T` that encodes values `I`: an operand of the type, or a plain `null`. */
|
|
1614
|
+
type CaseValue<T, I> = Operand<T, I> | null;
|
|
1615
|
+
/** Branch of `caseWhen`: a condition and the value of the result when it holds. */
|
|
1616
|
+
type CaseBranch<T, I> = readonly [condition: CaseCondition, value: CaseValue<T, I>];
|
|
1617
|
+
/** Value of `caseWhen` of a type of values `T` whose branches and fallback have the values `V`, of which one gives the result. */
|
|
1618
|
+
type CaseResult<T, V> = Exclude<T, null> | Extract<OperandValue<V>, null>;
|
|
1461
1619
|
/**
|
|
1462
|
-
*
|
|
1620
|
+
* Returns the value of the first branch whose condition holds, as a SQL `CASE` expression, or `NULL` when none holds.
|
|
1463
1621
|
*
|
|
1464
|
-
*
|
|
1622
|
+
* `type` decodes the result and gives it its operators, and a plain value of a branch is cast to it, so that PostgreSQL does not take plain values for text.
|
|
1465
1623
|
*/
|
|
1466
|
-
declare function
|
|
1624
|
+
declare function caseWhen<Output, Input, O extends OperatorDefinitions>(type: Type<Output, Input, O, any>, branches: NoInfer<readonly CaseBranch<Output, Input>[]>): Expression<Exclude<Output, null> | null, O, Input>;
|
|
1467
1625
|
/**
|
|
1468
|
-
*
|
|
1626
|
+
* Returns the value of the first branch whose condition holds, as a SQL `CASE` expression, or `otherwise` when none holds.
|
|
1469
1627
|
*
|
|
1470
|
-
*
|
|
1471
|
-
* The columns `to` must include a key of `target`, primary or unique, so that they match at most one record.
|
|
1472
|
-
* Without the record, a query of the relation gives `null`, and a query of a relation declared with `required: true` rejects unless it filters the record.
|
|
1473
|
-
* Set `required: true` only where the database guarantees the record, such as by a foreign key on columns `from` that are not nullable.
|
|
1628
|
+
* `type` decodes the result and gives it its operators, and a plain value of a branch or of `otherwise` is cast to it, so that PostgreSQL does not take plain values for text.
|
|
1474
1629
|
*/
|
|
1475
|
-
declare function
|
|
1630
|
+
declare function caseWhen<Output, Input, O extends OperatorDefinitions, const B extends readonly CaseBranch<Output, Input>[], const E extends CaseValue<Output, Input>>(type: Type<Output, Input, O, any>, branches: B, otherwise: E): Expression<CaseResult<Output, B[number][1] | E>, O, Input>;
|
|
1476
1631
|
/**
|
|
1477
1632
|
* State in types of a query that inserts, updates, or deletes rows: its table and the relations of its schema, the rows mode of the rows it changes, and its result, which is their number until a selection returns their fields.
|
|
1478
1633
|
*
|
|
@@ -1486,8 +1641,8 @@ interface MutationQueryState extends QueryState {
|
|
|
1486
1641
|
/** Whether the query returns the fields of the rows it changes rather than their number. */
|
|
1487
1642
|
readonly returning: boolean;
|
|
1488
1643
|
}
|
|
1489
|
-
/** State of a query that inserts, updates, or deletes rows of table `T` with schema context `C` in rows mode `Rows` and returns their number
|
|
1490
|
-
interface InitialMutationState<T extends AnyTable, C extends SchemaContext, Rows extends ResultRows> extends MutationQueryState {
|
|
1644
|
+
/** State of a query that inserts, updates, or deletes rows of table `T` with schema context `C` in rows mode `Rows` and returns their number, whose values select records of relations `U`. */
|
|
1645
|
+
interface InitialMutationState<T extends AnyTable, C extends SchemaContext, Rows extends ResultRows, U extends UsedRelation = never> extends MutationQueryState {
|
|
1491
1646
|
readonly table: T;
|
|
1492
1647
|
readonly schema: C;
|
|
1493
1648
|
readonly changed: Rows;
|
|
@@ -1495,7 +1650,7 @@ interface InitialMutationState<T extends AnyTable, C extends SchemaContext, Rows
|
|
|
1495
1650
|
readonly result: number;
|
|
1496
1651
|
readonly rows: "one";
|
|
1497
1652
|
readonly value: true;
|
|
1498
|
-
readonly uses:
|
|
1653
|
+
readonly uses: U;
|
|
1499
1654
|
}
|
|
1500
1655
|
/** State `S` of a mutation with the parts of `Changes` replaced. */
|
|
1501
1656
|
type ChangeMutationState<S extends MutationQueryState, Changes extends Partial<MutationQueryState>> = { readonly [K in keyof MutationQueryState]: K extends keyof Changes ? Changes[K] : S[K]; } & {};
|
|
@@ -1526,6 +1681,14 @@ type ValueState$1<S extends MutationQueryState, V, Rows extends ResultRows> = Ch
|
|
|
1526
1681
|
value: true;
|
|
1527
1682
|
returning: true;
|
|
1528
1683
|
}>;
|
|
1684
|
+
/** State of a mutation of state `S` that returns the value of `E`, an expression or a query of one value that a callback returns, of each row it changes in rows mode `Rows`. */
|
|
1685
|
+
type OperandState<S extends MutationQueryState, E extends TypedOperand, Rows extends ResultRows> = ChangeMutationState<S, {
|
|
1686
|
+
result: OperandValue<E>;
|
|
1687
|
+
rows: Rows;
|
|
1688
|
+
value: true;
|
|
1689
|
+
returning: true;
|
|
1690
|
+
uses: S["uses"] | OperandUses<E>;
|
|
1691
|
+
}>;
|
|
1529
1692
|
/**
|
|
1530
1693
|
* Immutable query of state `S` that inserts, updates, or deletes rows, unbound or bound to a `Db`.
|
|
1531
1694
|
*
|
|
@@ -1536,7 +1699,7 @@ type ValueState$1<S extends MutationQueryState, V, Rows extends ResultRows> = Ch
|
|
|
1536
1699
|
declare class MutationQuery<out S extends MutationQueryState, out Kind extends SelectQueryKind = "unbound"> {
|
|
1537
1700
|
readonly table: S["table"];
|
|
1538
1701
|
readonly node: MutationNode;
|
|
1539
|
-
/** Relations of the table in the schema the query starts from, which
|
|
1702
|
+
/** Relations of the table in the schema the query starts from, which its callbacks receive. */
|
|
1540
1703
|
readonly context: QueryContext;
|
|
1541
1704
|
readonly types: S;
|
|
1542
1705
|
/** `Db` that executes the query when it is awaited; `undefined` for an unbound query. */
|
|
@@ -1544,7 +1707,7 @@ declare class MutationQuery<out S extends MutationQueryState, out Kind extends S
|
|
|
1544
1707
|
/** Executes a bound query on its `Db`; `undefined` for an unbound query, so that it is not thenable. */
|
|
1545
1708
|
readonly then: QueryThen<S, Kind>;
|
|
1546
1709
|
constructor(table: S["table"], node: MutationNode,
|
|
1547
|
-
/** Relations of the table in the schema the query starts from, which
|
|
1710
|
+
/** Relations of the table in the schema the query starts from, which its callbacks receive. */
|
|
1548
1711
|
context: QueryContext, db?: AnyDb);
|
|
1549
1712
|
/** Returns all columns of each changed row, replacing fields under their keys, instead of the number of the rows. */
|
|
1550
1713
|
select<S extends RecordMutationState, Kind extends SelectQueryKind>(this: MutationQuery<S, Kind>, all: "*"): MutationQuery<RecordsState<S, Selectable<S["table"]>>, Kind>;
|
|
@@ -1566,13 +1729,18 @@ declare class MutationQuery<out S extends MutationQueryState, out Kind extends S
|
|
|
1566
1729
|
/**
|
|
1567
1730
|
* Returns the value of the expression that `callback` returns for the changed row instead of the number of the rows, in a query that changes one row, such as of `insert` or `find`.
|
|
1568
1731
|
*
|
|
1732
|
+
* `callback` receives what the callback of `select` receives, and may return a query of one value, which gives `NULL` without its row.
|
|
1569
1733
|
* A query of a nullable row resolves to `undefined` without the row.
|
|
1570
1734
|
*/
|
|
1571
|
-
get<S extends OneRowMutationState, Kind extends SelectQueryKind, E extends
|
|
1735
|
+
get<S extends OneRowMutationState, Kind extends SelectQueryKind, E extends TypedOperand>(this: MutationQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): MutationQuery<OperandState<S, E, OneValueRows<S["changed"]>>, Kind>;
|
|
1572
1736
|
/** Returns the value of a column of each changed row instead of the number of the rows, keeping whether the query returns an array or one value. */
|
|
1573
1737
|
pluck<S extends MutationQueryState, Kind extends SelectQueryKind, K extends keyof S["table"]["columns"] & string>(this: MutationQuery<S, Kind>, key: K): MutationQuery<ValueState$1<S, Selectable<S["table"]>[K], ValueRows<S["changed"]>>, Kind>;
|
|
1574
|
-
/**
|
|
1575
|
-
|
|
1738
|
+
/**
|
|
1739
|
+
* Returns the value of the expression that `callback` returns for each changed row instead of the number of the rows, keeping whether the query returns an array or one value.
|
|
1740
|
+
*
|
|
1741
|
+
* `callback` receives what the callback of `select` receives, and may return a query of one value, which gives `NULL` without its row.
|
|
1742
|
+
*/
|
|
1743
|
+
pluck<S extends MutationQueryState, Kind extends SelectQueryKind, E extends TypedOperand>(this: MutationQuery<S, Kind>, callback: (columns: ColumnRefs<S["table"]> & RelationRefs<S["schema"]>) => E): MutationQuery<OperandState<S, E, ValueRows<S["changed"]>>, Kind>;
|
|
1576
1744
|
/**
|
|
1577
1745
|
* Compiles the query into SQL text and parameters; `schemaName` qualifies its tables.
|
|
1578
1746
|
*
|
|
@@ -1583,7 +1751,7 @@ declare class MutationQuery<out S extends MutationQueryState, out Kind extends S
|
|
|
1583
1751
|
[operandNode](): never;
|
|
1584
1752
|
/** Creates a mutation of the same kind and `Db` with the node changes applied. */
|
|
1585
1753
|
private derive;
|
|
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. */
|
|
1754
|
+
/** Creates the mutation that returns the value of `arg` of `method`, a column key or a callback that receives the columns and the relations and returns an expression or a query of one value, of each changed row. */
|
|
1587
1755
|
private deriveValue;
|
|
1588
1756
|
}
|
|
1589
1757
|
/** Query of any state and kind that inserts, updates, or deletes rows. */
|
|
@@ -1945,7 +2113,7 @@ type Db<T extends Tables, R extends SchemaRelations = EmptyRecord> = DbEntries<T
|
|
|
1945
2113
|
/** Bound query entry points; each access starts a query over a new table occurrence. */
|
|
1946
2114
|
type DbEntries<T extends Tables, R extends SchemaRelations> = { readonly [K in keyof T]: BoundSelectQuery<InitialQueryState<T[K], TableContext<R, K>>>; };
|
|
1947
2115
|
/** Bound or unbound query over a table of `T`, of `$select`, or that changes the rows of a table of `T`, that selects records only of relations of `R`, or a query of SQL text. */
|
|
1948
|
-
type DbQuery<T extends Tables, R extends SchemaRelations> = QueryOf<DbQueryState<T[keyof T], UsableRelation<R>>> | RecordQuery<RecordQueryState<unknown, UsableRelation<R>>, SelectQueryKind> | MutationQuery<DbMutationState<T[keyof T], UsableRelation<R>>, SelectQueryKind> | SqlQuery<SqlQueryState>;
|
|
2116
|
+
type DbQuery<T extends Tables, R extends SchemaRelations> = QueryOf<DbQueryState<T[keyof T], UsableRelation<R>>> | RecordQuery<RecordQueryState$1<unknown, UsableRelation<R>>, SelectQueryKind> | MutationQuery<DbMutationState<T[keyof T], UsableRelation<R>>, SelectQueryKind> | SqlQuery<SqlQueryState>;
|
|
1949
2117
|
/** State of a query that a `Db` can execute: over table `T`, selecting records only of relations `U`. */
|
|
1950
2118
|
interface DbQueryState<T extends AnyTable, U extends UsedRelation> extends QueryStateOf<T> {
|
|
1951
2119
|
readonly uses: U;
|
|
@@ -1978,7 +2146,7 @@ interface DbMethods<T extends Tables, R extends SchemaRelations> {
|
|
|
1978
2146
|
*/
|
|
1979
2147
|
$execute<Q extends DbQuery<T, R>>(query: Q): Promise<QueryResult<Q["types"]>>;
|
|
1980
2148
|
/**
|
|
1981
|
-
* Starts a query of one record whose fields are the values of the expressions and the results of the queries of `selection`, selected in one statement when awaited.
|
|
2149
|
+
* Starts a query of one record whose fields are the values of the expressions and of the literals and the results of the queries of `selection`, selected in one statement when awaited.
|
|
1982
2150
|
*
|
|
1983
2151
|
* A query of `selection` is unbound or bound to this `Db`, and the value of its field is the result it gives when executed, such as an array of records or one value.
|
|
1984
2152
|
*/
|
|
@@ -2222,6 +2390,8 @@ interface SelectNode<From extends SourceNode | undefined = SourceNode | undefine
|
|
|
2222
2390
|
readonly offset: ExpressionNode | undefined;
|
|
2223
2391
|
/** Required relation that guarantees the row of the query, such as `field.form`; see `ResultPlan`. */
|
|
2224
2392
|
readonly guaranteedBy: string | undefined;
|
|
2393
|
+
/** Template of the records of a query with literals; see `ResultPlan`. */
|
|
2394
|
+
readonly recordTemplate?: readonly RecordTemplateField[] | undefined;
|
|
2225
2395
|
}
|
|
2226
2396
|
/** Assignment of `SET` of an update: the value of the column under `key`. */
|
|
2227
2397
|
interface AssignmentNode {
|
|
@@ -2236,6 +2406,8 @@ interface AssignmentNode {
|
|
|
2236
2406
|
interface MutationParts<Field> extends ResultMode {
|
|
2237
2407
|
readonly target: TableSourceNode;
|
|
2238
2408
|
readonly returning: readonly Field[] | undefined;
|
|
2409
|
+
/** Template of the records of a mutation with literals; see `ResultPlan`. */
|
|
2410
|
+
readonly recordTemplate?: readonly RecordTemplateField[] | undefined;
|
|
2239
2411
|
}
|
|
2240
2412
|
/** Insert statement of rows of `VALUES`. */
|
|
2241
2413
|
interface InsertNode<Field = ProjectionNode> extends MutationParts<Field> {
|
|
@@ -2308,27 +2480,90 @@ interface BaseOperators {
|
|
|
2308
2480
|
}
|
|
2309
2481
|
/** Operators of ordered types: those of `equalityOperators`, and `lt`, `lte`, `gt`, and `gte` comparing with operands of the expression type. */
|
|
2310
2482
|
declare const orderingOperators: {
|
|
2483
|
+
eq: EqualityOperator<ComparisonSignature>;
|
|
2484
|
+
ne: EqualityOperator<ComparisonSignature>;
|
|
2485
|
+
in: EqualityOperator<InSignature>;
|
|
2311
2486
|
lt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
2312
2487
|
lte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
2313
2488
|
gt: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
2314
2489
|
gte: GenericOperator<ComparisonSignature, AnyExpression<unknown, unknown>>;
|
|
2315
|
-
eq: EqualityOperator<ComparisonSignature>;
|
|
2316
|
-
ne: EqualityOperator<ComparisonSignature>;
|
|
2317
|
-
in: EqualityOperator<InSignature>;
|
|
2318
2490
|
};
|
|
2491
|
+
/** Operators of the built-in types of numbers: those of `orderingOperators`. */
|
|
2492
|
+
type NumberTypeOperators = MergeOperators<NoOperators, typeof orderingOperators>;
|
|
2319
2493
|
/** Signature of pattern matching: patterns stay strings even when the text values are transformed. */
|
|
2320
2494
|
interface PatternSignature extends OperatorSignature {
|
|
2321
2495
|
readonly method: <V extends Operand<string>>(pattern: V) => Expression<BooleanResult<this["T"] | OperandValue<V>>>;
|
|
2322
2496
|
}
|
|
2497
|
+
/** Signature of `lower`, `upper`, and `trim`: a value of `text`, whatever the representation of the text values, and `NULL` when the text can be. */
|
|
2498
|
+
interface TextConversionSignature extends OperatorSignature {
|
|
2499
|
+
readonly method: () => Expression<string | (null extends this["T"] ? null : never), TextTypeOperators>;
|
|
2500
|
+
}
|
|
2501
|
+
/** Signature of `length`: the number of characters of the text, and `NULL` when the text can be. */
|
|
2502
|
+
interface TextLengthSignature extends OperatorSignature {
|
|
2503
|
+
readonly method: () => Expression<number | (null extends this["T"] ? null : never), NumberTypeOperators>;
|
|
2504
|
+
}
|
|
2505
|
+
/** Operators of `textOperators`. */
|
|
2506
|
+
type TextOperators = {
|
|
2507
|
+
like: GenericOperator<PatternSignature, AnyExpression<string | null>>;
|
|
2508
|
+
ilike: GenericOperator<PatternSignature, AnyExpression<string | null>>;
|
|
2509
|
+
lower: GenericOperator<TextConversionSignature, AnyExpression<string | null>>;
|
|
2510
|
+
upper: GenericOperator<TextConversionSignature, AnyExpression<string | null>>;
|
|
2511
|
+
trim: GenericOperator<TextConversionSignature, AnyExpression<string | null>>;
|
|
2512
|
+
length: GenericOperator<TextLengthSignature, AnyExpression<string | null>>;
|
|
2513
|
+
};
|
|
2514
|
+
/** Operators of the built-in text types: those of `orderingOperators` and `textOperators`. */
|
|
2515
|
+
type TextTypeOperators = MergeOperators<MergeOperators<NoOperators, typeof orderingOperators>, TextOperators>;
|
|
2323
2516
|
/**
|
|
2324
|
-
* Operators of text types: pattern matching with `LIKE` and `ILIKE
|
|
2517
|
+
* Operators of text types: pattern matching with `LIKE` and `ILIKE`, `lower` and `upper`, which convert the case of the text, `trim`, which removes spaces from both of its ends, and `length`, which counts its characters.
|
|
2325
2518
|
*
|
|
2326
2519
|
* A string pattern is sent as it is; `param(type, pattern)` encodes it with a type.
|
|
2327
2520
|
*/
|
|
2328
|
-
declare const textOperators:
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2521
|
+
declare const textOperators: TextOperators;
|
|
2522
|
+
/** Condition that always holds, such as for a branch of `and` built in code: `and(check, isAdmin ? TRUE : other)`. */
|
|
2523
|
+
declare const TRUE: Expression<boolean>;
|
|
2524
|
+
/** Condition that never holds, such as for a branch of `or` built in code: `or(check, isAdmin ? other : FALSE)`. */
|
|
2525
|
+
declare const FALSE: Expression<boolean>;
|
|
2526
|
+
/**
|
|
2527
|
+
* Defines a reusable expression of a table, which the callbacks of queries over the table call with their columns and any further arguments, such as to filter by it and select it in one query.
|
|
2528
|
+
*
|
|
2529
|
+
* `expression` returns an expression or a query of one value, and a call has its type, so that a selected field has its values and an expression has its operators.
|
|
2530
|
+
* 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 queries whose schema has them can call it.
|
|
2531
|
+
* Defined with a table, it receives only the columns, and every query of the table can call it, also one without relations, such as of `from`.
|
|
2532
|
+
*/
|
|
2533
|
+
declare function defineExpression<T extends AnyTable, R extends AnyExpression | ScalarQuery, A extends unknown[], C extends SchemaContext = NoRelations>(table: TableOrQuery<T, C>, expression: (columns: ColumnRefs<T> & RelationRefs<C>, ...args: A) => R): (columns: ColumnRefs<T> & RelationRefs<C>, ...args: A) => R;
|
|
2534
|
+
/** Keys of the columns among references `R`, without the queries of relations. */
|
|
2535
|
+
type ColumnRefKey<R> = { [K in keyof R]: R[K] extends AnyExpression ? K : never; }[keyof R];
|
|
2536
|
+
/** Type that a key of the object of `matches` is checked against when it is not a column of its references, naming the columns. */
|
|
2537
|
+
interface NotAColumn<Keys> {
|
|
2538
|
+
readonly "keys must be columns of the references": Keys;
|
|
2539
|
+
}
|
|
2540
|
+
/** Value of column `E` in the object of `matches`: an operand of its `eq`, or `null` when its input type includes it. */
|
|
2541
|
+
type MatchValue<E> = (E extends TypedExpression ? ExpressionOperators<E> extends {
|
|
2542
|
+
readonly eq: EqualityOperator<ComparisonSignature>;
|
|
2543
|
+
} ? Operand<ExpressionValue<E>, ExpressionInput<E>> : EqOperand<E> : EqOperand<E>) | (null extends ExpressionInput<E> ? null : never);
|
|
2544
|
+
/**
|
|
2545
|
+
* Check of object `V` of `matches` against references `R`, which gives each of its keys the value of its column.
|
|
2546
|
+
*
|
|
2547
|
+
* It maps the keys of the object rather than those of the references, so that a call reads the operands of only the columns it matches.
|
|
2548
|
+
*/
|
|
2549
|
+
type MatchCheck<R, V> = { readonly [K in keyof V]: K extends ColumnRefKey<R> ? MatchValue<R[K]> : NotAColumn<ColumnRefKey<R>>; };
|
|
2550
|
+
/** `null` that matching expression `E` with value `V` adds to the result; `never` when `V` is `null`, since `IS NULL` is never `NULL`. */
|
|
2551
|
+
type MatchNull<E, V> = V extends null ? never : E extends TypedExpression ? ExpressionOperators<E> extends {
|
|
2552
|
+
readonly eq: EqualityOperator<ComparisonSignature>;
|
|
2553
|
+
} ? null extends ExpressionValue<E> | OperandValue<V> ? null : never : CustomEqNull<E> : CustomEqNull<E>;
|
|
2554
|
+
/** `null` of the result of a custom `eq` of expression `E`. */
|
|
2555
|
+
type CustomEqNull<E> = E extends {
|
|
2556
|
+
eq: (...args: never[]) => AnyExpression<infer O>;
|
|
2557
|
+
} ? Extract<O, null> : never;
|
|
2558
|
+
/** Value of `matches` of object `V` over references `R`: `boolean`, or also `null` when a comparison of a column can be `NULL`. */
|
|
2559
|
+
type MatchResult<R, V> = boolean | (V extends unknown ? { [K in keyof V]-?: K extends keyof R ? MatchNull<R[K], V[K]> : never; }[keyof V] : never);
|
|
2560
|
+
/**
|
|
2561
|
+
* Creates a Boolean expression of an object of column values over the columns that a callback of a query receives, such as `matches(form, { published: true })`.
|
|
2562
|
+
*
|
|
2563
|
+
* Each value matches its column as in an object passed to `where`: `null` by `IS NULL`, and another value by the `eq` operator of the column; all of them must match, and an empty object is `TRUE`.
|
|
2564
|
+
* Unlike such an object in `and`, `or`, and `not`, the expression refers to the columns it receives whichever query it is used in, and applies wherever an expression does, such as in `select`.
|
|
2565
|
+
*/
|
|
2566
|
+
declare function matches<R extends object, const V extends { readonly [K in ColumnRefKey<R>]?: unknown; }>(columns: R, values: V & MatchCheck<R, V>): Expression<MatchResult<R, V>>;
|
|
2332
2567
|
/**
|
|
2333
2568
|
* 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
2569
|
*
|
|
@@ -2448,4 +2683,4 @@ declare function identifier(...names: [string, ...string[]]): UntypedExpression;
|
|
|
2448
2683
|
*/
|
|
2449
2684
|
declare function param<Output, Input, O extends OperatorDefinitions>(type: Type<Output, Input, O, any>, value: Input): Expression<Output, O, Input>;
|
|
2450
2685
|
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 {
|
|
2686
|
+
export { InitialSqlQueryState as $, EmptyRecord as $n, KeyKind as $r, Predicate as $t, AnyDb as A, SchemaPartRelations as An, RequiredRelationError as Ar, UpdateSet as At, TransactionCoordinator as B, MergeSelection as Bn, AnyType as Br, desc as Bt, orderingOperators as C, UsableRelation as Cn, Selectable as Cr, ScalarQuery as Ct, ExpressionOperators as D, AnySchema as Dn, ToColumns as Dr, from as Dt, Expression as E, one as En, TableOptions as Er, ValuesQuery as Et, DbQueryState as F, RecordQuery as Fn, Driver as Fr, OrderTerm as Ft, TestHooks as G, FilteredRows as Gn, TypeOperators as Gr, EqValue as Gt, PendingTestFixture as H, Selection as Hn, TextValue as Hr, KeyCheck as Ht, Database as I, RecordQueryState$1 as In, DriverResult as Ir, OrderTerms as It, AnyQuery as J, QueryResult as Jn, TypeTransform as Jr, WhereFilter as Jt, TestTransactionOptions as K, OneRow as Kn, TypeOptions as Kr, WhereCallback as Kt, DatabaseOptions as L, SelectionState as Ln, SqlStatement as Lr, Ordering as Lt, Db as M, Tables as Mn, ResultMode as Mr, OrderColumns as Mt, DbMutationState as N, defineSchema as Nn, ResultRows as Nr, OrderDirection as Nt, TypedExpression as O, Schema as On, defineTable as Or, ColumnValue as Ot, DbOf as P, AnyRecordQuery as Pn, Connection as Pr, OrderKey as Pt, FieldTypes as Q, literal as Qn, ColumnAttributes as Qr, ConditionOperand as Qt, TransactionOptions as R, ExpressionInput as Rn, TransactionFailure as Rr, SelectedRefs as Rt, NumberTypeOperators as S, TableRelations as Sn, KeyColumns as Sr, ResultOf as St, BaseOperators as T, many as Tn, TableKeys as Tr, TypedScalarQuery as Tt, TestFixture as U, SelectionResult as Un, Type as Ur, NotAKey as Ut, OpenedTestFixture as V, NestedQuery as Vn, BaseType as Vr, orderBy as Vt, TestHelpers as W, SelectionUses as Wn, TypeInput as Wr, PrimaryKeyValues as Wt, AnySqlQuery as X, ValueRows as Xn, AnyColumn as Xr, CombinedCondition as Xt, SelectQueryKind as Y, ResultByRows as Yn, defineType as Yr, WhereValues as Yt, DecodedFields as Z, Literal as Zn, Column as Zr, Condition as Zt, TextConversionSignature as _, RelationKind as _n, AnyTableKeys as _r, least as _t, Helper as a, GenericOperator as ai, QueryContext as an, EqualityOperator as ar, MutationQueryState as at, TextTypeOperators as b, SchemaRelations as bn, ColumnShape as br, FilteredStateRows as bt, ColumnRefKey as c, defineGenericOperator as ci, DeclaredRelations as cn, InSignature as cr, CaseValue as ct, NotAColumn as d, OneRelationKeys as dn, ComparisonSignature as dr, TypedOperand as dt, ToColumn as ei, and as en, InitialQueryState as er, SqlQuery as et, matches as f, Relation as fn, Operand as fr, TypedOperandInput as ft, PatternSignature as g, RelationKeys as gn, AnyTable as gr, greatest as gt, TRUE as h, RelationKey as hn, CompileOptions as hr, coalesce as ht, sql as i, OperatorDefinitions as ii, ColumnRefs as in, SelectQueryState as ir, MutationQuery as it, BindOptions as j, SchemaTables as jn, ResultDecodeError as jr, UpdateValues as jt, UntypedExpression as k, SchemaPart as kn, NotFoundError as kr, InsertValues as kt, MatchCheck as l, MergeRelations as ln, equalityOperators as lr, FollowingOperand as lt, FALSE as m, RelationDeclarations as mn, compare as mr, caseWhen as mt, identifier as n, MergeOperators as ni, or as nn, QueryStateOf as nr, AnyMutationQuery as nt, HelperEffect as o, GenericOperatorImplementation as oi, RelationRefs as on, EqualityOperators as or, CaseBranch as ot, defineExpression as p, RelationDeclaration as pn, OperandValue as pr, TypedOperandOperators as pt, createTestHelpers as q, OneValueRows as qn, TypeOutput as qr, WhereCondition as qt, param as r, NoOperators as ri, ExistsValueType as rn, QueryValueType as rr, InitialMutationState as rt, defineHelper as s, OperatorSignature as si, CountValueType as sn, HasEquality as sr, CaseCondition as st, SqlTemplate as t, BoundOperators as ti, not as tn, QueryState as tr, SqlQueryState as tt, MatchResult as u, NoRelations as un, BooleanResult as ur, NullSkippingResult as ut, TextLengthSignature as v, RequiredMember as vn, ColumnDefinitions as vr, AnySelectQuery as vt, AnyExpression as w, UsedRelation as wn, Table as wr, SelectQuery as wt, textOperators as x, TableContext as xn, ColumnValues as xr, OperandUses as xt, TextOperators as y, SchemaContext as yn, ColumnOperators as yr, BoundSelectQuery as yt, createDatabase as z, ExpressionValue as zn, createStatement as zr, asc as zt };
|