kysely 0.8.0 → 0.9.2
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 +47 -8
- package/dist/cjs/dialect/mysql/mysql-driver.js +7 -7
- package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +0 -2
- package/dist/cjs/dialect/mysql/mysql-query-compiler.js +0 -29
- package/dist/cjs/dialect/postgres/postgres-driver.js +5 -5
- package/dist/cjs/operation-node/create-schema-node.d.ts +1 -1
- package/dist/cjs/operation-node/create-schema-node.js +2 -2
- package/dist/cjs/operation-node/create-table-node.d.ts +1 -5
- package/dist/cjs/operation-node/create-table-node.js +1 -31
- package/dist/cjs/operation-node/join-node.d.ts +2 -1
- package/dist/cjs/operation-node/join-node.js +8 -6
- package/dist/cjs/operation-node/operation-node-source.d.ts +1 -1
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -1
- package/dist/cjs/operation-node/primitive-value-list-node.js +1 -1
- package/dist/cjs/operation-node/query-node.d.ts +4 -3
- package/dist/cjs/operation-node/query-node.js +10 -2
- package/dist/cjs/operation-node/select-query-node.d.ts +2 -1
- package/dist/cjs/operation-node/select-query-node.js +10 -2
- package/dist/cjs/parser/group-by-parser.d.ts +4 -0
- package/dist/cjs/parser/group-by-parser.js +9 -0
- package/dist/cjs/parser/join-parser.d.ts +6 -3
- package/dist/cjs/parser/order-by-parser.d.ts +2 -4
- package/dist/cjs/parser/order-by-parser.js +6 -3
- package/dist/cjs/parser/reference-parser.d.ts +1 -1
- package/dist/cjs/parser/reference-parser.js +1 -1
- package/dist/cjs/parser/table-parser.d.ts +8 -8
- package/dist/cjs/query-builder/function-builder.d.ts +6 -6
- package/dist/cjs/query-builder/function-builder.js +7 -7
- package/dist/cjs/query-builder/join-builder.js +8 -8
- package/dist/cjs/query-builder/query-builder.js +20 -22
- package/dist/cjs/query-compiler/compiled-query.d.ts +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -3
- package/dist/cjs/query-compiler/default-query-compiler.js +23 -29
- package/dist/cjs/query-creator.d.ts +14 -11
- package/dist/cjs/query-creator.js +14 -11
- package/dist/cjs/raw-builder/raw-builder.d.ts +1 -1
- package/dist/cjs/raw-builder/raw-builder.js +6 -6
- package/dist/cjs/schema/alter-table-builder.d.ts +3 -0
- package/dist/cjs/schema/alter-table-builder.js +3 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +14 -5
- package/dist/cjs/schema/create-schema-builder.js +1 -1
- package/dist/cjs/schema/create-table-builder.d.ts +55 -10
- package/dist/cjs/schema/create-table-builder.js +59 -17
- package/dist/cjs/schema/schema.d.ts +37 -2
- package/dist/cjs/schema/schema.js +36 -1
- package/dist/cjs/util/object-utils.d.ts +12 -11
- package/dist/cjs/util/object-utils.js +6 -2
- package/dist/esm/dialect/mysql/mysql-driver.js +8 -8
- package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +0 -2
- package/dist/esm/dialect/mysql/mysql-query-compiler.js +0 -29
- package/dist/esm/dialect/postgres/postgres-driver.js +5 -5
- package/dist/esm/operation-node/create-schema-node.d.ts +1 -1
- package/dist/esm/operation-node/create-schema-node.js +2 -2
- package/dist/esm/operation-node/create-table-node.d.ts +1 -5
- package/dist/esm/operation-node/create-table-node.js +1 -31
- package/dist/esm/operation-node/join-node.d.ts +2 -1
- package/dist/esm/operation-node/join-node.js +8 -6
- package/dist/esm/operation-node/operation-node-source.d.ts +1 -1
- package/dist/esm/operation-node/operation-node-transformer.js +2 -1
- package/dist/esm/operation-node/primitive-value-list-node.js +1 -1
- package/dist/esm/operation-node/query-node.d.ts +4 -3
- package/dist/esm/operation-node/query-node.js +10 -2
- package/dist/esm/operation-node/select-query-node.d.ts +2 -1
- package/dist/esm/operation-node/select-query-node.js +10 -2
- package/dist/esm/parser/group-by-parser.d.ts +4 -0
- package/dist/esm/parser/group-by-parser.js +5 -0
- package/dist/esm/parser/join-parser.d.ts +6 -3
- package/dist/esm/parser/order-by-parser.d.ts +2 -4
- package/dist/esm/parser/order-by-parser.js +6 -2
- package/dist/esm/parser/reference-parser.d.ts +1 -1
- package/dist/esm/parser/reference-parser.js +2 -2
- package/dist/esm/parser/table-parser.d.ts +8 -8
- package/dist/esm/query-builder/function-builder.d.ts +6 -6
- package/dist/esm/query-builder/function-builder.js +7 -7
- package/dist/esm/query-builder/join-builder.js +8 -8
- package/dist/esm/query-builder/query-builder.js +21 -23
- package/dist/esm/query-compiler/compiled-query.d.ts +1 -1
- package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -3
- package/dist/esm/query-compiler/default-query-compiler.js +23 -29
- package/dist/esm/query-creator.d.ts +14 -11
- package/dist/esm/query-creator.js +14 -11
- package/dist/esm/raw-builder/raw-builder.d.ts +1 -1
- package/dist/esm/raw-builder/raw-builder.js +6 -6
- package/dist/esm/schema/alter-table-builder.d.ts +3 -0
- package/dist/esm/schema/alter-table-builder.js +3 -0
- package/dist/esm/schema/column-definition-builder.d.ts +14 -5
- package/dist/esm/schema/create-schema-builder.js +1 -1
- package/dist/esm/schema/create-table-builder.d.ts +55 -10
- package/dist/esm/schema/create-table-builder.js +60 -18
- package/dist/esm/schema/schema.d.ts +37 -2
- package/dist/esm/schema/schema.js +36 -1
- package/dist/esm/util/object-utils.d.ts +12 -11
- package/dist/esm/util/object-utils.js +4 -1
- package/package.json +1 -1
|
@@ -82,9 +82,9 @@ class FunctionBuilder {
|
|
|
82
82
|
* Calls the `sum` function for the column given as the argument.
|
|
83
83
|
*
|
|
84
84
|
* If this is used in a `select` statement the type of the selected expression
|
|
85
|
-
* will be `number | string` by default. This is because Kysely can't
|
|
86
|
-
* type the db driver outputs. Sometimes the output can be larger than
|
|
87
|
-
* largest javascript number and a string is returned instead. Most drivers
|
|
85
|
+
* will be `number | string | BigInt` by default. This is because Kysely can't
|
|
86
|
+
* know the type the db driver outputs. Sometimes the output can be larger than
|
|
87
|
+
* the largest javascript number and a string is returned instead. Most drivers
|
|
88
88
|
* allow you to configure the output type of large numbers and Kysely can't
|
|
89
89
|
* know if you've done so.
|
|
90
90
|
*
|
|
@@ -106,9 +106,9 @@ class FunctionBuilder {
|
|
|
106
106
|
* Calls the `count` function for the column given as the argument.
|
|
107
107
|
*
|
|
108
108
|
* If this is used in a `select` statement the type of the selected expression
|
|
109
|
-
* will be `number | string` by default. This is because Kysely can't
|
|
110
|
-
* type the db driver outputs. Sometimes the output can be larger than
|
|
111
|
-
* largest javascript number and a string is returned instead. Most drivers
|
|
109
|
+
* will be `number | string | BigInt` by default. This is because Kysely can't
|
|
110
|
+
* know the type the db driver outputs. Sometimes the output can be larger than
|
|
111
|
+
* the largest javascript number and a string is returned instead. Most drivers
|
|
112
112
|
* allow you to configure the output type of large numbers and Kysely can't
|
|
113
113
|
* know if you've done so.
|
|
114
114
|
*
|
|
@@ -131,7 +131,7 @@ class FunctionBuilder {
|
|
|
131
131
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
132
132
|
executor: this.#props.executor,
|
|
133
133
|
sql: `${fn}(??)`,
|
|
134
|
-
|
|
134
|
+
parameters: [column],
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -13,13 +13,13 @@ class JoinBuilder {
|
|
|
13
13
|
on(...args) {
|
|
14
14
|
return new JoinBuilder({
|
|
15
15
|
...this.#props,
|
|
16
|
-
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode,
|
|
16
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode, (0, filter_parser_js_1.parseOnFilter)(this.#props.parseContext, args)),
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
orOn(...args) {
|
|
20
20
|
return new JoinBuilder({
|
|
21
21
|
...this.#props,
|
|
22
|
-
joinNode: join_node_js_1.JoinNode.
|
|
22
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOrOn(this.#props.joinNode, (0, filter_parser_js_1.parseOnFilter)(this.#props.parseContext, args)),
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -31,7 +31,7 @@ class JoinBuilder {
|
|
|
31
31
|
onRef(lhs, op, rhs) {
|
|
32
32
|
return new JoinBuilder({
|
|
33
33
|
...this.#props,
|
|
34
|
-
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode,
|
|
34
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -43,7 +43,7 @@ class JoinBuilder {
|
|
|
43
43
|
orOnRef(lhs, op, rhs) {
|
|
44
44
|
return new JoinBuilder({
|
|
45
45
|
...this.#props,
|
|
46
|
-
joinNode: join_node_js_1.JoinNode.
|
|
46
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOrOn(this.#props.joinNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -55,7 +55,7 @@ class JoinBuilder {
|
|
|
55
55
|
onExists(arg) {
|
|
56
56
|
return new JoinBuilder({
|
|
57
57
|
...this.#props,
|
|
58
|
-
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode,
|
|
58
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -67,7 +67,7 @@ class JoinBuilder {
|
|
|
67
67
|
onNotExists(arg) {
|
|
68
68
|
return new JoinBuilder({
|
|
69
69
|
...this.#props,
|
|
70
|
-
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode,
|
|
70
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOn(this.#props.joinNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -79,7 +79,7 @@ class JoinBuilder {
|
|
|
79
79
|
orOnExists(arg) {
|
|
80
80
|
return new JoinBuilder({
|
|
81
81
|
...this.#props,
|
|
82
|
-
joinNode: join_node_js_1.JoinNode.
|
|
82
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOrOn(this.#props.joinNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -91,7 +91,7 @@ class JoinBuilder {
|
|
|
91
91
|
orOnNotExists(arg) {
|
|
92
92
|
return new JoinBuilder({
|
|
93
93
|
...this.#props,
|
|
94
|
-
joinNode: join_node_js_1.JoinNode.
|
|
94
|
+
joinNode: join_node_js_1.JoinNode.cloneWithOrOn(this.#props.joinNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
toOperationNode() {
|
|
@@ -6,13 +6,10 @@ const join_parser_js_1 = require("../parser/join-parser.js");
|
|
|
6
6
|
const select_parser_js_1 = require("../parser/select-parser.js");
|
|
7
7
|
const filter_parser_js_1 = require("../parser/filter-parser.js");
|
|
8
8
|
const insert_values_parser_js_1 = require("../parser/insert-values-parser.js");
|
|
9
|
-
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
10
|
-
const order_by_item_node_js_1 = require("../operation-node/order-by-item-node.js");
|
|
11
9
|
const select_query_node_js_1 = require("../operation-node/select-query-node.js");
|
|
12
10
|
const insert_query_node_js_1 = require("../operation-node/insert-query-node.js");
|
|
13
11
|
const query_node_js_1 = require("../operation-node/query-node.js");
|
|
14
12
|
const order_by_parser_js_1 = require("../parser/order-by-parser.js");
|
|
15
|
-
const group_by_item_node_js_1 = require("../operation-node/group-by-item-node.js");
|
|
16
13
|
const update_query_node_js_1 = require("../operation-node/update-query-node.js");
|
|
17
14
|
const update_set_parser_js_1 = require("../parser/update-set-parser.js");
|
|
18
15
|
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
@@ -22,6 +19,7 @@ const on_conflict_parser_js_1 = require("../parser/on-conflict-parser.js");
|
|
|
22
19
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
23
20
|
const delete_query_node_js_1 = require("../operation-node/delete-query-node.js");
|
|
24
21
|
const on_duplicate_key_node_js_1 = require("../operation-node/on-duplicate-key-node.js");
|
|
22
|
+
const group_by_parser_js_1 = require("../parser/group-by-parser.js");
|
|
25
23
|
/**
|
|
26
24
|
* The main query builder class.
|
|
27
25
|
*
|
|
@@ -46,7 +44,7 @@ class QueryBuilder {
|
|
|
46
44
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
47
45
|
return new QueryBuilder({
|
|
48
46
|
...this.#props,
|
|
49
|
-
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode,
|
|
47
|
+
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
@@ -104,14 +102,14 @@ class QueryBuilder {
|
|
|
104
102
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
105
103
|
return new QueryBuilder({
|
|
106
104
|
...this.#props,
|
|
107
|
-
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode,
|
|
105
|
+
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
108
106
|
});
|
|
109
107
|
}
|
|
110
108
|
orWhere(...args) {
|
|
111
109
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
112
110
|
return new QueryBuilder({
|
|
113
111
|
...this.#props,
|
|
114
|
-
queryNode: query_node_js_1.QueryNode.
|
|
112
|
+
queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
115
|
/**
|
|
@@ -124,7 +122,7 @@ class QueryBuilder {
|
|
|
124
122
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
125
123
|
return new QueryBuilder({
|
|
126
124
|
...this.#props,
|
|
127
|
-
queryNode: query_node_js_1.QueryNode.
|
|
125
|
+
queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
128
126
|
});
|
|
129
127
|
}
|
|
130
128
|
/**
|
|
@@ -190,7 +188,7 @@ class QueryBuilder {
|
|
|
190
188
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
191
189
|
return new QueryBuilder({
|
|
192
190
|
...this.#props,
|
|
193
|
-
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode,
|
|
191
|
+
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
194
192
|
});
|
|
195
193
|
}
|
|
196
194
|
/**
|
|
@@ -200,7 +198,7 @@ class QueryBuilder {
|
|
|
200
198
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
201
199
|
return new QueryBuilder({
|
|
202
200
|
...this.#props,
|
|
203
|
-
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode,
|
|
201
|
+
queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
204
202
|
});
|
|
205
203
|
}
|
|
206
204
|
/**
|
|
@@ -210,7 +208,7 @@ class QueryBuilder {
|
|
|
210
208
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
211
209
|
return new QueryBuilder({
|
|
212
210
|
...this.#props,
|
|
213
|
-
queryNode: query_node_js_1.QueryNode.
|
|
211
|
+
queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
214
212
|
});
|
|
215
213
|
}
|
|
216
214
|
/**
|
|
@@ -220,14 +218,14 @@ class QueryBuilder {
|
|
|
220
218
|
assertCanHaveWhereClause(this.#props.queryNode);
|
|
221
219
|
return new QueryBuilder({
|
|
222
220
|
...this.#props,
|
|
223
|
-
queryNode: query_node_js_1.QueryNode.
|
|
221
|
+
queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
224
222
|
});
|
|
225
223
|
}
|
|
226
224
|
having(...args) {
|
|
227
225
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
228
226
|
return new QueryBuilder({
|
|
229
227
|
...this.#props,
|
|
230
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode,
|
|
228
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode, (0, filter_parser_js_1.parseHavingFilter)(this.#props.parseContext, args)),
|
|
231
229
|
});
|
|
232
230
|
}
|
|
233
231
|
/**
|
|
@@ -238,14 +236,14 @@ class QueryBuilder {
|
|
|
238
236
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
239
237
|
return new QueryBuilder({
|
|
240
238
|
...this.#props,
|
|
241
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode,
|
|
239
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
242
240
|
});
|
|
243
241
|
}
|
|
244
242
|
orHaving(...args) {
|
|
245
243
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
246
244
|
return new QueryBuilder({
|
|
247
245
|
...this.#props,
|
|
248
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
246
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrHaving(this.#props.queryNode, (0, filter_parser_js_1.parseHavingFilter)(this.#props.parseContext, args)),
|
|
249
247
|
});
|
|
250
248
|
}
|
|
251
249
|
/**
|
|
@@ -256,7 +254,7 @@ class QueryBuilder {
|
|
|
256
254
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
257
255
|
return new QueryBuilder({
|
|
258
256
|
...this.#props,
|
|
259
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
257
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrHaving(this.#props.queryNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
260
258
|
});
|
|
261
259
|
}
|
|
262
260
|
/**
|
|
@@ -267,7 +265,7 @@ class QueryBuilder {
|
|
|
267
265
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
268
266
|
return new QueryBuilder({
|
|
269
267
|
...this.#props,
|
|
270
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode,
|
|
268
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
271
269
|
});
|
|
272
270
|
}
|
|
273
271
|
/**
|
|
@@ -278,7 +276,7 @@ class QueryBuilder {
|
|
|
278
276
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
279
277
|
return new QueryBuilder({
|
|
280
278
|
...this.#props,
|
|
281
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode,
|
|
279
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithHaving(this.#props.queryNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
282
280
|
});
|
|
283
281
|
}
|
|
284
282
|
/**
|
|
@@ -289,7 +287,7 @@ class QueryBuilder {
|
|
|
289
287
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
290
288
|
return new QueryBuilder({
|
|
291
289
|
...this.#props,
|
|
292
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
290
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrHaving(this.#props.queryNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
293
291
|
});
|
|
294
292
|
}
|
|
295
293
|
/**
|
|
@@ -300,7 +298,7 @@ class QueryBuilder {
|
|
|
300
298
|
assertCanHaveHavingClause(this.#props.queryNode);
|
|
301
299
|
return new QueryBuilder({
|
|
302
300
|
...this.#props,
|
|
303
|
-
queryNode: select_query_node_js_1.SelectQueryNode.
|
|
301
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrHaving(this.#props.queryNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
304
302
|
});
|
|
305
303
|
}
|
|
306
304
|
select(selection) {
|
|
@@ -717,14 +715,14 @@ class QueryBuilder {
|
|
|
717
715
|
assertCanHaveOrderByClause(this.#props.queryNode);
|
|
718
716
|
return new QueryBuilder({
|
|
719
717
|
...this.#props,
|
|
720
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrderByItem(this.#props.queryNode,
|
|
718
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOrderByItem(this.#props.queryNode, (0, order_by_parser_js_1.parseOrderBy)(this.#props.parseContext, orderBy, direction)),
|
|
721
719
|
});
|
|
722
720
|
}
|
|
723
721
|
groupBy(orderBy) {
|
|
724
722
|
assertCanHaveGroupByClause(this.#props.queryNode);
|
|
725
723
|
return new QueryBuilder({
|
|
726
724
|
...this.#props,
|
|
727
|
-
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, (0,
|
|
725
|
+
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, (0, group_by_parser_js_1.parseGroupBy)(this.#props.parseContext, orderBy)),
|
|
728
726
|
});
|
|
729
727
|
}
|
|
730
728
|
/**
|
|
@@ -964,7 +962,7 @@ function assertCanHaveUpdates(node) {
|
|
|
964
962
|
}
|
|
965
963
|
function assertCanHaveReturningClause(node) {
|
|
966
964
|
if (!query_node_js_1.QueryNode.isMutating(node)) {
|
|
967
|
-
throw new Error('only
|
|
965
|
+
throw new Error('only insert, delete and update queries can have a returning clause');
|
|
968
966
|
}
|
|
969
967
|
}
|
|
970
968
|
function assertCanHaveOrderByClause(node) {
|
|
@@ -62,7 +62,7 @@ import { ModifyColumnNode } from '../operation-node/modify-column-node.js';
|
|
|
62
62
|
import { OnDuplicateKeyNode } from '../operation-node/on-duplicate-key-node.js';
|
|
63
63
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
64
64
|
#private;
|
|
65
|
-
protected get
|
|
65
|
+
protected get numParameters(): number;
|
|
66
66
|
compileQuery(node: RootOperationNode): CompiledQuery;
|
|
67
67
|
protected getSql(): string;
|
|
68
68
|
protected visitSelectQuery(node: SelectQueryNode): void;
|
|
@@ -92,6 +92,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
92
92
|
protected visitTable(node: TableNode): void;
|
|
93
93
|
protected visitCreateTable(node: CreateTableNode): void;
|
|
94
94
|
protected visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
95
|
+
protected getAutoIncrement(): string;
|
|
95
96
|
protected visitReferences(node: ReferencesNode): void;
|
|
96
97
|
protected visitDropTable(node: DropTableNode): void;
|
|
97
98
|
protected visitDataType(node: DataTypeNode): void;
|
|
@@ -125,10 +126,10 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
125
126
|
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
126
127
|
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
127
128
|
protected append(str: string): void;
|
|
128
|
-
protected appendValue(
|
|
129
|
+
protected appendValue(parameter: unknown): void;
|
|
129
130
|
protected getLeftIdentifierWrapper(): string;
|
|
130
131
|
protected getRightIdentifierWrapper(): string;
|
|
131
132
|
protected getCurrentParameterPlaceholder(): string;
|
|
132
|
-
protected
|
|
133
|
+
protected addParameter(parameter: unknown): void;
|
|
133
134
|
protected appendImmediateValue(value: PrimitiveValue): void;
|
|
134
135
|
}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultQueryCompiler = void 0;
|
|
4
|
-
const data_type_node_js_1 = require("../operation-node/data-type-node.js");
|
|
5
4
|
const operation_node_visitor_js_1 = require("../operation-node/operation-node-visitor.js");
|
|
6
5
|
const query_node_js_1 = require("../operation-node/query-node.js");
|
|
7
6
|
const raw_node_js_1 = require("../operation-node/raw-node.js");
|
|
8
7
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
9
8
|
class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisitor {
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
get
|
|
13
|
-
return this.#
|
|
9
|
+
#sql = '';
|
|
10
|
+
#parameters = [];
|
|
11
|
+
get numParameters() {
|
|
12
|
+
return this.#parameters.length;
|
|
14
13
|
}
|
|
15
14
|
compileQuery(node) {
|
|
16
|
-
this.#
|
|
17
|
-
this.#
|
|
15
|
+
this.#sql = '';
|
|
16
|
+
this.#parameters = [];
|
|
18
17
|
this.visitNode(node);
|
|
19
18
|
return (0, object_utils_js_1.freeze)({
|
|
20
19
|
sql: this.getSql(),
|
|
21
|
-
|
|
20
|
+
parameters: this.#parameters,
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
getSql() {
|
|
25
|
-
return this.#
|
|
24
|
+
return this.#sql;
|
|
26
25
|
}
|
|
27
26
|
visitSelectQuery(node) {
|
|
28
27
|
// This is a sub query if this is not the root node.
|
|
@@ -292,19 +291,7 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
292
291
|
visitColumnDefinition(node) {
|
|
293
292
|
this.visitNode(node.column);
|
|
294
293
|
this.append(' ');
|
|
295
|
-
|
|
296
|
-
// Postgres overrides the data type for autoincrementing columns.
|
|
297
|
-
if (data_type_node_js_1.DataTypeNode.is(node.dataType) &&
|
|
298
|
-
node.dataType.dataType === 'bigint') {
|
|
299
|
-
this.append('bigserial');
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
this.append('serial');
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
this.visitNode(node.dataType);
|
|
307
|
-
}
|
|
294
|
+
this.visitNode(node.dataType);
|
|
308
295
|
if (node.defaultTo) {
|
|
309
296
|
this.append(' default ');
|
|
310
297
|
this.visitNode(node.defaultTo);
|
|
@@ -312,6 +299,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
312
299
|
if (!node.isNullable) {
|
|
313
300
|
this.append(' not null');
|
|
314
301
|
}
|
|
302
|
+
if (node.isAutoIncrementing) {
|
|
303
|
+
this.append(' ');
|
|
304
|
+
this.append(this.getAutoIncrement());
|
|
305
|
+
}
|
|
315
306
|
if (node.isUnique) {
|
|
316
307
|
this.append(' unique');
|
|
317
308
|
}
|
|
@@ -327,6 +318,9 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
327
318
|
this.visitNode(node.check);
|
|
328
319
|
}
|
|
329
320
|
}
|
|
321
|
+
getAutoIncrement() {
|
|
322
|
+
return 'auto_increment';
|
|
323
|
+
}
|
|
330
324
|
visitReferences(node) {
|
|
331
325
|
this.append('references ');
|
|
332
326
|
this.visitNode(node.table);
|
|
@@ -637,10 +631,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
637
631
|
this.visitNode(node.constraintName);
|
|
638
632
|
}
|
|
639
633
|
append(str) {
|
|
640
|
-
this.#
|
|
634
|
+
this.#sql += str;
|
|
641
635
|
}
|
|
642
|
-
appendValue(
|
|
643
|
-
this.
|
|
636
|
+
appendValue(parameter) {
|
|
637
|
+
this.addParameter(parameter);
|
|
644
638
|
this.append(this.getCurrentParameterPlaceholder());
|
|
645
639
|
}
|
|
646
640
|
getLeftIdentifierWrapper() {
|
|
@@ -650,10 +644,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
650
644
|
return '"';
|
|
651
645
|
}
|
|
652
646
|
getCurrentParameterPlaceholder() {
|
|
653
|
-
return '$' + this.
|
|
647
|
+
return '$' + this.numParameters;
|
|
654
648
|
}
|
|
655
|
-
|
|
656
|
-
this.#
|
|
649
|
+
addParameter(parameter) {
|
|
650
|
+
this.#parameters.push(parameter);
|
|
657
651
|
}
|
|
658
652
|
appendImmediateValue(value) {
|
|
659
653
|
if ((0, object_utils_js_1.isString)(value)) {
|
|
@@ -682,7 +676,7 @@ const SELECT_MODIFIER_SQL = {
|
|
|
682
676
|
ForNoKeyUpdate: 'for no key update',
|
|
683
677
|
ForUpdate: 'for update',
|
|
684
678
|
ForShare: 'for share',
|
|
685
|
-
NoWait: '
|
|
679
|
+
NoWait: 'nowait',
|
|
686
680
|
SkipLocked: 'skip locked',
|
|
687
681
|
};
|
|
688
682
|
const JOIN_TYPE_SQL = {
|
|
@@ -10,7 +10,7 @@ export declare class QueryCreator<DB> {
|
|
|
10
10
|
#private;
|
|
11
11
|
constructor(props: QueryCreatorProps);
|
|
12
12
|
/**
|
|
13
|
-
* Creates a `select` query builder
|
|
13
|
+
* Creates a `select` query builder for the given table or tables.
|
|
14
14
|
*
|
|
15
15
|
* The tables passed to this method are built as the query's `from` clause.
|
|
16
16
|
*
|
|
@@ -221,6 +221,9 @@ export declare class QueryCreator<DB> {
|
|
|
221
221
|
* Sets the schema to be used for all table references that don't explicitly
|
|
222
222
|
* specify a schema.
|
|
223
223
|
*
|
|
224
|
+
* This only affects the query created through the builder returned from
|
|
225
|
+
* this method and doesn't modify the `db` instance.
|
|
226
|
+
*
|
|
224
227
|
* @example
|
|
225
228
|
* ```
|
|
226
229
|
* await db.withSchema('mammals')
|
|
@@ -261,10 +264,10 @@ export declare class QueryCreator<DB> {
|
|
|
261
264
|
* Provides a way to pass arbitrary SQL into your query and executing completely
|
|
262
265
|
* raw queries.
|
|
263
266
|
*
|
|
264
|
-
* You can use strings `?` and `??` in the `sql` to bind parameters such as
|
|
267
|
+
* You can use the strings `?` and `??` in the `sql` to bind parameters such as
|
|
265
268
|
* user input to the SQL. You should never EVER concatenate untrusted user
|
|
266
269
|
* input to the SQL string to avoid injection vulnerabilities. Instead use `?`
|
|
267
|
-
* in place of
|
|
270
|
+
* in place of a value and pass the actual value in the `parameters` list. See
|
|
268
271
|
* the examples below.
|
|
269
272
|
*
|
|
270
273
|
* You should only use `raw` when there is no other way to get the job done. This is
|
|
@@ -276,11 +279,11 @@ export declare class QueryCreator<DB> {
|
|
|
276
279
|
* Raw builder instances can be passed to pretty much anywhere: `select`, `where`,
|
|
277
280
|
* `*Join`, `groupBy`, `orderBy` etc. Just try it. If the method accepts it, it works.
|
|
278
281
|
*
|
|
279
|
-
* @param sql - The raw SQL. Special strings `?` and `??` can be used
|
|
280
|
-
*
|
|
282
|
+
* @param sql - The raw SQL. Special strings `?` and `??` can be used as parameter
|
|
283
|
+
* placeholders. `?` for values and `??` for identifiers such as column names
|
|
281
284
|
* or `column.table` references.
|
|
282
285
|
*
|
|
283
|
-
* @param params - The parameters that will be bound to the `?` and `??`
|
|
286
|
+
* @param params - The parameters that will be bound to the `?` and `??` placeholders in
|
|
284
287
|
* the sql string.
|
|
285
288
|
*
|
|
286
289
|
* @example
|
|
@@ -318,7 +321,7 @@ export declare class QueryCreator<DB> {
|
|
|
318
321
|
* the output type. In this case you need to use the `castTo` method on the query
|
|
319
322
|
* to specify a return type for the query.
|
|
320
323
|
*
|
|
321
|
-
* We could've also used `??`
|
|
324
|
+
* We could've also used a `??` placeholder to provide `first_name` and `last_name` like
|
|
322
325
|
* this:
|
|
323
326
|
*
|
|
324
327
|
* ```ts
|
|
@@ -333,9 +336,9 @@ export declare class QueryCreator<DB> {
|
|
|
333
336
|
*
|
|
334
337
|
* But it's often cleaner to just write the column names in the SQL. Again remember to
|
|
335
338
|
* never concatenate column names or any other untrusted user input to the SQL string or you
|
|
336
|
-
* are going to create an injection vulnerability. All user input should go to the
|
|
339
|
+
* are going to create an injection vulnerability. All user input should go to the parameters
|
|
337
340
|
* array, never to the SQL string directly. But if the column names or values are trusted
|
|
338
|
-
* and known at compile time, there is no reason to use
|
|
341
|
+
* and known at compile time, there is no reason to use parameters.
|
|
339
342
|
*
|
|
340
343
|
* @example
|
|
341
344
|
* Example of using `raw` in `where`:
|
|
@@ -361,7 +364,7 @@ export declare class QueryCreator<DB> {
|
|
|
361
364
|
*
|
|
362
365
|
* The function in the above example returns people that are older than the given number of
|
|
363
366
|
* years. The number of years in this example is an untrusted user input, and therefore we use
|
|
364
|
-
* a `?`
|
|
367
|
+
* a `?` placeholder for it.
|
|
365
368
|
*
|
|
366
369
|
* @example
|
|
367
370
|
* Example of creating a completely raw query from scratch:
|
|
@@ -375,7 +378,7 @@ export declare class QueryCreator<DB> {
|
|
|
375
378
|
* The result of `execute()` method is always an array. In this case the type of
|
|
376
379
|
* the `persons` variable is `Person[]`.
|
|
377
380
|
*/
|
|
378
|
-
raw<T = unknown>(sql: string,
|
|
381
|
+
raw<T = unknown>(sql: string, parameters?: any[]): RawBuilder<T>;
|
|
379
382
|
}
|
|
380
383
|
export interface QueryCreatorProps {
|
|
381
384
|
readonly executor: QueryExecutor;
|
|
@@ -158,6 +158,9 @@ class QueryCreator {
|
|
|
158
158
|
* Sets the schema to be used for all table references that don't explicitly
|
|
159
159
|
* specify a schema.
|
|
160
160
|
*
|
|
161
|
+
* This only affects the query created through the builder returned from
|
|
162
|
+
* this method and doesn't modify the `db` instance.
|
|
163
|
+
*
|
|
161
164
|
* @example
|
|
162
165
|
* ```
|
|
163
166
|
* await db.withSchema('mammals')
|
|
@@ -203,10 +206,10 @@ class QueryCreator {
|
|
|
203
206
|
* Provides a way to pass arbitrary SQL into your query and executing completely
|
|
204
207
|
* raw queries.
|
|
205
208
|
*
|
|
206
|
-
* You can use strings `?` and `??` in the `sql` to bind parameters such as
|
|
209
|
+
* You can use the strings `?` and `??` in the `sql` to bind parameters such as
|
|
207
210
|
* user input to the SQL. You should never EVER concatenate untrusted user
|
|
208
211
|
* input to the SQL string to avoid injection vulnerabilities. Instead use `?`
|
|
209
|
-
* in place of
|
|
212
|
+
* in place of a value and pass the actual value in the `parameters` list. See
|
|
210
213
|
* the examples below.
|
|
211
214
|
*
|
|
212
215
|
* You should only use `raw` when there is no other way to get the job done. This is
|
|
@@ -218,11 +221,11 @@ class QueryCreator {
|
|
|
218
221
|
* Raw builder instances can be passed to pretty much anywhere: `select`, `where`,
|
|
219
222
|
* `*Join`, `groupBy`, `orderBy` etc. Just try it. If the method accepts it, it works.
|
|
220
223
|
*
|
|
221
|
-
* @param sql - The raw SQL. Special strings `?` and `??` can be used
|
|
222
|
-
*
|
|
224
|
+
* @param sql - The raw SQL. Special strings `?` and `??` can be used as parameter
|
|
225
|
+
* placeholders. `?` for values and `??` for identifiers such as column names
|
|
223
226
|
* or `column.table` references.
|
|
224
227
|
*
|
|
225
|
-
* @param params - The parameters that will be bound to the `?` and `??`
|
|
228
|
+
* @param params - The parameters that will be bound to the `?` and `??` placeholders in
|
|
226
229
|
* the sql string.
|
|
227
230
|
*
|
|
228
231
|
* @example
|
|
@@ -260,7 +263,7 @@ class QueryCreator {
|
|
|
260
263
|
* the output type. In this case you need to use the `castTo` method on the query
|
|
261
264
|
* to specify a return type for the query.
|
|
262
265
|
*
|
|
263
|
-
* We could've also used `??`
|
|
266
|
+
* We could've also used a `??` placeholder to provide `first_name` and `last_name` like
|
|
264
267
|
* this:
|
|
265
268
|
*
|
|
266
269
|
* ```ts
|
|
@@ -275,9 +278,9 @@ class QueryCreator {
|
|
|
275
278
|
*
|
|
276
279
|
* But it's often cleaner to just write the column names in the SQL. Again remember to
|
|
277
280
|
* never concatenate column names or any other untrusted user input to the SQL string or you
|
|
278
|
-
* are going to create an injection vulnerability. All user input should go to the
|
|
281
|
+
* are going to create an injection vulnerability. All user input should go to the parameters
|
|
279
282
|
* array, never to the SQL string directly. But if the column names or values are trusted
|
|
280
|
-
* and known at compile time, there is no reason to use
|
|
283
|
+
* and known at compile time, there is no reason to use parameters.
|
|
281
284
|
*
|
|
282
285
|
* @example
|
|
283
286
|
* Example of using `raw` in `where`:
|
|
@@ -303,7 +306,7 @@ class QueryCreator {
|
|
|
303
306
|
*
|
|
304
307
|
* The function in the above example returns people that are older than the given number of
|
|
305
308
|
* years. The number of years in this example is an untrusted user input, and therefore we use
|
|
306
|
-
* a `?`
|
|
309
|
+
* a `?` placeholder for it.
|
|
307
310
|
*
|
|
308
311
|
* @example
|
|
309
312
|
* Example of creating a completely raw query from scratch:
|
|
@@ -317,12 +320,12 @@ class QueryCreator {
|
|
|
317
320
|
* The result of `execute()` method is always an array. In this case the type of
|
|
318
321
|
* the `persons` variable is `Person[]`.
|
|
319
322
|
*/
|
|
320
|
-
raw(sql,
|
|
323
|
+
raw(sql, parameters) {
|
|
321
324
|
return new raw_builder_js_1.RawBuilder({
|
|
322
325
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
323
326
|
executor: this.#props.executor,
|
|
324
327
|
sql,
|
|
325
|
-
|
|
328
|
+
parameters,
|
|
326
329
|
});
|
|
327
330
|
}
|
|
328
331
|
}
|
|
@@ -28,24 +28,24 @@ class RawBuilder {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
toOperationNode() {
|
|
31
|
-
const
|
|
31
|
+
const parameterPlaceholderRegex = /(\?\??)/g;
|
|
32
32
|
const sql = this.#props.sql;
|
|
33
|
-
const
|
|
33
|
+
const parameters = this.#props.parameters ?? [];
|
|
34
34
|
const sqlFragments = [];
|
|
35
35
|
const argNodes = [];
|
|
36
36
|
let paramIdx = 0;
|
|
37
37
|
let sqlIdx = 0;
|
|
38
38
|
let match = null;
|
|
39
|
-
while ((match =
|
|
39
|
+
while ((match = parameterPlaceholderRegex.exec(sql))) {
|
|
40
40
|
const str = match[1];
|
|
41
|
-
if (paramIdx >=
|
|
42
|
-
throw new Error(`value not provided for all
|
|
41
|
+
if (paramIdx >= parameters.length) {
|
|
42
|
+
throw new Error(`value not provided for all placeholders in string ${sql}`);
|
|
43
43
|
}
|
|
44
44
|
if (match.index > 0 && sql[match.index - 1] === '\\') {
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
47
|
sqlFragments.push(sql.slice(sqlIdx, match.index).replaceAll('\\?', '?'));
|
|
48
|
-
argNodes.push(parseRawArg(str,
|
|
48
|
+
argNodes.push(parseRawArg(str, parameters[paramIdx]));
|
|
49
49
|
sqlIdx = match.index + str.length;
|
|
50
50
|
++paramIdx;
|
|
51
51
|
}
|