kysely 0.21.6 → 0.22.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/README.md +2 -2
- package/dist/cjs/index.d.ts +9 -4
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/kysely.d.ts +3 -3
- package/dist/cjs/kysely.js +3 -3
- package/dist/cjs/migration/file-migration-provider.js +7 -2
- package/dist/cjs/operation-node/aggregate-function-node.d.ts +22 -0
- package/dist/cjs/operation-node/aggregate-function-node.js +31 -0
- package/dist/cjs/operation-node/alias-node.d.ts +2 -1
- package/dist/cjs/operation-node/group-by-node.d.ts +1 -1
- package/dist/cjs/operation-node/group-by-node.js +3 -3
- package/dist/cjs/operation-node/insert-query-node.d.ts +2 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +10 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +38 -5
- package/dist/cjs/operation-node/operation-node-utils.d.ts +2 -1
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +10 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +5 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/over-node.d.ts +19 -0
- package/dist/cjs/operation-node/over-node.js +35 -0
- package/dist/cjs/operation-node/partition-by-item-node.d.ts +14 -0
- package/dist/cjs/operation-node/{union-node.js → partition-by-item-node.js} +6 -7
- package/dist/cjs/operation-node/partition-by-node.d.ts +14 -0
- package/dist/cjs/operation-node/partition-by-node.js +24 -0
- package/dist/cjs/operation-node/select-query-node.d.ts +3 -3
- package/dist/cjs/operation-node/select-query-node.js +4 -4
- package/dist/cjs/operation-node/set-operation-node.d.ts +18 -0
- package/dist/cjs/operation-node/set-operation-node.js +20 -0
- package/dist/cjs/operation-node/value-list-node.d.ts +2 -1
- package/dist/cjs/parser/complex-expression-parser.d.ts +6 -4
- package/dist/cjs/parser/group-by-parser.d.ts +1 -1
- package/dist/cjs/parser/group-by-parser.js +2 -2
- package/dist/cjs/parser/parse-utils.d.ts +2 -0
- package/dist/cjs/parser/parse-utils.js +9 -1
- package/dist/cjs/parser/partition-by-parser.d.ts +6 -0
- package/dist/cjs/parser/partition-by-parser.js +9 -0
- package/dist/cjs/parser/reference-parser.d.ts +2 -1
- package/dist/cjs/parser/select-parser.d.ts +4 -3
- package/dist/cjs/parser/set-operation-parser.d.ts +5 -0
- package/dist/cjs/parser/set-operation-parser.js +8 -0
- package/dist/cjs/parser/value-parser.d.ts +2 -1
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +117 -0
- package/dist/cjs/query-builder/aggregate-function-builder.js +146 -0
- package/dist/cjs/query-builder/expression-builder.d.ts +3 -3
- package/dist/cjs/query-builder/expression-builder.js +3 -3
- package/dist/cjs/query-builder/{function-builder.d.ts → function-module.d.ts} +49 -42
- package/dist/cjs/query-builder/{function-builder.js → function-module.js} +70 -59
- package/dist/cjs/query-builder/over-builder.d.ts +59 -0
- package/dist/cjs/query-builder/over-builder.js +50 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +63 -3
- package/dist/cjs/query-builder/select-query-builder.js +83 -3
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +10 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +41 -14
- package/dist/cjs/raw-builder/sql.d.ts +13 -5
- package/dist/cjs/raw-builder/sql.js +6 -0
- package/dist/cjs/util/type-utils.d.ts +4 -0
- package/dist/esm/index.d.ts +9 -4
- package/dist/esm/index.js +7 -2
- package/dist/esm/kysely.d.ts +3 -3
- package/dist/esm/kysely.js +3 -3
- package/dist/esm/migration/file-migration-provider.js +7 -2
- package/dist/esm/operation-node/aggregate-function-node.d.ts +22 -0
- package/dist/esm/operation-node/aggregate-function-node.js +29 -0
- package/dist/esm/operation-node/alias-node.d.ts +2 -1
- package/dist/esm/operation-node/group-by-node.d.ts +1 -1
- package/dist/esm/operation-node/group-by-node.js +3 -3
- package/dist/esm/operation-node/insert-query-node.d.ts +2 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +10 -2
- package/dist/esm/operation-node/operation-node-transformer.js +38 -5
- package/dist/esm/operation-node/operation-node-utils.d.ts +2 -1
- package/dist/esm/operation-node/operation-node-visitor.d.ts +10 -2
- package/dist/esm/operation-node/operation-node-visitor.js +5 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/over-node.d.ts +19 -0
- package/dist/esm/operation-node/over-node.js +33 -0
- package/dist/esm/operation-node/partition-by-item-node.d.ts +14 -0
- package/dist/esm/operation-node/partition-by-item-node.js +16 -0
- package/dist/esm/operation-node/partition-by-node.d.ts +14 -0
- package/dist/esm/operation-node/partition-by-node.js +22 -0
- package/dist/esm/operation-node/select-query-node.d.ts +3 -3
- package/dist/esm/operation-node/select-query-node.js +4 -4
- package/dist/esm/operation-node/set-operation-node.d.ts +18 -0
- package/dist/esm/operation-node/set-operation-node.js +18 -0
- package/dist/esm/operation-node/value-list-node.d.ts +2 -1
- package/dist/esm/parser/complex-expression-parser.d.ts +6 -4
- package/dist/esm/parser/group-by-parser.d.ts +1 -1
- package/dist/esm/parser/group-by-parser.js +2 -2
- package/dist/esm/parser/parse-utils.d.ts +2 -0
- package/dist/esm/parser/parse-utils.js +7 -0
- package/dist/esm/parser/partition-by-parser.d.ts +6 -0
- package/dist/esm/parser/partition-by-parser.js +6 -0
- package/dist/esm/parser/reference-parser.d.ts +2 -1
- package/dist/esm/parser/select-parser.d.ts +4 -3
- package/dist/esm/parser/set-operation-parser.d.ts +5 -0
- package/dist/esm/parser/set-operation-parser.js +5 -0
- package/dist/esm/parser/value-parser.d.ts +2 -1
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +117 -0
- package/dist/esm/query-builder/aggregate-function-builder.js +142 -0
- package/dist/esm/query-builder/expression-builder.d.ts +3 -3
- package/dist/esm/query-builder/expression-builder.js +3 -3
- package/dist/esm/query-builder/{function-builder.d.ts → function-module.d.ts} +49 -42
- package/dist/esm/query-builder/{function-builder.js → function-module.js} +69 -58
- package/dist/esm/query-builder/over-builder.d.ts +59 -0
- package/dist/esm/query-builder/over-builder.js +47 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +63 -3
- package/dist/esm/query-builder/select-query-builder.js +83 -3
- package/dist/esm/query-compiler/default-query-compiler.d.ts +10 -2
- package/dist/esm/query-compiler/default-query-compiler.js +41 -14
- package/dist/esm/raw-builder/sql.d.ts +13 -5
- package/dist/esm/raw-builder/sql.js +6 -0
- package/dist/esm/util/type-utils.d.ts +4 -0
- package/package.json +4 -1
- package/dist/cjs/operation-node/union-node.d.ts +0 -16
- package/dist/cjs/parser/union-parser.d.ts +0 -5
- package/dist/cjs/parser/union-parser.js +0 -8
- package/dist/esm/operation-node/union-node.d.ts +0 -16
- package/dist/esm/operation-node/union-node.js +0 -17
- package/dist/esm/parser/union-parser.d.ts +0 -5
- package/dist/esm/parser/union-parser.js +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringReference, ExtractTypeFromReferenceExpression } from '../parser/reference-parser.js';
|
|
2
|
-
import {
|
|
2
|
+
import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
|
|
3
3
|
/**
|
|
4
4
|
* Helpers for type safe SQL function calls.
|
|
5
5
|
*
|
|
@@ -32,38 +32,8 @@ import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
|
32
32
|
* having count("pet"."id") > $1
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
export declare class
|
|
36
|
-
#private;
|
|
35
|
+
export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
37
36
|
constructor();
|
|
38
|
-
/**
|
|
39
|
-
* Calls the `max` function for the column given as the argument.
|
|
40
|
-
*
|
|
41
|
-
* ### Examples
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* const { max } = db.fn
|
|
45
|
-
*
|
|
46
|
-
* db.selectFrom('toy')
|
|
47
|
-
* .select(max('price').as('max_price'))
|
|
48
|
-
* .execute()
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
max<C extends StringReference<DB, TB>>(column: C): RawBuilder<ExtractTypeFromReferenceExpression<DB, TB, C>>;
|
|
52
|
-
/**
|
|
53
|
-
* Calls the `min` function for the column given as the argument.
|
|
54
|
-
*
|
|
55
|
-
* ### Examples
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const { min } = db.fn
|
|
59
|
-
*
|
|
60
|
-
* db.selectFrom('toy')
|
|
61
|
-
* .select(min('price').as('min_price'))
|
|
62
|
-
* .execute()
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
*/
|
|
66
|
-
min<C extends StringReference<DB, TB>>(column: C): RawBuilder<ExtractTypeFromReferenceExpression<DB, TB, C>>;
|
|
67
37
|
/**
|
|
68
38
|
* Calls the `avg` function for the column given as the argument.
|
|
69
39
|
*
|
|
@@ -85,9 +55,9 @@ export declare class FunctionBuilder<DB, TB extends keyof DB> {
|
|
|
85
55
|
* .execute()
|
|
86
56
|
* ```
|
|
87
57
|
*/
|
|
88
|
-
avg<O extends number | string, C extends StringReference<DB, TB> = StringReference<DB, TB>>(column: C):
|
|
58
|
+
avg<O extends number | string, C extends StringReference<DB, TB> = StringReference<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
|
|
89
59
|
/**
|
|
90
|
-
* Calls the `
|
|
60
|
+
* Calls the `count` function for the column given as the argument.
|
|
91
61
|
*
|
|
92
62
|
* If this is used in a `select` statement the type of the selected expression
|
|
93
63
|
* will be `number | string | bigint` by default. This is because Kysely can't
|
|
@@ -100,19 +70,56 @@ export declare class FunctionBuilder<DB, TB extends keyof DB> {
|
|
|
100
70
|
* the type as the first type argument:
|
|
101
71
|
*
|
|
102
72
|
* ```ts
|
|
103
|
-
* const {
|
|
73
|
+
* const { count } = db.fn
|
|
104
74
|
*
|
|
105
75
|
* db.selectFrom('toy')
|
|
106
|
-
* .select(
|
|
76
|
+
* .select(count<number>('id').as('num_toys'))
|
|
77
|
+
* .execute()
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* You can limit column range:
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* db.selectFrom('toy')
|
|
84
|
+
* .select(qb => qb.fn.count<number>('id').as('num_toys'))
|
|
107
85
|
* .execute()
|
|
108
86
|
* ```
|
|
109
87
|
*/
|
|
110
|
-
|
|
88
|
+
count<O extends number | string | bigint, C extends StringReference<DB, TB> = StringReference<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
|
|
111
89
|
/**
|
|
112
|
-
* Calls the `
|
|
90
|
+
* Calls the `max` function for the column given as the argument.
|
|
91
|
+
*
|
|
92
|
+
* ### Examples
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const { max } = db.fn
|
|
96
|
+
*
|
|
97
|
+
* db.selectFrom('toy')
|
|
98
|
+
* .select(max('price').as('max_price'))
|
|
99
|
+
* .execute()
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
max<C extends StringReference<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, ExtractTypeFromReferenceExpression<DB, TB, C>>;
|
|
103
|
+
/**
|
|
104
|
+
* Calls the `min` function for the column given as the argument.
|
|
105
|
+
*
|
|
106
|
+
* ### Examples
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* const { min } = db.fn
|
|
110
|
+
*
|
|
111
|
+
* db.selectFrom('toy')
|
|
112
|
+
* .select(min('price').as('min_price'))
|
|
113
|
+
* .execute()
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
min<C extends StringReference<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, ExtractTypeFromReferenceExpression<DB, TB, C>>;
|
|
118
|
+
/**
|
|
119
|
+
* Calls the `sum` function for the column given as the argument.
|
|
113
120
|
*
|
|
114
121
|
* If this is used in a `select` statement the type of the selected expression
|
|
115
|
-
* will be `number | string |bigint` by default. This is because Kysely can't
|
|
122
|
+
* will be `number | string | bigint` by default. This is because Kysely can't
|
|
116
123
|
* know the type the db driver outputs. Sometimes the output can be larger than
|
|
117
124
|
* the largest javascript number and a string is returned instead. Most drivers
|
|
118
125
|
* allow you to configure the output type of large numbers and Kysely can't
|
|
@@ -122,12 +129,12 @@ export declare class FunctionBuilder<DB, TB extends keyof DB> {
|
|
|
122
129
|
* the type as the first type argument:
|
|
123
130
|
*
|
|
124
131
|
* ```ts
|
|
125
|
-
* const {
|
|
132
|
+
* const { sum } = db.fn
|
|
126
133
|
*
|
|
127
134
|
* db.selectFrom('toy')
|
|
128
|
-
* .select(
|
|
135
|
+
* .select(sum<number>('price').as('total_price'))
|
|
129
136
|
* .execute()
|
|
130
137
|
* ```
|
|
131
138
|
*/
|
|
132
|
-
|
|
139
|
+
sum<O extends number | string | bigint, C extends StringReference<DB, TB> = StringReference<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
|
|
133
140
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.FunctionModule = void 0;
|
|
4
|
+
const aggregate_function_node_js_1 = require("../operation-node/aggregate-function-node.js");
|
|
5
5
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
6
|
-
const
|
|
7
|
-
const query_id_js_1 = require("../util/query-id.js");
|
|
6
|
+
const aggregate_function_builder_js_1 = require("./aggregate-function-builder.js");
|
|
8
7
|
/**
|
|
9
8
|
* Helpers for type safe SQL function calls.
|
|
10
9
|
*
|
|
@@ -37,46 +36,13 @@ const query_id_js_1 = require("../util/query-id.js");
|
|
|
37
36
|
* having count("pet"."id") > $1
|
|
38
37
|
* ```
|
|
39
38
|
*/
|
|
40
|
-
class
|
|
39
|
+
class FunctionModule {
|
|
41
40
|
constructor() {
|
|
42
|
-
this.min = this.min.bind(this);
|
|
43
|
-
this.max = this.max.bind(this);
|
|
44
41
|
this.avg = this.avg.bind(this);
|
|
45
|
-
this.sum = this.sum.bind(this);
|
|
46
42
|
this.count = this.count.bind(this);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
* ### Examples
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* const { max } = db.fn
|
|
55
|
-
*
|
|
56
|
-
* db.selectFrom('toy')
|
|
57
|
-
* .select(max('price').as('max_price'))
|
|
58
|
-
* .execute()
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
max(column) {
|
|
62
|
-
return this.#oneArgFunction('max', column);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Calls the `min` function for the column given as the argument.
|
|
66
|
-
*
|
|
67
|
-
* ### Examples
|
|
68
|
-
*
|
|
69
|
-
* ```ts
|
|
70
|
-
* const { min } = db.fn
|
|
71
|
-
*
|
|
72
|
-
* db.selectFrom('toy')
|
|
73
|
-
* .select(min('price').as('min_price'))
|
|
74
|
-
* .execute()
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
min(column) {
|
|
79
|
-
return this.#oneArgFunction('min', column);
|
|
43
|
+
this.max = this.max.bind(this);
|
|
44
|
+
this.min = this.min.bind(this);
|
|
45
|
+
this.sum = this.sum.bind(this);
|
|
80
46
|
}
|
|
81
47
|
/**
|
|
82
48
|
* Calls the `avg` function for the column given as the argument.
|
|
@@ -100,10 +66,12 @@ class FunctionBuilder {
|
|
|
100
66
|
* ```
|
|
101
67
|
*/
|
|
102
68
|
avg(column) {
|
|
103
|
-
return
|
|
69
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
70
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('avg', (0, reference_parser_js_1.parseStringReference)(column)),
|
|
71
|
+
});
|
|
104
72
|
}
|
|
105
73
|
/**
|
|
106
|
-
* Calls the `
|
|
74
|
+
* Calls the `count` function for the column given as the argument.
|
|
107
75
|
*
|
|
108
76
|
* If this is used in a `select` statement the type of the selected expression
|
|
109
77
|
* will be `number | string | bigint` by default. This is because Kysely can't
|
|
@@ -116,21 +84,68 @@ class FunctionBuilder {
|
|
|
116
84
|
* the type as the first type argument:
|
|
117
85
|
*
|
|
118
86
|
* ```ts
|
|
119
|
-
* const {
|
|
87
|
+
* const { count } = db.fn
|
|
120
88
|
*
|
|
121
89
|
* db.selectFrom('toy')
|
|
122
|
-
* .select(
|
|
90
|
+
* .select(count<number>('id').as('num_toys'))
|
|
91
|
+
* .execute()
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* You can limit column range:
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* db.selectFrom('toy')
|
|
98
|
+
* .select(qb => qb.fn.count<number>('id').as('num_toys'))
|
|
123
99
|
* .execute()
|
|
124
100
|
* ```
|
|
125
101
|
*/
|
|
126
|
-
|
|
127
|
-
return
|
|
102
|
+
count(column) {
|
|
103
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
104
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('count', (0, reference_parser_js_1.parseStringReference)(column)),
|
|
105
|
+
});
|
|
128
106
|
}
|
|
129
107
|
/**
|
|
130
|
-
* Calls the `
|
|
108
|
+
* Calls the `max` function for the column given as the argument.
|
|
109
|
+
*
|
|
110
|
+
* ### Examples
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* const { max } = db.fn
|
|
114
|
+
*
|
|
115
|
+
* db.selectFrom('toy')
|
|
116
|
+
* .select(max('price').as('max_price'))
|
|
117
|
+
* .execute()
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
max(column) {
|
|
121
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
122
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('max', (0, reference_parser_js_1.parseStringReference)(column)),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Calls the `min` function for the column given as the argument.
|
|
127
|
+
*
|
|
128
|
+
* ### Examples
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* const { min } = db.fn
|
|
132
|
+
*
|
|
133
|
+
* db.selectFrom('toy')
|
|
134
|
+
* .select(min('price').as('min_price'))
|
|
135
|
+
* .execute()
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
min(column) {
|
|
140
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
141
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('min', (0, reference_parser_js_1.parseStringReference)(column)),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Calls the `sum` function for the column given as the argument.
|
|
131
146
|
*
|
|
132
147
|
* If this is used in a `select` statement the type of the selected expression
|
|
133
|
-
* will be `number | string |bigint` by default. This is because Kysely can't
|
|
148
|
+
* will be `number | string | bigint` by default. This is because Kysely can't
|
|
134
149
|
* know the type the db driver outputs. Sometimes the output can be larger than
|
|
135
150
|
* the largest javascript number and a string is returned instead. Most drivers
|
|
136
151
|
* allow you to configure the output type of large numbers and Kysely can't
|
|
@@ -140,21 +155,17 @@ class FunctionBuilder {
|
|
|
140
155
|
* the type as the first type argument:
|
|
141
156
|
*
|
|
142
157
|
* ```ts
|
|
143
|
-
* const {
|
|
158
|
+
* const { sum } = db.fn
|
|
144
159
|
*
|
|
145
160
|
* db.selectFrom('toy')
|
|
146
|
-
* .select(
|
|
161
|
+
* .select(sum<number>('price').as('total_price'))
|
|
147
162
|
* .execute()
|
|
148
163
|
* ```
|
|
149
164
|
*/
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
#oneArgFunction(fn, column) {
|
|
154
|
-
return new raw_builder_js_1.RawBuilder({
|
|
155
|
-
queryId: (0, query_id_js_1.createQueryId)(),
|
|
156
|
-
rawNode: raw_node_js_1.RawNode.create([`${fn}(`, ')'], [(0, reference_parser_js_1.parseStringReference)(column)]),
|
|
165
|
+
sum(column) {
|
|
166
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
167
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('sum', (0, reference_parser_js_1.parseStringReference)(column)),
|
|
157
168
|
});
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
|
-
exports.
|
|
171
|
+
exports.FunctionModule = FunctionModule;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DynamicReferenceBuilder } from '../dynamic/dynamic-reference-builder.js';
|
|
2
|
+
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
3
|
+
import { OverNode } from '../operation-node/over-node.js';
|
|
4
|
+
import { OrderByDirectionExpression } from '../parser/order-by-parser.js';
|
|
5
|
+
import { PartitionByExpression } from '../parser/partition-by-parser.js';
|
|
6
|
+
import { StringReference } from '../parser/reference-parser.js';
|
|
7
|
+
export declare class OverBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(props: OverBuilderProps);
|
|
10
|
+
/**
|
|
11
|
+
* Adds an order by clause item inside the over function.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result = await db
|
|
15
|
+
* .selectFrom('person')
|
|
16
|
+
* .select(
|
|
17
|
+
* eb => eb.fn.avg<number>('age').over(
|
|
18
|
+
* ob => ob.orderBy('first_name', 'asc').orderBy('last_name', 'asc')
|
|
19
|
+
* ).as('average_age')
|
|
20
|
+
* )
|
|
21
|
+
* .execute()
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The generated SQL (PostgreSQL):
|
|
25
|
+
*
|
|
26
|
+
* ```sql
|
|
27
|
+
* select avg("age") over(order by "first_name" asc, "last_name" asc) as "average_age"
|
|
28
|
+
* from "person"
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
orderBy(orderBy: StringReference<DB, TB> | DynamicReferenceBuilder<any>, direction?: OrderByDirectionExpression): OverBuilder<DB, TB>;
|
|
32
|
+
/**
|
|
33
|
+
* Adds partition by clause item/s inside the over function.
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const result = await db
|
|
37
|
+
* .selectFrom('person')
|
|
38
|
+
* .select(
|
|
39
|
+
* eb => eb.fn.avg<number>('age').over(
|
|
40
|
+
* ob => ob.partitionBy(['last_name', 'first_name'])
|
|
41
|
+
* ).as('average_age')
|
|
42
|
+
* )
|
|
43
|
+
* .execute()
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* The generated SQL (PostgreSQL):
|
|
47
|
+
*
|
|
48
|
+
* ```sql
|
|
49
|
+
* select avg("age") over(partition by "last_name", "first_name") as "average_age"
|
|
50
|
+
* from "person"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
partitionBy(partitionBy: ReadonlyArray<PartitionByExpression<DB, TB>>): OverBuilder<DB, TB>;
|
|
54
|
+
partitionBy(partitionBy: PartitionByExpression<DB, TB>): OverBuilder<DB, TB>;
|
|
55
|
+
toOperationNode(): OverNode;
|
|
56
|
+
}
|
|
57
|
+
export interface OverBuilderProps {
|
|
58
|
+
readonly overNode: OverNode;
|
|
59
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OverBuilder = void 0;
|
|
4
|
+
const over_node_js_1 = require("../operation-node/over-node.js");
|
|
5
|
+
const order_by_parser_js_1 = require("../parser/order-by-parser.js");
|
|
6
|
+
const partition_by_parser_js_1 = require("../parser/partition-by-parser.js");
|
|
7
|
+
const object_utils_js_1 = require("../util/object-utils.js");
|
|
8
|
+
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
9
|
+
class OverBuilder {
|
|
10
|
+
#props;
|
|
11
|
+
constructor(props) {
|
|
12
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Adds an order by clause item inside the over function.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const result = await db
|
|
19
|
+
* .selectFrom('person')
|
|
20
|
+
* .select(
|
|
21
|
+
* eb => eb.fn.avg<number>('age').over(
|
|
22
|
+
* ob => ob.orderBy('first_name', 'asc').orderBy('last_name', 'asc')
|
|
23
|
+
* ).as('average_age')
|
|
24
|
+
* )
|
|
25
|
+
* .execute()
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The generated SQL (PostgreSQL):
|
|
29
|
+
*
|
|
30
|
+
* ```sql
|
|
31
|
+
* select avg("age") over(order by "first_name" asc, "last_name" asc) as "average_age"
|
|
32
|
+
* from "person"
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
orderBy(orderBy, direction) {
|
|
36
|
+
return new OverBuilder({
|
|
37
|
+
overNode: over_node_js_1.OverNode.cloneWithOrderByItem(this.#props.overNode, (0, order_by_parser_js_1.parseOrderBy)(orderBy, direction)),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
partitionBy(partitionBy) {
|
|
41
|
+
return new OverBuilder({
|
|
42
|
+
overNode: over_node_js_1.OverNode.cloneWithPartitionByItems(this.#props.overNode, (0, partition_by_parser_js_1.parsePartitionBy)(partitionBy)),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
toOperationNode() {
|
|
46
|
+
return this.#props.overNode;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.OverBuilder = OverBuilder;
|
|
50
|
+
(0, prevent_await_js_1.preventAwait)(OverBuilder, "don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");
|
|
@@ -13,13 +13,13 @@ import { Compilable } from '../util/compilable.js';
|
|
|
13
13
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
14
14
|
import { QueryId } from '../util/query-id.js';
|
|
15
15
|
import { GroupByExpression } from '../parser/group-by-parser.js';
|
|
16
|
-
import { UnionExpression } from '../parser/union-parser.js';
|
|
17
16
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
18
17
|
import { WhereInterface } from './where-interface.js';
|
|
19
18
|
import { NoResultErrorConstructor } from './no-result-error.js';
|
|
20
19
|
import { HavingInterface } from './having-interface.js';
|
|
21
20
|
import { AliasedRawBuilder } from '../raw-builder/raw-builder.js';
|
|
22
21
|
import { Explainable, ExplainFormat } from '../util/explainable.js';
|
|
22
|
+
import { SetOperationExpression } from '../parser/set-operation-parser.js';
|
|
23
23
|
export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, HavingInterface<DB, TB>, OperationNodeSource, Compilable, Explainable {
|
|
24
24
|
#private;
|
|
25
25
|
constructor(props: SelectQueryBuilderProps);
|
|
@@ -1202,7 +1202,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1202
1202
|
* .orderBy('name')
|
|
1203
1203
|
* ```
|
|
1204
1204
|
*/
|
|
1205
|
-
union(expression:
|
|
1205
|
+
union(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1206
1206
|
/**
|
|
1207
1207
|
* Combines another select query or raw expression to this query using `union all`.
|
|
1208
1208
|
*
|
|
@@ -1217,7 +1217,67 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1217
1217
|
* .orderBy('name')
|
|
1218
1218
|
* ```
|
|
1219
1219
|
*/
|
|
1220
|
-
unionAll(expression:
|
|
1220
|
+
unionAll(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1221
|
+
/**
|
|
1222
|
+
* Combines another select query or raw expression to this query using `intersect`.
|
|
1223
|
+
*
|
|
1224
|
+
* The output row type of the combined query must match `this` query.
|
|
1225
|
+
*
|
|
1226
|
+
* ### Examples
|
|
1227
|
+
*
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* db.selectFrom('person')
|
|
1230
|
+
* .select(['id', 'first_name as name'])
|
|
1231
|
+
* .intersect(db.selectFrom('pet').select(['id', 'name']))
|
|
1232
|
+
* .orderBy('name')
|
|
1233
|
+
* ```
|
|
1234
|
+
*/
|
|
1235
|
+
intersect(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1236
|
+
/**
|
|
1237
|
+
* Combines another select query or raw expression to this query using `intersect all`.
|
|
1238
|
+
*
|
|
1239
|
+
* The output row type of the combined query must match `this` query.
|
|
1240
|
+
*
|
|
1241
|
+
* ### Examples
|
|
1242
|
+
*
|
|
1243
|
+
* ```ts
|
|
1244
|
+
* db.selectFrom('person')
|
|
1245
|
+
* .select(['id', 'first_name as name'])
|
|
1246
|
+
* .intersectAll(db.selectFrom('pet').select(['id', 'name']))
|
|
1247
|
+
* .orderBy('name')
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
intersectAll(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Combines another select query or raw expression to this query using `except`.
|
|
1253
|
+
*
|
|
1254
|
+
* The output row type of the combined query must match `this` query.
|
|
1255
|
+
*
|
|
1256
|
+
* ### Examples
|
|
1257
|
+
*
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* db.selectFrom('person')
|
|
1260
|
+
* .select(['id', 'first_name as name'])
|
|
1261
|
+
* .except(db.selectFrom('pet').select(['id', 'name']))
|
|
1262
|
+
* .orderBy('name')
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
except(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Combines another select query or raw expression to this query using `except all`.
|
|
1268
|
+
*
|
|
1269
|
+
* The output row type of the combined query must match `this` query.
|
|
1270
|
+
*
|
|
1271
|
+
* ### Examples
|
|
1272
|
+
*
|
|
1273
|
+
* ```ts
|
|
1274
|
+
* db.selectFrom('person')
|
|
1275
|
+
* .select(['id', 'first_name as name'])
|
|
1276
|
+
* .exceptAll(db.selectFrom('pet').select(['id', 'name']))
|
|
1277
|
+
* .orderBy('name')
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
exceptAll(expression: SetOperationExpression<DB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1221
1281
|
/**
|
|
1222
1282
|
* Simply calls the given function passing `this` as the only argument.
|
|
1223
1283
|
*
|
|
@@ -14,10 +14,10 @@ const limit_node_js_1 = require("../operation-node/limit-node.js");
|
|
|
14
14
|
const offset_node_js_1 = require("../operation-node/offset-node.js");
|
|
15
15
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
16
16
|
const group_by_parser_js_1 = require("../parser/group-by-parser.js");
|
|
17
|
-
const union_parser_js_1 = require("../parser/union-parser.js");
|
|
18
17
|
const no_result_error_js_1 = require("./no-result-error.js");
|
|
19
18
|
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
20
19
|
const explain_node_js_1 = require("../operation-node/explain-node.js");
|
|
20
|
+
const set_operation_parser_js_1 = require("../parser/set-operation-parser.js");
|
|
21
21
|
class SelectQueryBuilder {
|
|
22
22
|
#props;
|
|
23
23
|
constructor(props) {
|
|
@@ -472,7 +472,7 @@ class SelectQueryBuilder {
|
|
|
472
472
|
union(expression) {
|
|
473
473
|
return new SelectQueryBuilder({
|
|
474
474
|
...this.#props,
|
|
475
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
475
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('union', expression, false)),
|
|
476
476
|
});
|
|
477
477
|
}
|
|
478
478
|
/**
|
|
@@ -492,7 +492,87 @@ class SelectQueryBuilder {
|
|
|
492
492
|
unionAll(expression) {
|
|
493
493
|
return new SelectQueryBuilder({
|
|
494
494
|
...this.#props,
|
|
495
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
495
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('union', expression, true)),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Combines another select query or raw expression to this query using `intersect`.
|
|
500
|
+
*
|
|
501
|
+
* The output row type of the combined query must match `this` query.
|
|
502
|
+
*
|
|
503
|
+
* ### Examples
|
|
504
|
+
*
|
|
505
|
+
* ```ts
|
|
506
|
+
* db.selectFrom('person')
|
|
507
|
+
* .select(['id', 'first_name as name'])
|
|
508
|
+
* .intersect(db.selectFrom('pet').select(['id', 'name']))
|
|
509
|
+
* .orderBy('name')
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
intersect(expression) {
|
|
513
|
+
return new SelectQueryBuilder({
|
|
514
|
+
...this.#props,
|
|
515
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('intersect', expression, false)),
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Combines another select query or raw expression to this query using `intersect all`.
|
|
520
|
+
*
|
|
521
|
+
* The output row type of the combined query must match `this` query.
|
|
522
|
+
*
|
|
523
|
+
* ### Examples
|
|
524
|
+
*
|
|
525
|
+
* ```ts
|
|
526
|
+
* db.selectFrom('person')
|
|
527
|
+
* .select(['id', 'first_name as name'])
|
|
528
|
+
* .intersectAll(db.selectFrom('pet').select(['id', 'name']))
|
|
529
|
+
* .orderBy('name')
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
intersectAll(expression) {
|
|
533
|
+
return new SelectQueryBuilder({
|
|
534
|
+
...this.#props,
|
|
535
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('intersect', expression, true)),
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Combines another select query or raw expression to this query using `except`.
|
|
540
|
+
*
|
|
541
|
+
* The output row type of the combined query must match `this` query.
|
|
542
|
+
*
|
|
543
|
+
* ### Examples
|
|
544
|
+
*
|
|
545
|
+
* ```ts
|
|
546
|
+
* db.selectFrom('person')
|
|
547
|
+
* .select(['id', 'first_name as name'])
|
|
548
|
+
* .except(db.selectFrom('pet').select(['id', 'name']))
|
|
549
|
+
* .orderBy('name')
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
except(expression) {
|
|
553
|
+
return new SelectQueryBuilder({
|
|
554
|
+
...this.#props,
|
|
555
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('except', expression, false)),
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Combines another select query or raw expression to this query using `except all`.
|
|
560
|
+
*
|
|
561
|
+
* The output row type of the combined query must match `this` query.
|
|
562
|
+
*
|
|
563
|
+
* ### Examples
|
|
564
|
+
*
|
|
565
|
+
* ```ts
|
|
566
|
+
* db.selectFrom('person')
|
|
567
|
+
* .select(['id', 'first_name as name'])
|
|
568
|
+
* .exceptAll(db.selectFrom('pet').select(['id', 'name']))
|
|
569
|
+
* .orderBy('name')
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
exceptAll(expression) {
|
|
573
|
+
return new SelectQueryBuilder({
|
|
574
|
+
...this.#props,
|
|
575
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('except', expression, true)),
|
|
496
576
|
});
|
|
497
577
|
}
|
|
498
578
|
/**
|
|
@@ -60,7 +60,6 @@ import { ColumnDefinitionNode } from '../operation-node/column-definition-node.j
|
|
|
60
60
|
import { ModifyColumnNode } from '../operation-node/modify-column-node.js';
|
|
61
61
|
import { OnDuplicateKeyNode } from '../operation-node/on-duplicate-key-node.js';
|
|
62
62
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
63
|
-
import { UnionNode } from '../operation-node/union-node.js';
|
|
64
63
|
import { CreateViewNode } from '../operation-node/create-view-node.js';
|
|
65
64
|
import { DropViewNode } from '../operation-node/drop-view-node.js';
|
|
66
65
|
import { GeneratedNode } from '../operation-node/generated-node.js';
|
|
@@ -74,6 +73,11 @@ import { DropTypeNode } from '../operation-node/drop-type-node.js';
|
|
|
74
73
|
import { ExplainNode } from '../operation-node/explain-node.js';
|
|
75
74
|
import { SchemableIdentifierNode } from '../operation-node/schemable-identifier-node.js';
|
|
76
75
|
import { DefaultInsertValueNode } from '../operation-node/default-insert-value-node.js';
|
|
76
|
+
import { AggregateFunctionNode } from '../operation-node/aggregate-function-node.js';
|
|
77
|
+
import { OverNode } from '../operation-node/over-node.js';
|
|
78
|
+
import { PartitionByNode } from '../operation-node/partition-by-node.js';
|
|
79
|
+
import { PartitionByItemNode } from '../operation-node/partition-by-item-node.js';
|
|
80
|
+
import { SetOperationNode } from '../operation-node/set-operation-node.js';
|
|
77
81
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
78
82
|
#private;
|
|
79
83
|
protected get numParameters(): number;
|
|
@@ -145,7 +149,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
145
149
|
protected visitModifyColumn(node: ModifyColumnNode): void;
|
|
146
150
|
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
147
151
|
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
148
|
-
protected
|
|
152
|
+
protected visitSetOperation(node: SetOperationNode): void;
|
|
149
153
|
protected visitCreateView(node: CreateViewNode): void;
|
|
150
154
|
protected visitDropView(node: DropViewNode): void;
|
|
151
155
|
protected visitGenerated(node: GeneratedNode): void;
|
|
@@ -155,6 +159,10 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
155
159
|
protected visitDropType(node: DropTypeNode): void;
|
|
156
160
|
protected visitExplain(node: ExplainNode): void;
|
|
157
161
|
protected visitDefaultInsertValue(_: DefaultInsertValueNode): void;
|
|
162
|
+
protected visitAggregateFunction(node: AggregateFunctionNode): void;
|
|
163
|
+
protected visitOver(node: OverNode): void;
|
|
164
|
+
protected visitPartitionBy(node: PartitionByNode): void;
|
|
165
|
+
protected visitPartitionByItem(node: PartitionByItemNode): void;
|
|
158
166
|
protected append(str: string): void;
|
|
159
167
|
protected appendValue(parameter: unknown): void;
|
|
160
168
|
protected getLeftIdentifierWrapper(): string;
|