durcno 1.0.0-alpha.12 → 1.0.0-alpha.13
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/bin.cjs +1 -1
- package/dist/src/columns/common.d.mts +9 -0
- package/dist/src/columns/common.mjs +13 -0
- package/dist/src/constraints/check.d.mts +2 -2
- package/dist/src/constraints/check.mjs +1 -1
- package/dist/src/db.d.mts +1 -9
- package/dist/src/db.mjs +1 -11
- package/dist/src/filters/array.d.mts +16 -16
- package/dist/src/filters/index.d.mts +25 -25
- package/dist/src/filters/postgis.d.mts +1 -2
- package/dist/src/filters/string.d.mts +1 -2
- package/dist/src/functions/aggregate.d.mts +7 -7
- package/dist/src/functions/index.d.mts +3 -3
- package/dist/src/functions/numeric.d.mts +11 -11
- package/dist/src/functions/string.d.mts +17 -17
- package/dist/src/migration/ddl/index.d.mts +1 -41
- package/dist/src/migration/ddl/index.mjs +1 -44
- package/dist/src/migration/ddl/statement.d.mts +1 -4
- package/dist/src/migration/snapshot.mjs +18 -0
- package/dist/src/query-builders/insert.d.mts +5 -2
- package/dist/src/query-builders/insert.mjs +3 -2
- package/dist/src/query-builders/pre.d.mts +10 -3
- package/dist/src/query-builders/pre.mjs +11 -2
- package/dist/src/query-builders/rq.d.mts +39 -28
- package/dist/src/query-builders/rq.mjs +18 -10
- package/dist/src/query-builders/select.d.mts +4 -3
- package/dist/src/query-builders/select.mjs +12 -2
- package/dist/src/table.d.mts +5 -5
- package/package.json +2 -2
- package/dist/src/migration/ddl/enum.d.mts +0 -100
- package/dist/src/migration/ddl/enum.mjs +0 -148
- package/dist/src/query-builders/insert-returning.d.mts +0 -15
- package/dist/src/query-builders/insert-returning.mjs +0 -37
package/dist/bin.cjs
CHANGED
|
@@ -10451,7 +10451,7 @@ async function status(options) {
|
|
|
10451
10451
|
}
|
|
10452
10452
|
|
|
10453
10453
|
// src/cli/index.ts
|
|
10454
|
-
program.version("1.0.0-alpha.
|
|
10454
|
+
program.version("1.0.0-alpha.12");
|
|
10455
10455
|
var Options = {
|
|
10456
10456
|
config: ["--config <path>", "Path to the config file"]
|
|
10457
10457
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CheckExpression } from "../constraints/check.mjs";
|
|
1
2
|
import { entityType } from "../symbols.mjs";
|
|
2
3
|
import { StdTable, StdTableColumn } from "../table.mjs";
|
|
4
|
+
import { AnyFilter } from "../filters/index.mjs";
|
|
3
5
|
import { Arg } from "../query-builders/pre.mjs";
|
|
4
6
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
5
7
|
import { Sql } from "../sql.mjs";
|
|
@@ -273,6 +275,13 @@ declare abstract class Column<TConfig extends ColumnConfig, TColVal, TPgType ext
|
|
|
273
275
|
get hasReferences(): boolean;
|
|
274
276
|
get getReferencesCol(): StdTableColumn | null;
|
|
275
277
|
get getReferencesOnDelete(): OnDeleteAction | null;
|
|
278
|
+
/**
|
|
279
|
+
* Attaches a column-level CHECK constraint.
|
|
280
|
+
* SQL equivalent: `CONSTRAINT "{table}_{col}_check" CHECK (<expr>)`
|
|
281
|
+
* @param fn - Function receiving the column and returning a filter or SQL expression.
|
|
282
|
+
*/
|
|
283
|
+
check(fn: (c: this) => CheckExpression<this>): this;
|
|
284
|
+
get getCheckFn(): ((c: StdTableColumn) => AnyFilter | Sql) | undefined;
|
|
276
285
|
/**
|
|
277
286
|
* Sets a function to be called during INSERT queries to generate a value.
|
|
278
287
|
* @param fn - A function that returns the value to insert
|
|
@@ -74,6 +74,7 @@ var Column = class {
|
|
|
74
74
|
#generated;
|
|
75
75
|
#generatedAs;
|
|
76
76
|
#references;
|
|
77
|
+
#check;
|
|
77
78
|
#name;
|
|
78
79
|
#nameSql;
|
|
79
80
|
#table;
|
|
@@ -334,6 +335,18 @@ var Column = class {
|
|
|
334
335
|
return this.#references ? this.#references.onDelete : null;
|
|
335
336
|
}
|
|
336
337
|
/**
|
|
338
|
+
* Attaches a column-level CHECK constraint.
|
|
339
|
+
* SQL equivalent: `CONSTRAINT "{table}_{col}_check" CHECK (<expr>)`
|
|
340
|
+
* @param fn - Function receiving the column and returning a filter or SQL expression.
|
|
341
|
+
*/
|
|
342
|
+
check(fn) {
|
|
343
|
+
this.#check = fn;
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
get getCheckFn() {
|
|
347
|
+
return this.#check;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
337
350
|
* Sets a function to be called during INSERT queries to generate a value.
|
|
338
351
|
* @param fn - A function that returns the value to insert
|
|
339
352
|
* @returns HasInsertFn<this>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TableAnyColumn } from "../table.mjs";
|
|
1
|
+
import { AnyColumn, TableAnyColumn } from "../table.mjs";
|
|
2
2
|
import { AnyFilter, Filter } from "../filters/index.mjs";
|
|
3
3
|
import { QueryContext } from "../query-builders/query.mjs";
|
|
4
4
|
import { Sql } from "../sql.mjs";
|
|
@@ -8,7 +8,7 @@ import { Sql } from "../sql.mjs";
|
|
|
8
8
|
* A check constraint expression that can be a filter condition or a raw SQL snippet.
|
|
9
9
|
* Used in `checkConstraints` table extra to define `CHECK` constraints.
|
|
10
10
|
*/
|
|
11
|
-
type CheckExpression<TScopeColumns extends TableAnyColumn> = Filter<TScopeColumns, false> | Sql;
|
|
11
|
+
type CheckExpression<TScopeColumns extends TableAnyColumn | AnyColumn> = Filter<TScopeColumns, false> | Sql;
|
|
12
12
|
/** A CHECK constraint for a table, storing its name and filter/SQL expression. */
|
|
13
13
|
declare class Check {
|
|
14
14
|
#private;
|
|
@@ -34,7 +34,7 @@ var Check = class {
|
|
|
34
34
|
* ```ts
|
|
35
35
|
* table("public", "projects", { name: varchar({ length: 255 }) }, {
|
|
36
36
|
* checkConstraints: (t, check) => [
|
|
37
|
-
* check("check_projects_name_length", gte(
|
|
37
|
+
* check("check_projects_name_length", gte(length(t.name), 1)),
|
|
38
38
|
* ],
|
|
39
39
|
* });
|
|
40
40
|
* ```
|
package/dist/src/db.d.mts
CHANGED
|
@@ -10,7 +10,6 @@ import { DistinctQuery } from "./query-builders/distinct.mjs";
|
|
|
10
10
|
import { ExistsQuery } from "./query-builders/exists.mjs";
|
|
11
11
|
import { FirstQuery } from "./query-builders/first.mjs";
|
|
12
12
|
import { InsertBuilder } from "./query-builders/insert.mjs";
|
|
13
|
-
import { InsertReturningQuery } from "./query-builders/insert-returning.mjs";
|
|
14
13
|
import { RawQuery } from "./query-builders/raw.mjs";
|
|
15
14
|
import { RelationQueryBuilder } from "./query-builders/rq.mjs";
|
|
16
15
|
import { UpdateBuilder } from "./query-builders/update.mjs";
|
|
@@ -124,13 +123,6 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
|
|
|
124
123
|
*/
|
|
125
124
|
$distinct<TTable extends TTables[keyof TTables], TColumn extends Valueof<TTable["_"]["columns"]>>(table: TTable, column: TColumn): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
|
|
126
125
|
$distinct<TTable extends TTables[keyof TTables], TColumn extends Valueof<TTable["_"]["columns"]>, TWhere extends FilterExpression<Valueof<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
|
|
127
|
-
/**
|
|
128
|
-
* Insert a row and return the inserted row with all columns.
|
|
129
|
-
* @param table The table to insert into
|
|
130
|
-
* @param values The values to insert
|
|
131
|
-
* @returns Promise<T> - the inserted row with all columns including generated values
|
|
132
|
-
*/
|
|
133
|
-
$insertReturning<TTable extends TTables[keyof TTables]>(table: TTable, values: { [colName in keyof TTable["_"]["columns"] as TTable["_"]["columns"][colName]["ValTypeInsert"] extends never ? never : undefined extends TTable["_"]["columns"][colName]["ValTypeInsert"] ? never : colName]: TTable["_"]["columns"][colName]["ValTypeInsert"] } & { [colName in keyof TTable["_"]["columns"] as TTable["_"]["columns"][colName]["ValTypeInsert"] extends never ? never : undefined extends TTable["_"]["columns"][colName]["ValTypeInsert"] ? colName : never]?: Exclude<TTable["_"]["columns"][colName]["ValTypeInsert"], undefined> }): InsertReturningQuery<TTable, { [ColName in keyof TTable["_"]["columns"]]: TTable["_"]["columns"][ColName]["ValTypeSelect"] }>;
|
|
134
126
|
/**
|
|
135
127
|
* Start building a relational query for the specified table.
|
|
136
128
|
*
|
|
@@ -148,7 +140,7 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
|
|
|
148
140
|
* @param table The table to query — must have relations registered via `relations()`.
|
|
149
141
|
* @returns A `RelationQueryBuilder` with `.findMany()` and `.findFirst()` methods.
|
|
150
142
|
*/
|
|
151
|
-
query<UTSchema extends string, UTName extends string, TColumns extends Record<string, AnyColumn>>(table: TableWithColumns<UTSchema, UTName, TColumns>): RelationQueryBuilder<UTSchema, UTName, TColumns, TAllRelations[`"${CamelToSnake<UTSchema>}"."${CamelToSnake<UTName>}"`], TAllRelations>;
|
|
143
|
+
query<UTSchema extends string, UTName extends string, TColumns extends Record<string, AnyColumn>>(table: TableWithColumns<UTSchema, UTName, TColumns>): RelationQueryBuilder<UTSchema, UTName, TColumns, TAllRelations[`"${CamelToSnake<UTSchema>}"."${CamelToSnake<UTName>}"`], TAllRelations, TPrepare>;
|
|
152
144
|
/**
|
|
153
145
|
* Execute a raw SQL query with optional parameter binding and custom result handler.
|
|
154
146
|
* @param query The raw SQL query string with $1, $2, etc. placeholders for parameters
|
package/dist/src/db.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { DistinctQuery } from "./query-builders/distinct.mjs";
|
|
|
7
7
|
import { ExistsQuery } from "./query-builders/exists.mjs";
|
|
8
8
|
import { FirstQuery } from "./query-builders/first.mjs";
|
|
9
9
|
import { InsertBuilder } from "./query-builders/insert.mjs";
|
|
10
|
-
import { InsertReturningQuery } from "./query-builders/insert-returning.mjs";
|
|
11
10
|
import { RawQuery } from "./query-builders/raw.mjs";
|
|
12
11
|
import { RelationQueryBuilder } from "./query-builders/rq.mjs";
|
|
13
12
|
import { SelectBuilder } from "./query-builders/select.mjs";
|
|
@@ -91,15 +90,6 @@ var Base = class {
|
|
|
91
90
|
return new DistinctQuery(table, column, where, this.#getExecutor(), this.$.pre);
|
|
92
91
|
}
|
|
93
92
|
/**
|
|
94
|
-
* Insert a row and return the inserted row with all columns.
|
|
95
|
-
* @param table The table to insert into
|
|
96
|
-
* @param values The values to insert
|
|
97
|
-
* @returns Promise<T> - the inserted row with all columns including generated values
|
|
98
|
-
*/
|
|
99
|
-
$insertReturning(table, values) {
|
|
100
|
-
return new InsertReturningQuery(table, values, this.#getExecutor());
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
93
|
* Start building a relational query for the specified table.
|
|
104
94
|
*
|
|
105
95
|
* Returns a builder with two methods:
|
|
@@ -117,7 +107,7 @@ var Base = class {
|
|
|
117
107
|
* @returns A `RelationQueryBuilder` with `.findMany()` and `.findFirst()` methods.
|
|
118
108
|
*/
|
|
119
109
|
query(table) {
|
|
120
|
-
return new RelationQueryBuilder(table, this.#allRelations[table._.fullName], this.#allRelations, this.#getExecutor());
|
|
110
|
+
return new RelationQueryBuilder(table, this.#allRelations[table._.fullName], this.#allRelations, this.#getExecutor(), this.$.pre);
|
|
121
111
|
}
|
|
122
112
|
/**
|
|
123
113
|
* Execute a raw SQL query with optional parameter binding and custom result handler.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn } from "../table.mjs";
|
|
2
2
|
import { Filter } from "./index.mjs";
|
|
3
3
|
import { Arg, IsArg } from "../query-builders/pre.mjs";
|
|
4
4
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
@@ -13,7 +13,7 @@ type ArrayElement<T> = T extends readonly (infer E)[] ? E extends readonly unkno
|
|
|
13
13
|
* ArrayContains filter: col @> ARRAY[values]
|
|
14
14
|
* Returns true if the array column contains all the specified values.
|
|
15
15
|
*/
|
|
16
|
-
declare class ArrayContainsFilter<TCol extends
|
|
16
|
+
declare class ArrayContainsFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
|
|
17
17
|
readonly left: TCol;
|
|
18
18
|
readonly values: TValues;
|
|
19
19
|
constructor(column: TCol, values: TValues);
|
|
@@ -26,13 +26,13 @@ declare class ArrayContainsFilter<TCol extends TableAnyColumn, TValues extends A
|
|
|
26
26
|
* @example
|
|
27
27
|
* db.from(Posts).select().where(arrayContains(Posts.tags, ['typescript', 'postgres']))
|
|
28
28
|
*/
|
|
29
|
-
declare function arrayContains<TCol extends
|
|
30
|
-
declare function arrayContains<TCol extends
|
|
29
|
+
declare function arrayContains<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
|
|
30
|
+
declare function arrayContains<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
|
|
31
31
|
/**
|
|
32
32
|
* ArrayContainedBy filter: col <@ ARRAY[values]
|
|
33
33
|
* Returns true if the array column is contained by (is a subset of) the specified values.
|
|
34
34
|
*/
|
|
35
|
-
declare class ArrayContainedByFilter<TCol extends
|
|
35
|
+
declare class ArrayContainedByFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
|
|
36
36
|
readonly left: TCol;
|
|
37
37
|
readonly values: TValues;
|
|
38
38
|
constructor(column: TCol, values: TValues);
|
|
@@ -42,13 +42,13 @@ declare class ArrayContainedByFilter<TCol extends TableAnyColumn, TValues extend
|
|
|
42
42
|
* Creates a condition that checks if an array column is contained by the specified values.
|
|
43
43
|
* SQL: column <@ ARRAY[values]
|
|
44
44
|
*/
|
|
45
|
-
declare function arrayContainedBy<TCol extends
|
|
46
|
-
declare function arrayContainedBy<TCol extends
|
|
45
|
+
declare function arrayContainedBy<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
|
|
46
|
+
declare function arrayContainedBy<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
|
|
47
47
|
/**
|
|
48
48
|
* ArrayOverlaps filter: col && ARRAY[values]
|
|
49
49
|
* Returns true if the arrays have any elements in common.
|
|
50
50
|
*/
|
|
51
|
-
declare class ArrayOverlapsFilter<TCol extends
|
|
51
|
+
declare class ArrayOverlapsFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
|
|
52
52
|
readonly left: TCol;
|
|
53
53
|
readonly right: TValues;
|
|
54
54
|
constructor(column: TCol, values: TValues);
|
|
@@ -58,13 +58,13 @@ declare class ArrayOverlapsFilter<TCol extends TableAnyColumn, TValues extends A
|
|
|
58
58
|
* Creates a condition that checks if an array column overlaps with the specified values.
|
|
59
59
|
* SQL: column && ARRAY[values]
|
|
60
60
|
*/
|
|
61
|
-
declare function arrayOverlaps<TCol extends
|
|
62
|
-
declare function arrayOverlaps<TCol extends
|
|
61
|
+
declare function arrayOverlaps<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
|
|
62
|
+
declare function arrayOverlaps<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
|
|
63
63
|
/**
|
|
64
64
|
* ArrayHas filter: value = ANY(col)
|
|
65
65
|
* Returns true if the value exists in the array column.
|
|
66
66
|
*/
|
|
67
|
-
declare class ArrayHasFilter<TCol extends
|
|
67
|
+
declare class ArrayHasFilter<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
|
|
68
68
|
readonly left: TCol;
|
|
69
69
|
readonly value: TRight;
|
|
70
70
|
constructor(column: TCol, value: TRight);
|
|
@@ -74,13 +74,13 @@ declare class ArrayHasFilter<TCol extends TableAnyColumn, TRight extends ArrayEl
|
|
|
74
74
|
* Creates a condition that checks if a value exists in an array column.
|
|
75
75
|
* SQL: value = ANY(column)
|
|
76
76
|
*/
|
|
77
|
-
declare function arrayHas<TCol extends
|
|
78
|
-
declare function arrayHas<TCol extends
|
|
77
|
+
declare function arrayHas<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
|
|
78
|
+
declare function arrayHas<TCol extends AnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
|
|
79
79
|
/**
|
|
80
80
|
* ArrayAll filter: value = ALL(col)
|
|
81
81
|
* Returns true if all elements in the array column equal the value.
|
|
82
82
|
*/
|
|
83
|
-
declare class ArrayAllFilter<TCol extends
|
|
83
|
+
declare class ArrayAllFilter<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
|
|
84
84
|
readonly left: TCol;
|
|
85
85
|
readonly value: TRight;
|
|
86
86
|
constructor(column: TCol, value: TRight);
|
|
@@ -90,7 +90,7 @@ declare class ArrayAllFilter<TCol extends TableAnyColumn, TRight extends ArrayEl
|
|
|
90
90
|
* Creates a condition that checks if all elements in an array column equal a value.
|
|
91
91
|
* SQL: value = ALL(column)
|
|
92
92
|
*/
|
|
93
|
-
declare function arrayAll<TCol extends
|
|
94
|
-
declare function arrayAll<TCol extends
|
|
93
|
+
declare function arrayAll<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
|
|
94
|
+
declare function arrayAll<TCol extends AnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
|
|
95
95
|
//#endregion
|
|
96
96
|
export { arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasicTypes, Or } from "../types.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyColumn } from "../table.mjs";
|
|
3
3
|
import { AnyScalarSqlFn } from "../functions/index.mjs";
|
|
4
4
|
import { SelectQuery } from "../query-builders/select.mjs";
|
|
5
5
|
import { Arg, IsArg } from "../query-builders/pre.mjs";
|
|
@@ -8,7 +8,7 @@ import { Sql } from "../sql.mjs";
|
|
|
8
8
|
|
|
9
9
|
//#region src/filters/index.d.ts
|
|
10
10
|
/** Abstract base class for SQL filter expressions used in `WHERE`/`ON`/`CHECK` clauses. */
|
|
11
|
-
declare abstract class Filter<TColumns extends
|
|
11
|
+
declare abstract class Filter<TColumns extends AnyColumn = AnyColumn, THasArg extends boolean = false> {
|
|
12
12
|
/** Phantom field: the columns this filter is applied to. */
|
|
13
13
|
readonly $Columns: TColumns;
|
|
14
14
|
/** Phantom field: `true` when this filter embeds at least one `Arg` placeholder. */
|
|
@@ -23,12 +23,12 @@ type AnyFilter = Filter<any, any>;
|
|
|
23
23
|
* or a raw `Sql` snippet. When `TArg` is `true`, filters carrying `Arg`
|
|
24
24
|
* placeholders are also accepted (prepared-query context).
|
|
25
25
|
*/
|
|
26
|
-
type FilterExpression<TScopeColumns extends
|
|
27
|
-
type StdCondition = FilterExpression<
|
|
26
|
+
type FilterExpression<TScopeColumns extends AnyColumn, TPrepare extends boolean = false> = Filter<TScopeColumns, TPrepare extends true ? boolean : false> | Sql;
|
|
27
|
+
type StdCondition = FilterExpression<AnyColumn>;
|
|
28
28
|
type HasArg<T> = T extends {
|
|
29
29
|
$HasArg: true;
|
|
30
30
|
} ? true : false;
|
|
31
|
-
declare class ComparisonLeftIsColumn<TLeft extends
|
|
31
|
+
declare class ComparisonLeftIsColumn<TLeft extends AnyColumn, TOp extends string, TRight extends TLeft["ValType"] | Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn> extends Filter<TLeft, Or<IsArg<TRight>, HasArg<TRight>>> {
|
|
32
32
|
readonly left: TLeft;
|
|
33
33
|
readonly op: TOp;
|
|
34
34
|
readonly right: TRight;
|
|
@@ -42,57 +42,57 @@ declare class ComparisonLeftIsSqlFn<TLeft extends AnyScalarSqlFn, TOp extends st
|
|
|
42
42
|
constructor(field: TLeft, op: TOp, right: TRight);
|
|
43
43
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
44
44
|
}
|
|
45
|
-
declare function eq<TLeft extends
|
|
46
|
-
declare function eq<TLeft extends
|
|
45
|
+
declare function eq<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "=", TRight>;
|
|
46
|
+
declare function eq<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "=", TRight>;
|
|
47
47
|
declare function eq<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
|
|
48
48
|
declare function eq<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
|
|
49
|
-
declare function ne<TLeft extends
|
|
50
|
-
declare function ne<TLeft extends
|
|
49
|
+
declare function ne<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "!=", TRight>;
|
|
50
|
+
declare function ne<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "!=", TRight>;
|
|
51
51
|
declare function ne<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
|
|
52
52
|
declare function ne<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
|
|
53
|
-
declare function gt<TLeft extends
|
|
54
|
-
declare function gt<TLeft extends
|
|
53
|
+
declare function gt<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">", TRight>;
|
|
54
|
+
declare function gt<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">", TRight>;
|
|
55
55
|
declare function gt<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
|
|
56
56
|
declare function gt<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
|
|
57
|
-
declare function gte<TLeft extends
|
|
58
|
-
declare function gte<TLeft extends
|
|
57
|
+
declare function gte<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">=", TRight>;
|
|
58
|
+
declare function gte<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">=", TRight>;
|
|
59
59
|
declare function gte<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
|
|
60
60
|
declare function gte<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
|
|
61
|
-
declare function lt<TLeft extends
|
|
62
|
-
declare function lt<TLeft extends
|
|
61
|
+
declare function lt<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<", TRight>;
|
|
62
|
+
declare function lt<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<", TRight>;
|
|
63
63
|
declare function lt<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
|
|
64
64
|
declare function lt<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
|
|
65
|
-
declare function lte<TLeft extends
|
|
66
|
-
declare function lte<TLeft extends
|
|
65
|
+
declare function lte<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<=", TRight>;
|
|
66
|
+
declare function lte<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<=", TRight>;
|
|
67
67
|
declare function lte<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
|
|
68
68
|
declare function lte<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
|
|
69
|
-
declare class IsNullCondition<TCol extends
|
|
69
|
+
declare class IsNullCondition<TCol extends AnyColumn> extends Filter<TCol, false> {
|
|
70
70
|
readonly field: TCol;
|
|
71
71
|
constructor(field: TCol);
|
|
72
72
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
73
73
|
}
|
|
74
|
-
declare function isNull<TCol extends
|
|
75
|
-
declare class IsNotNullCondition<TCol extends
|
|
74
|
+
declare function isNull<TCol extends AnyColumn>(field: TCol): IsNullCondition<TCol>;
|
|
75
|
+
declare class IsNotNullCondition<TCol extends AnyColumn> extends Filter<TCol, false> {
|
|
76
76
|
readonly field: TCol;
|
|
77
77
|
constructor(field: TCol);
|
|
78
78
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
79
79
|
}
|
|
80
|
-
declare function isNotNull<TCol extends
|
|
80
|
+
declare function isNotNull<TCol extends AnyColumn>(field: TCol): IsNotNullCondition<TCol>;
|
|
81
81
|
type InSelectQuery<TArg extends boolean, TReturn> = SelectQuery<any, any, any, any, any, TArg, any, any, Record<string, TReturn>[]>;
|
|
82
|
-
declare class InCondition<TCol extends
|
|
82
|
+
declare class InCondition<TCol extends AnyColumn, TArg extends boolean> extends Filter<TCol, TArg> {
|
|
83
83
|
readonly field: TCol;
|
|
84
84
|
readonly values: TCol["ValType"][] | InSelectQuery<TArg, TCol["ValType"]>;
|
|
85
85
|
constructor(field: TCol, values: TCol["ValType"][] | InSelectQuery<TArg, TCol["ValType"]>);
|
|
86
86
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
87
87
|
}
|
|
88
|
-
declare function isIn<TCol extends
|
|
89
|
-
declare class NotInCondition<TCol extends
|
|
88
|
+
declare function isIn<TCol extends AnyColumn>(field: TCol, values: TCol["ValType"][] | InSelectQuery<boolean, TCol["ValType"]>): InCondition<TCol, false>;
|
|
89
|
+
declare class NotInCondition<TCol extends AnyColumn> extends Filter<TCol, false> {
|
|
90
90
|
readonly field: TCol;
|
|
91
91
|
readonly values: TCol["ValType"][];
|
|
92
92
|
constructor(field: TCol, values: TCol["ValType"][]);
|
|
93
93
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
94
94
|
}
|
|
95
|
-
declare function notIn<TCol extends
|
|
95
|
+
declare function notIn<TCol extends AnyColumn>(field: TCol, values: TCol["ValType"][]): NotInCondition<TCol>;
|
|
96
96
|
declare class AndCondition<TConditions extends (AnyFilter | Sql)[]> extends Filter<ExtractCols<TConditions[number]>, HasArgOf<TConditions>> {
|
|
97
97
|
readonly conditions: TConditions;
|
|
98
98
|
constructor(...conditions: TConditions);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Or } from "../types.mjs";
|
|
2
|
-
import { TableAnyColumn } from "../table.mjs";
|
|
3
2
|
import { Filter } from "./index.mjs";
|
|
4
3
|
import { PointColumn } from "../columns/postgis/geography/point.mjs";
|
|
5
4
|
import { Arg, IsArg } from "../query-builders/pre.mjs";
|
|
@@ -7,7 +6,7 @@ import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
|
7
6
|
|
|
8
7
|
//#region src/filters/postgis.d.ts
|
|
9
8
|
/** Constrains `TCol` to geography point columns only. */
|
|
10
|
-
type GeographyPointCol =
|
|
9
|
+
type GeographyPointCol = PointColumn<any>;
|
|
11
10
|
/**
|
|
12
11
|
* Spatial filter: `ST_DWithin(col, ST_SetSRID(ST_MakePoint(lon, lat), srid), radius)`
|
|
13
12
|
* Returns true if the geometry column is within `radius` meters of the given point.
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Column } from "../columns/common.mjs";
|
|
2
|
-
import { TableAnyColumn } from "../table.mjs";
|
|
3
2
|
import { Filter } from "./index.mjs";
|
|
4
3
|
import { Arg, IsArg } from "../query-builders/pre.mjs";
|
|
5
4
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
6
5
|
|
|
7
6
|
//#region src/filters/string.d.ts
|
|
8
|
-
type TextScalarTableColumn =
|
|
7
|
+
type TextScalarTableColumn = Column<any, any, "text"> & {
|
|
9
8
|
config: {
|
|
10
9
|
dimension?: undefined;
|
|
11
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn } from "../table.mjs";
|
|
2
2
|
import { AnyScalarSqlFn, ExprColumns, HasArg, SqlFn } from "./index.mjs";
|
|
3
3
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
4
4
|
|
|
@@ -8,8 +8,8 @@ import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
|
8
8
|
* Restricts nested expressions to scalars, preventing illegal
|
|
9
9
|
* aggregate-in-aggregate nesting at the type level.
|
|
10
10
|
*/
|
|
11
|
-
type AggregateInput =
|
|
12
|
-
type NumericAggregateInput = (
|
|
11
|
+
type AggregateInput = AnyColumn | AnyScalarSqlFn;
|
|
12
|
+
type NumericAggregateInput = (AnyColumn & {
|
|
13
13
|
$: {
|
|
14
14
|
PgType: "numeric";
|
|
15
15
|
};
|
|
@@ -32,7 +32,7 @@ type NumericAggregateInput = (TableAnyColumn & {
|
|
|
32
32
|
*
|
|
33
33
|
* @template TExpr - The table column to count.
|
|
34
34
|
*/
|
|
35
|
-
declare class CountFn<TExpr extends
|
|
35
|
+
declare class CountFn<TExpr extends AnyColumn> extends SqlFn<TExpr, false, "aggregate", "numeric", number> {
|
|
36
36
|
private readonly expr;
|
|
37
37
|
readonly isAggregate = true;
|
|
38
38
|
constructor(expr: TExpr);
|
|
@@ -62,7 +62,7 @@ declare class CountStarFn extends SqlFn<never, false, "aggregate", "numeric", nu
|
|
|
62
62
|
*
|
|
63
63
|
* @template TExpr - The table column to count distinct values from.
|
|
64
64
|
*/
|
|
65
|
-
declare class CountDistinctFn<TExpr extends
|
|
65
|
+
declare class CountDistinctFn<TExpr extends AnyColumn> extends SqlFn<TExpr, false, "aggregate", "numeric", number> {
|
|
66
66
|
private readonly expr;
|
|
67
67
|
readonly isAggregate = true;
|
|
68
68
|
constructor(expr: TExpr);
|
|
@@ -84,7 +84,7 @@ declare function count(star: "*"): CountStarFn;
|
|
|
84
84
|
* @example
|
|
85
85
|
* db.from(Orders).select({ total: count(Orders.id) });
|
|
86
86
|
*/
|
|
87
|
-
declare function count<TExpr extends
|
|
87
|
+
declare function count<TExpr extends AnyColumn>(expr: TExpr): CountFn<TExpr>;
|
|
88
88
|
/**
|
|
89
89
|
* Creates a SQL aggregate expression `count(DISTINCT col)` that counts distinct non-null values.
|
|
90
90
|
*
|
|
@@ -94,7 +94,7 @@ declare function count<TExpr extends TableAnyColumn>(expr: TExpr): CountFn<TExpr
|
|
|
94
94
|
* @example
|
|
95
95
|
* db.from(Orders).select({ uniqueUsers: countDistinct(Orders.userId) });
|
|
96
96
|
*/
|
|
97
|
-
declare function countDistinct<TExpr extends
|
|
97
|
+
declare function countDistinct<TExpr extends AnyColumn>(expr: TExpr): CountDistinctFn<TExpr>;
|
|
98
98
|
/**
|
|
99
99
|
* SQL aggregate expression: `sum(col)`
|
|
100
100
|
* Returns the sum of all non-null values in the column, or `null` if no rows match.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn } from "../table.mjs";
|
|
2
2
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
3
3
|
import { Sql } from "../sql.mjs";
|
|
4
4
|
|
|
@@ -24,7 +24,7 @@ import { Sql } from "../sql.mjs";
|
|
|
24
24
|
* enabling type-safe nested function calls (e.g. `lower(trim(col))`).
|
|
25
25
|
* @template TTsType - The TypeScript type this expression evaluates to.
|
|
26
26
|
*/
|
|
27
|
-
declare abstract class SqlFn<TColumn extends
|
|
27
|
+
declare abstract class SqlFn<TColumn extends AnyColumn, THasArg extends boolean = false, TFnType extends "aggregate" | "scalar" = "aggregate" | "scalar", TPgType extends string = string, TTsType = any> {
|
|
28
28
|
readonly $: {
|
|
29
29
|
kind: "sqlFn";
|
|
30
30
|
TsType: TTsType;
|
|
@@ -75,7 +75,7 @@ type ExprColumns<TExpr> = TExpr extends {
|
|
|
75
75
|
$: {
|
|
76
76
|
kind: "sqlFn";
|
|
77
77
|
};
|
|
78
|
-
$Columns: infer TCol extends
|
|
78
|
+
$Columns: infer TCol extends AnyColumn;
|
|
79
79
|
} ? TCol : TExpr extends {
|
|
80
80
|
$: {
|
|
81
81
|
kind: "column";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Or } from "../types.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyScalarColumn } from "../table.mjs";
|
|
3
3
|
import { AnySqlFn, ExprColumns, HasArg, SqlFn } from "./index.mjs";
|
|
4
4
|
import { Arg, IsArg } from "../query-builders/pre.mjs";
|
|
5
5
|
import { Query, QueryContext } from "../query-builders/query.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/functions/numeric.d.ts
|
|
8
|
-
declare class AbsFn<TExpr extends (
|
|
8
|
+
declare class AbsFn<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
9
9
|
$: {
|
|
10
10
|
PgType: "numeric";
|
|
11
11
|
};
|
|
@@ -15,12 +15,12 @@ declare class AbsFn<TExpr extends (AnyScalarTableColumn | AnySqlFn) & {
|
|
|
15
15
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
16
16
|
}
|
|
17
17
|
/** Returns the absolute value of a numeric expression. */
|
|
18
|
-
declare function abs<TExpr extends (
|
|
18
|
+
declare function abs<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
19
19
|
$: {
|
|
20
20
|
PgType: "numeric";
|
|
21
21
|
};
|
|
22
22
|
}>(expr: TExpr): AbsFn<TExpr>;
|
|
23
|
-
declare class ModFn<TExpr extends (
|
|
23
|
+
declare class ModFn<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
24
24
|
$: {
|
|
25
25
|
PgType: "numeric";
|
|
26
26
|
};
|
|
@@ -31,12 +31,12 @@ declare class ModFn<TExpr extends (AnyScalarTableColumn | AnySqlFn) & {
|
|
|
31
31
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
32
32
|
}
|
|
33
33
|
/** Returns the remainder of `expr` divided by `n`. */
|
|
34
|
-
declare function mod<TExpr extends (
|
|
34
|
+
declare function mod<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
35
35
|
$: {
|
|
36
36
|
PgType: "numeric";
|
|
37
37
|
};
|
|
38
38
|
}, TN extends number | Arg<number>>(expr: TExpr, n: TN): ModFn<TExpr, TN>;
|
|
39
|
-
declare class RoundFn<TExpr extends (
|
|
39
|
+
declare class RoundFn<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
40
40
|
$: {
|
|
41
41
|
PgType: "numeric";
|
|
42
42
|
};
|
|
@@ -47,12 +47,12 @@ declare class RoundFn<TExpr extends (AnyScalarTableColumn | AnySqlFn) & {
|
|
|
47
47
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
48
48
|
}
|
|
49
49
|
/** Rounds a numeric expression to the nearest integer, or to `decimals` decimal places. */
|
|
50
|
-
declare function round<TExpr extends (
|
|
50
|
+
declare function round<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
51
51
|
$: {
|
|
52
52
|
PgType: "numeric";
|
|
53
53
|
};
|
|
54
54
|
}, TDecimals extends number | Arg<number> | undefined = undefined>(expr: TExpr, decimals?: TDecimals): RoundFn<TExpr, TDecimals>;
|
|
55
|
-
declare class CeilFn<TExpr extends (
|
|
55
|
+
declare class CeilFn<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
56
56
|
$: {
|
|
57
57
|
PgType: "numeric";
|
|
58
58
|
};
|
|
@@ -62,12 +62,12 @@ declare class CeilFn<TExpr extends (AnyScalarTableColumn | AnySqlFn) & {
|
|
|
62
62
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
63
63
|
}
|
|
64
64
|
/** Returns the smallest integer greater than or equal to the numeric expression. */
|
|
65
|
-
declare function ceil<TExpr extends (
|
|
65
|
+
declare function ceil<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
66
66
|
$: {
|
|
67
67
|
PgType: "numeric";
|
|
68
68
|
};
|
|
69
69
|
}>(expr: TExpr): CeilFn<TExpr>;
|
|
70
|
-
declare class FloorFn<TExpr extends (
|
|
70
|
+
declare class FloorFn<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
71
71
|
$: {
|
|
72
72
|
PgType: "numeric";
|
|
73
73
|
};
|
|
@@ -77,7 +77,7 @@ declare class FloorFn<TExpr extends (AnyScalarTableColumn | AnySqlFn) & {
|
|
|
77
77
|
toQuery(query: Query, ctx?: QueryContext): void;
|
|
78
78
|
}
|
|
79
79
|
/** Returns the largest integer less than or equal to the numeric expression. */
|
|
80
|
-
declare function floor<TExpr extends (
|
|
80
|
+
declare function floor<TExpr extends (AnyScalarColumn | AnySqlFn) & {
|
|
81
81
|
$: {
|
|
82
82
|
PgType: "numeric";
|
|
83
83
|
};
|