kysely 0.27.0 → 0.27.1
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/README.md +2 -2
- package/dist/cjs/dialect/mssql/mssql-introspector.js +8 -6
- package/dist/cjs/expression/expression-wrapper.d.ts +13 -3
- package/dist/cjs/expression/expression-wrapper.js +12 -0
- package/dist/cjs/operation-node/insert-query-node.d.ts +1 -0
- package/dist/cjs/operation-node/limit-node.d.ts +2 -3
- package/dist/cjs/operation-node/limit-node.js +1 -2
- package/dist/cjs/operation-node/offset-node.d.ts +2 -3
- package/dist/cjs/operation-node/offset-node.js +1 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -0
- package/dist/cjs/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/cjs/operation-node/select-modifier-node.js +2 -1
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +17 -0
- package/dist/cjs/query-builder/aggregate-function-builder.js +21 -0
- package/dist/cjs/query-builder/case-builder.d.ts +2 -2
- package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -4
- package/dist/cjs/query-builder/delete-query-builder.js +4 -3
- package/dist/cjs/query-builder/function-module.d.ts +1 -1
- package/dist/cjs/query-builder/insert-query-builder.d.ts +7 -3
- package/dist/cjs/query-builder/insert-query-builder.js +13 -2
- package/dist/cjs/query-builder/json-path-builder.d.ts +2 -1
- package/dist/cjs/query-builder/json-path-builder.js +3 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +11 -9
- package/dist/cjs/query-builder/select-query-builder.js +12 -10
- package/dist/cjs/query-builder/update-query-builder.d.ts +3 -3
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +8 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +11 -1
- package/dist/cjs/raw-builder/raw-builder.js +3 -0
- package/dist/cjs/raw-builder/sql.js +9 -2
- package/dist/cjs/util/object-utils.d.ts +1 -1
- package/dist/cjs/util/object-utils.js +1 -1
- package/dist/esm/dialect/mssql/mssql-introspector.js +8 -6
- package/dist/esm/expression/expression-wrapper.d.ts +13 -3
- package/dist/esm/expression/expression-wrapper.js +12 -0
- package/dist/esm/operation-node/insert-query-node.d.ts +1 -0
- package/dist/esm/operation-node/limit-node.d.ts +2 -3
- package/dist/esm/operation-node/limit-node.js +1 -2
- package/dist/esm/operation-node/offset-node.d.ts +2 -3
- package/dist/esm/operation-node/offset-node.js +1 -2
- package/dist/esm/operation-node/operation-node-transformer.js +2 -0
- package/dist/esm/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/esm/operation-node/select-modifier-node.js +2 -1
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +17 -0
- package/dist/esm/query-builder/aggregate-function-builder.js +21 -0
- package/dist/esm/query-builder/case-builder.d.ts +2 -2
- package/dist/esm/query-builder/delete-query-builder.d.ts +5 -4
- package/dist/esm/query-builder/delete-query-builder.js +4 -3
- package/dist/esm/query-builder/function-module.d.ts +1 -1
- package/dist/esm/query-builder/insert-query-builder.d.ts +7 -3
- package/dist/esm/query-builder/insert-query-builder.js +13 -2
- package/dist/esm/query-builder/json-path-builder.d.ts +2 -1
- package/dist/esm/query-builder/json-path-builder.js +3 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +11 -9
- package/dist/esm/query-builder/select-query-builder.js +13 -11
- package/dist/esm/query-builder/update-query-builder.d.ts +3 -3
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +8 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +11 -1
- package/dist/esm/raw-builder/raw-builder.js +3 -0
- package/dist/esm/raw-builder/sql.js +9 -2
- package/dist/esm/util/object-utils.d.ts +1 -1
- package/dist/esm/util/object-utils.js +1 -1
- package/package.json +5 -11
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# [Kysely](https://kysely.dev)
|
|
14
14
|
|
|
15
15
|
Kysely (pronounce “Key-Seh-Lee”) is a type-safe and autocompletion-friendly typescript SQL query builder.
|
|
16
|
-
Inspired by [knex](http://knexjs.org/). Mainly developed for [node.js](https://nodejs.org/en/) but also
|
|
16
|
+
Inspired by [knex](http://knexjs.org/). Mainly developed for [node.js](https://nodejs.org/en/) but also
|
|
17
17
|
runs on all other javascript environments like [deno](https://deno.land/).
|
|
18
18
|
|
|
19
19
|

|
|
@@ -32,7 +32,7 @@ hatches for these situations. See the [sql template tag](https://kysely-org.gith
|
|
|
32
32
|
and the [DynamicModule](https://kysely-org.github.io/kysely-apidoc/classes/DynamicModule.html#ref) for more info.
|
|
33
33
|
|
|
34
34
|
All API documentation is written in the typing files and you can simply hover over the module, class
|
|
35
|
-
or method you're using to see it in your IDE. The same documentation is also hosted [here](https://github.
|
|
35
|
+
or method you're using to see it in your IDE. The same documentation is also hosted [here](https://kysely-org.github.io/kysely-apidoc/).
|
|
36
36
|
|
|
37
37
|
If you start using Kysely and can't find something you'd want to use, please open an issue or join our
|
|
38
38
|
[discord server](https://discord.gg/xyBJ3GwvAm).
|
|
@@ -67,12 +67,14 @@ class MssqlIntrospector {
|
|
|
67
67
|
const tableDictionary = {};
|
|
68
68
|
for (const rawColumn of rawColumns) {
|
|
69
69
|
const key = `${rawColumn.table_schema_name}.${rawColumn.table_name}`;
|
|
70
|
-
const table = (tableDictionary[key]
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const table = (tableDictionary[key] =
|
|
71
|
+
tableDictionary[key] ||
|
|
72
|
+
(0, object_utils_js_1.freeze)({
|
|
73
|
+
columns: [],
|
|
74
|
+
isView: rawColumn.table_type === 'V ',
|
|
75
|
+
name: rawColumn.table_name,
|
|
76
|
+
schema: rawColumn.table_schema_name ?? undefined,
|
|
77
|
+
}));
|
|
76
78
|
table.columns.push((0, object_utils_js_1.freeze)({
|
|
77
79
|
dataType: rawColumn.type_name,
|
|
78
80
|
dataTypeSchema: rawColumn.type_schema_name ?? undefined,
|
|
@@ -243,7 +243,17 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Al
|
|
|
243
243
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
244
244
|
* returns a copy of this `ExpressionWrapper` with a new output type.
|
|
245
245
|
*/
|
|
246
|
-
$castTo<
|
|
246
|
+
$castTo<C>(): ExpressionWrapper<DB, TB, C>;
|
|
247
|
+
/**
|
|
248
|
+
* Omit null from the expression's type.
|
|
249
|
+
*
|
|
250
|
+
* This function can be useful in cases where you know an expression can't be
|
|
251
|
+
* null, but Kysely is unable to infer it.
|
|
252
|
+
*
|
|
253
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
254
|
+
* returns a copy of `this` with a new output type.
|
|
255
|
+
*/
|
|
256
|
+
$notNull(): ExpressionWrapper<DB, TB, Exclude<T, null>>;
|
|
247
257
|
/**
|
|
248
258
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
249
259
|
*
|
|
@@ -397,7 +407,7 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
|
|
|
397
407
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
398
408
|
* returns a copy of this `OrWrapper` with a new output type.
|
|
399
409
|
*/
|
|
400
|
-
$castTo<
|
|
410
|
+
$castTo<C extends SqlBool>(): OrWrapper<DB, TB, C>;
|
|
401
411
|
/**
|
|
402
412
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
403
413
|
*
|
|
@@ -533,7 +543,7 @@ export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> impl
|
|
|
533
543
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
534
544
|
* returns a copy of this `AndWrapper` with a new output type.
|
|
535
545
|
*/
|
|
536
|
-
$castTo<
|
|
546
|
+
$castTo<C extends SqlBool>(): AndWrapper<DB, TB, C>;
|
|
537
547
|
/**
|
|
538
548
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
539
549
|
*
|
|
@@ -35,6 +35,18 @@ class ExpressionWrapper {
|
|
|
35
35
|
$castTo() {
|
|
36
36
|
return new ExpressionWrapper(this.#node);
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Omit null from the expression's type.
|
|
40
|
+
*
|
|
41
|
+
* This function can be useful in cases where you know an expression can't be
|
|
42
|
+
* null, but Kysely is unable to infer it.
|
|
43
|
+
*
|
|
44
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
45
|
+
* returns a copy of `this` with a new output type.
|
|
46
|
+
*/
|
|
47
|
+
$notNull() {
|
|
48
|
+
return new ExpressionWrapper(this.#node);
|
|
49
|
+
}
|
|
38
50
|
toOperationNode() {
|
|
39
51
|
return this.#node;
|
|
40
52
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
import { ValueNode } from './value-node.js';
|
|
3
2
|
export interface LimitNode extends OperationNode {
|
|
4
3
|
readonly kind: 'LimitNode';
|
|
5
|
-
readonly limit:
|
|
4
|
+
readonly limit: OperationNode;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*/
|
|
10
9
|
export declare const LimitNode: Readonly<{
|
|
11
10
|
is(node: OperationNode): node is LimitNode;
|
|
12
|
-
create(limit:
|
|
11
|
+
create(limit: OperationNode): LimitNode;
|
|
13
12
|
}>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LimitNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const value_node_js_1 = require("./value-node.js");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -13,7 +12,7 @@ exports.LimitNode = (0, object_utils_js_1.freeze)({
|
|
|
13
12
|
create(limit) {
|
|
14
13
|
return (0, object_utils_js_1.freeze)({
|
|
15
14
|
kind: 'LimitNode',
|
|
16
|
-
limit
|
|
15
|
+
limit,
|
|
17
16
|
});
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
import { ValueNode } from './value-node.js';
|
|
3
2
|
export interface OffsetNode extends OperationNode {
|
|
4
3
|
readonly kind: 'OffsetNode';
|
|
5
|
-
readonly offset:
|
|
4
|
+
readonly offset: OperationNode;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*/
|
|
10
9
|
export declare const OffsetNode: Readonly<{
|
|
11
10
|
is(node: OperationNode): node is OffsetNode;
|
|
12
|
-
create(offset:
|
|
11
|
+
create(offset: OperationNode): OffsetNode;
|
|
13
12
|
}>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OffsetNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const value_node_js_1 = require("./value-node.js");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -13,7 +12,7 @@ exports.OffsetNode = (0, object_utils_js_1.freeze)({
|
|
|
13
12
|
create(offset) {
|
|
14
13
|
return (0, object_utils_js_1.freeze)({
|
|
15
14
|
kind: 'OffsetNode',
|
|
16
|
-
offset
|
|
15
|
+
offset,
|
|
17
16
|
});
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -259,6 +259,7 @@ class OperationNodeTransformer {
|
|
|
259
259
|
ignore: node.ignore,
|
|
260
260
|
replace: node.replace,
|
|
261
261
|
explain: this.transformNode(node.explain),
|
|
262
|
+
defaultValues: node.defaultValues,
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
265
|
transformValues(node) {
|
|
@@ -635,6 +636,7 @@ class OperationNodeTransformer {
|
|
|
635
636
|
kind: 'SelectModifierNode',
|
|
636
637
|
modifier: node.modifier,
|
|
637
638
|
rawModifier: this.transformNode(node.rawModifier),
|
|
639
|
+
of: this.transformNodeList(node.of),
|
|
638
640
|
});
|
|
639
641
|
}
|
|
640
642
|
transformCreateType(node) {
|
|
@@ -4,12 +4,13 @@ export interface SelectModifierNode extends OperationNode {
|
|
|
4
4
|
readonly kind: 'SelectModifierNode';
|
|
5
5
|
readonly modifier?: SelectModifier;
|
|
6
6
|
readonly rawModifier?: OperationNode;
|
|
7
|
+
readonly of?: ReadonlyArray<OperationNode>;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
12
|
export declare const SelectModifierNode: Readonly<{
|
|
12
13
|
is(node: OperationNode): node is SelectModifierNode;
|
|
13
|
-
create(modifier: SelectModifier): SelectModifierNode;
|
|
14
|
+
create(modifier: SelectModifier, of?: ReadonlyArray<OperationNode>): SelectModifierNode;
|
|
14
15
|
createWithExpression(modifier: OperationNode): SelectModifierNode;
|
|
15
16
|
}>;
|
|
@@ -9,10 +9,11 @@ exports.SelectModifierNode = (0, object_utils_js_1.freeze)({
|
|
|
9
9
|
is(node) {
|
|
10
10
|
return node.kind === 'SelectModifierNode';
|
|
11
11
|
},
|
|
12
|
-
create(modifier) {
|
|
12
|
+
create(modifier, of) {
|
|
13
13
|
return (0, object_utils_js_1.freeze)({
|
|
14
14
|
kind: 'SelectModifierNode',
|
|
15
15
|
modifier,
|
|
16
|
+
of,
|
|
16
17
|
});
|
|
17
18
|
},
|
|
18
19
|
createWithExpression(modifier) {
|
|
@@ -199,6 +199,23 @@ export declare class AggregateFunctionBuilder<DB, TB extends keyof DB, O = unkno
|
|
|
199
199
|
* what the provided function returns.
|
|
200
200
|
*/
|
|
201
201
|
$call<T>(func: (qb: this) => T): T;
|
|
202
|
+
/**
|
|
203
|
+
* Casts the expression to the given type.
|
|
204
|
+
*
|
|
205
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
206
|
+
* returns a copy of this `AggregateFunctionBuilder` with a new output type.
|
|
207
|
+
*/
|
|
208
|
+
$castTo<C>(): AggregateFunctionBuilder<DB, TB, C>;
|
|
209
|
+
/**
|
|
210
|
+
* Omit null from the expression's type.
|
|
211
|
+
*
|
|
212
|
+
* This function can be useful in cases where you know an expression can't be
|
|
213
|
+
* null, but Kysely is unable to infer it.
|
|
214
|
+
*
|
|
215
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
216
|
+
* returns a copy of `this` with a new output type.
|
|
217
|
+
*/
|
|
218
|
+
$notNull(): AggregateFunctionBuilder<DB, TB, Exclude<O, null>>;
|
|
202
219
|
/**
|
|
203
220
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
204
221
|
*
|
|
@@ -172,6 +172,27 @@ class AggregateFunctionBuilder {
|
|
|
172
172
|
$call(func) {
|
|
173
173
|
return func(this);
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Casts the expression to the given type.
|
|
177
|
+
*
|
|
178
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
179
|
+
* returns a copy of this `AggregateFunctionBuilder` with a new output type.
|
|
180
|
+
*/
|
|
181
|
+
$castTo() {
|
|
182
|
+
return new AggregateFunctionBuilder(this.#props);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Omit null from the expression's type.
|
|
186
|
+
*
|
|
187
|
+
* This function can be useful in cases where you know an expression can't be
|
|
188
|
+
* null, but Kysely is unable to infer it.
|
|
189
|
+
*
|
|
190
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
191
|
+
* returns a copy of `this` with a new output type.
|
|
192
|
+
*/
|
|
193
|
+
$notNull() {
|
|
194
|
+
return new AggregateFunctionBuilder(this.#props);
|
|
195
|
+
}
|
|
175
196
|
toOperationNode() {
|
|
176
197
|
return this.#props.aggregateFunctionNode;
|
|
177
198
|
}
|
|
@@ -29,7 +29,7 @@ export declare class CaseThenBuilder<DB, TB extends keyof DB, W, O> {
|
|
|
29
29
|
* A `then` call can be followed by {@link Whenable.when}, {@link CaseWhenBuilder.else},
|
|
30
30
|
* {@link CaseWhenBuilder.end} or {@link CaseWhenBuilder.endCase} call.
|
|
31
31
|
*/
|
|
32
|
-
then<E extends Expression<
|
|
32
|
+
then<E extends Expression<unknown>>(expression: E): CaseWhenBuilder<DB, TB, W, O | ExtractTypeFromValueExpression<E>>;
|
|
33
33
|
then<V>(value: V): CaseWhenBuilder<DB, TB, W, O | V>;
|
|
34
34
|
}
|
|
35
35
|
export declare class CaseWhenBuilder<DB, TB extends keyof DB, W, O> implements Whenable<DB, TB, W, O>, Endable<DB, TB, O | null> {
|
|
@@ -48,7 +48,7 @@ export declare class CaseWhenBuilder<DB, TB extends keyof DB, W, O> implements W
|
|
|
48
48
|
*
|
|
49
49
|
* An `else` call must be followed by an {@link Endable.end} or {@link Endable.endCase} call.
|
|
50
50
|
*/
|
|
51
|
-
else<
|
|
51
|
+
else<E extends Expression<unknown>>(expression: E): CaseEndBuilder<DB, TB, O | ExtractTypeFromValueExpression<E>>;
|
|
52
52
|
else<V>(value: V): CaseEndBuilder<DB, TB, O | V>;
|
|
53
53
|
/**
|
|
54
54
|
* Adds an `end` keyword to the case operator.
|
|
@@ -23,6 +23,7 @@ import { ComparisonOperatorExpression, OperandValueExpressionOrList } from '../p
|
|
|
23
23
|
import { KyselyTypeError } from '../util/type-error.js';
|
|
24
24
|
import { Streamable } from '../util/streamable.js';
|
|
25
25
|
import { ExpressionOrFactory } from '../parser/expression-parser.js';
|
|
26
|
+
import { ValueExpression } from '../parser/value-parser.js';
|
|
26
27
|
export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable<O>, Explainable, Streamable<O> {
|
|
27
28
|
#private;
|
|
28
29
|
constructor(props: DeleteQueryBuilderProps);
|
|
@@ -814,7 +815,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
814
815
|
* .execute()
|
|
815
816
|
* ```
|
|
816
817
|
*/
|
|
817
|
-
limit(limit: number): DeleteQueryBuilder<DB, TB, O>;
|
|
818
|
+
limit(limit: ValueExpression<DB, TB, number>): DeleteQueryBuilder<DB, TB, O>;
|
|
818
819
|
/**
|
|
819
820
|
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
820
821
|
* what the provided function returns.
|
|
@@ -877,10 +878,10 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
877
878
|
/**
|
|
878
879
|
* Change the output type of the query.
|
|
879
880
|
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
881
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
882
|
+
* returns a copy of this `DeleteQueryBuilder` with a new output type.
|
|
882
883
|
*/
|
|
883
|
-
$castTo<
|
|
884
|
+
$castTo<C>(): DeleteQueryBuilder<DB, TB, C>;
|
|
884
885
|
/**
|
|
885
886
|
* Narrows (parts of) the output type of the query.
|
|
886
887
|
*
|
|
@@ -13,6 +13,7 @@ const delete_query_node_js_1 = require("../operation-node/delete-query-node.js")
|
|
|
13
13
|
const limit_node_js_1 = require("../operation-node/limit-node.js");
|
|
14
14
|
const order_by_parser_js_1 = require("../parser/order-by-parser.js");
|
|
15
15
|
const binary_operation_parser_js_1 = require("../parser/binary-operation-parser.js");
|
|
16
|
+
const value_parser_js_1 = require("../parser/value-parser.js");
|
|
16
17
|
class DeleteQueryBuilder {
|
|
17
18
|
#props;
|
|
18
19
|
constructor(props) {
|
|
@@ -139,7 +140,7 @@ class DeleteQueryBuilder {
|
|
|
139
140
|
limit(limit) {
|
|
140
141
|
return new DeleteQueryBuilder({
|
|
141
142
|
...this.#props,
|
|
142
|
-
queryNode: delete_query_node_js_1.DeleteQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create(limit)),
|
|
143
|
+
queryNode: delete_query_node_js_1.DeleteQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create((0, value_parser_js_1.parseValueExpression)(limit))),
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
@@ -213,8 +214,8 @@ class DeleteQueryBuilder {
|
|
|
213
214
|
/**
|
|
214
215
|
* Change the output type of the query.
|
|
215
216
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
217
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
218
|
+
* returns a copy of this `DeleteQueryBuilder` with a new output type.
|
|
218
219
|
*/
|
|
219
220
|
$castTo() {
|
|
220
221
|
return new DeleteQueryBuilder(this.#props);
|
|
@@ -138,7 +138,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
|
|
|
138
138
|
* from "person"
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
|
-
agg<O, RE extends ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
|
|
141
|
+
agg<O, RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
|
|
142
142
|
/**
|
|
143
143
|
* Calls the `avg` function for the column or expression given as the argument.
|
|
144
144
|
*
|
|
@@ -240,6 +240,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
240
240
|
* ```
|
|
241
241
|
*/
|
|
242
242
|
expression(expression: ExpressionOrFactory<DB, TB, any>): InsertQueryBuilder<DB, TB, O>;
|
|
243
|
+
/**
|
|
244
|
+
* Creates an `insert into "person" default values` query.
|
|
245
|
+
*/
|
|
246
|
+
defaultValues(): InsertQueryBuilder<DB, TB, O>;
|
|
243
247
|
/**
|
|
244
248
|
* Changes an `insert into` query to an `insert ignore into` query.
|
|
245
249
|
*
|
|
@@ -563,10 +567,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
563
567
|
/**
|
|
564
568
|
* Change the output type of the query.
|
|
565
569
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
570
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
571
|
+
* returns a copy of this `InsertQueryBuilder` with a new output type.
|
|
568
572
|
*/
|
|
569
|
-
$castTo<
|
|
573
|
+
$castTo<C>(): InsertQueryBuilder<DB, TB, C>;
|
|
570
574
|
/**
|
|
571
575
|
* Narrows (parts of) the output type of the query.
|
|
572
576
|
*
|
|
@@ -98,6 +98,17 @@ class InsertQueryBuilder {
|
|
|
98
98
|
}),
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Creates an `insert into "person" default values` query.
|
|
103
|
+
*/
|
|
104
|
+
defaultValues() {
|
|
105
|
+
return new InsertQueryBuilder({
|
|
106
|
+
...this.#props,
|
|
107
|
+
queryNode: insert_query_node_js_1.InsertQueryNode.cloneWith(this.#props.queryNode, {
|
|
108
|
+
defaultValues: true,
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
101
112
|
/**
|
|
102
113
|
* Changes an `insert into` query to an `insert ignore into` query.
|
|
103
114
|
*
|
|
@@ -398,8 +409,8 @@ class InsertQueryBuilder {
|
|
|
398
409
|
/**
|
|
399
410
|
* Change the output type of the query.
|
|
400
411
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
412
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
413
|
+
* returns a copy of this `InsertQueryBuilder` with a new output type.
|
|
403
414
|
*/
|
|
404
415
|
$castTo() {
|
|
405
416
|
return new InsertQueryBuilder(this.#props);
|
|
@@ -232,7 +232,8 @@ export declare class TraversedJSONPathBuilder<S, O> extends JSONPathBuilder<S, O
|
|
|
232
232
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
233
233
|
* returns a copy of this `JSONPathBuilder` with a new output type.
|
|
234
234
|
*/
|
|
235
|
-
$castTo<
|
|
235
|
+
$castTo<C>(): JSONPathBuilder<C>;
|
|
236
|
+
$notNull(): JSONPathBuilder<Exclude<O, null>>;
|
|
236
237
|
/**
|
|
237
238
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
238
239
|
*
|
|
@@ -25,6 +25,7 @@ import { Streamable } from '../util/streamable.js';
|
|
|
25
25
|
import { ExpressionOrFactory } from '../parser/expression-parser.js';
|
|
26
26
|
import { ExpressionWrapper } from '../expression/expression-wrapper.js';
|
|
27
27
|
import { SelectQueryBuilderExpression } from './select-query-builder-expression.js';
|
|
28
|
+
import { ValueExpression } from '../parser/value-parser.js';
|
|
28
29
|
export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInterface<DB, TB>, HavingInterface<DB, TB>, SelectQueryBuilderExpression<O>, Compilable<O>, Explainable, Streamable<O> {
|
|
29
30
|
/**
|
|
30
31
|
* Adds a `where` expression to the query.
|
|
@@ -674,19 +675,19 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
674
675
|
/**
|
|
675
676
|
* Adds the `for update` modifier to a select query on supported databases.
|
|
676
677
|
*/
|
|
677
|
-
forUpdate(): SelectQueryBuilder<DB, TB, O>;
|
|
678
|
+
forUpdate(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
|
|
678
679
|
/**
|
|
679
680
|
* Adds the `for share` modifier to a select query on supported databases.
|
|
680
681
|
*/
|
|
681
|
-
forShare(): SelectQueryBuilder<DB, TB, O>;
|
|
682
|
+
forShare(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
|
|
682
683
|
/**
|
|
683
684
|
* Adds the `for key share` modifier to a select query on supported databases.
|
|
684
685
|
*/
|
|
685
|
-
forKeyShare(): SelectQueryBuilder<DB, TB, O>;
|
|
686
|
+
forKeyShare(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
|
|
686
687
|
/**
|
|
687
688
|
* Adds the `for no key update` modifier to a select query on supported databases.
|
|
688
689
|
*/
|
|
689
|
-
forNoKeyUpdate(): SelectQueryBuilder<DB, TB, O>;
|
|
690
|
+
forNoKeyUpdate(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
|
|
690
691
|
/**
|
|
691
692
|
* Adds the `skip locked` modifier to a select query on supported databases.
|
|
692
693
|
*/
|
|
@@ -1161,7 +1162,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
1161
1162
|
* .limit(10)
|
|
1162
1163
|
* ```
|
|
1163
1164
|
*/
|
|
1164
|
-
limit(limit: number): SelectQueryBuilder<DB, TB, O>;
|
|
1165
|
+
limit(limit: ValueExpression<DB, TB, number>): SelectQueryBuilder<DB, TB, O>;
|
|
1165
1166
|
/**
|
|
1166
1167
|
* Adds an offset clause to the query.
|
|
1167
1168
|
*
|
|
@@ -1177,7 +1178,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
1177
1178
|
* .limit(10)
|
|
1178
1179
|
* ```
|
|
1179
1180
|
*/
|
|
1180
|
-
offset(offset: number): SelectQueryBuilder<DB, TB, O>;
|
|
1181
|
+
offset(offset: ValueExpression<DB, TB, number>): SelectQueryBuilder<DB, TB, O>;
|
|
1181
1182
|
/**
|
|
1182
1183
|
* Combines another select query or raw expression to this query using `union`.
|
|
1183
1184
|
*
|
|
@@ -1549,10 +1550,10 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
1549
1550
|
/**
|
|
1550
1551
|
* Change the output type of the query.
|
|
1551
1552
|
*
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1553
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
1554
|
+
* returns a copy of this `SelectQueryBuilder` with a new output type.
|
|
1554
1555
|
*/
|
|
1555
|
-
$castTo<
|
|
1556
|
+
$castTo<C>(): SelectQueryBuilder<DB, TB, C>;
|
|
1556
1557
|
/**
|
|
1557
1558
|
* Changes the output type from an object to a tuple.
|
|
1558
1559
|
*
|
|
@@ -1831,4 +1832,5 @@ type OuterJoinedBuilder<DB, TB extends keyof DB, O, A extends keyof any, R> = Se
|
|
|
1831
1832
|
type OuterJoinedBuilderDB<DB, TB extends keyof DB, A extends keyof any, R> = DrainOuterGeneric<{
|
|
1832
1833
|
[C in keyof DB | A]: C extends A ? Nullable<R> : C extends TB ? Nullable<DB[C]> : C extends keyof DB ? DB[C] : never;
|
|
1833
1834
|
}>;
|
|
1835
|
+
type TableOrList<TB extends keyof any> = (TB & string) | ReadonlyArray<TB & string>;
|
|
1834
1836
|
export {};
|
|
@@ -4,6 +4,7 @@ exports.createSelectQueryBuilder = void 0;
|
|
|
4
4
|
const alias_node_js_1 = require("../operation-node/alias-node.js");
|
|
5
5
|
const select_modifier_node_js_1 = require("../operation-node/select-modifier-node.js");
|
|
6
6
|
const join_parser_js_1 = require("../parser/join-parser.js");
|
|
7
|
+
const table_parser_js_1 = require("../parser/table-parser.js");
|
|
7
8
|
const select_parser_js_1 = require("../parser/select-parser.js");
|
|
8
9
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
9
10
|
const select_query_node_js_1 = require("../operation-node/select-query-node.js");
|
|
@@ -19,6 +20,7 @@ const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
|
19
20
|
const set_operation_parser_js_1 = require("../parser/set-operation-parser.js");
|
|
20
21
|
const binary_operation_parser_js_1 = require("../parser/binary-operation-parser.js");
|
|
21
22
|
const expression_wrapper_js_1 = require("../expression/expression-wrapper.js");
|
|
23
|
+
const value_parser_js_1 = require("../parser/value-parser.js");
|
|
22
24
|
class SelectQueryBuilderImpl {
|
|
23
25
|
#props;
|
|
24
26
|
constructor(props) {
|
|
@@ -84,28 +86,28 @@ class SelectQueryBuilderImpl {
|
|
|
84
86
|
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('Distinct')),
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
|
-
forUpdate() {
|
|
89
|
+
forUpdate(of) {
|
|
88
90
|
return new SelectQueryBuilderImpl({
|
|
89
91
|
...this.#props,
|
|
90
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForUpdate')),
|
|
92
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForUpdate', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
|
-
forShare() {
|
|
95
|
+
forShare(of) {
|
|
94
96
|
return new SelectQueryBuilderImpl({
|
|
95
97
|
...this.#props,
|
|
96
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForShare')),
|
|
98
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForShare', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
|
|
97
99
|
});
|
|
98
100
|
}
|
|
99
|
-
forKeyShare() {
|
|
101
|
+
forKeyShare(of) {
|
|
100
102
|
return new SelectQueryBuilderImpl({
|
|
101
103
|
...this.#props,
|
|
102
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForKeyShare')),
|
|
104
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForKeyShare', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
|
-
forNoKeyUpdate() {
|
|
107
|
+
forNoKeyUpdate(of) {
|
|
106
108
|
return new SelectQueryBuilderImpl({
|
|
107
109
|
...this.#props,
|
|
108
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForNoKeyUpdate')),
|
|
110
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForNoKeyUpdate', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
113
|
skipLocked() {
|
|
@@ -177,13 +179,13 @@ class SelectQueryBuilderImpl {
|
|
|
177
179
|
limit(limit) {
|
|
178
180
|
return new SelectQueryBuilderImpl({
|
|
179
181
|
...this.#props,
|
|
180
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create(limit)),
|
|
182
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create((0, value_parser_js_1.parseValueExpression)(limit))),
|
|
181
183
|
});
|
|
182
184
|
}
|
|
183
185
|
offset(offset) {
|
|
184
186
|
return new SelectQueryBuilderImpl({
|
|
185
187
|
...this.#props,
|
|
186
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOffset(this.#props.queryNode, offset_node_js_1.OffsetNode.create(offset)),
|
|
188
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOffset(this.#props.queryNode, offset_node_js_1.OffsetNode.create((0, value_parser_js_1.parseValueExpression)(offset))),
|
|
187
189
|
});
|
|
188
190
|
}
|
|
189
191
|
union(expression) {
|
|
@@ -829,10 +829,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
829
829
|
/**
|
|
830
830
|
* Change the output type of the query.
|
|
831
831
|
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
832
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
833
|
+
* returns a copy of this `UpdateQueryBuilder` with a new output type.
|
|
834
834
|
*/
|
|
835
|
-
$castTo<
|
|
835
|
+
$castTo<C>(): UpdateQueryBuilder<DB, UT, TB, C>;
|
|
836
836
|
/**
|
|
837
837
|
* Narrows (parts of) the output type of the query.
|
|
838
838
|
*
|
|
@@ -156,8 +156,8 @@ class UpdateQueryBuilder {
|
|
|
156
156
|
/**
|
|
157
157
|
* Change the output type of the query.
|
|
158
158
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
159
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
160
|
+
* returns a copy of this `UpdateQueryBuilder` with a new output type.
|
|
161
161
|
*/
|
|
162
162
|
$castTo() {
|
|
163
163
|
return new UpdateQueryBuilder(this.#props);
|
|
@@ -164,6 +164,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
164
164
|
this.append(' ');
|
|
165
165
|
this.visitNode(node.values);
|
|
166
166
|
}
|
|
167
|
+
if (node.defaultValues) {
|
|
168
|
+
this.append(' ');
|
|
169
|
+
this.append('default values');
|
|
170
|
+
}
|
|
167
171
|
if (node.onConflict) {
|
|
168
172
|
this.append(' ');
|
|
169
173
|
this.visitNode(node.onConflict);
|
|
@@ -869,6 +873,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
869
873
|
else {
|
|
870
874
|
this.append(SELECT_MODIFIER_SQL[node.modifier]);
|
|
871
875
|
}
|
|
876
|
+
if (node.of) {
|
|
877
|
+
this.append(' of ');
|
|
878
|
+
this.compileList(node.of, ', ');
|
|
879
|
+
}
|
|
872
880
|
}
|
|
873
881
|
visitCreateType(node) {
|
|
874
882
|
this.append('create type ');
|