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.
Files changed (94) hide show
  1. package/README.md +47 -8
  2. package/dist/cjs/dialect/mysql/mysql-driver.js +7 -7
  3. package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +0 -2
  4. package/dist/cjs/dialect/mysql/mysql-query-compiler.js +0 -29
  5. package/dist/cjs/dialect/postgres/postgres-driver.js +5 -5
  6. package/dist/cjs/operation-node/create-schema-node.d.ts +1 -1
  7. package/dist/cjs/operation-node/create-schema-node.js +2 -2
  8. package/dist/cjs/operation-node/create-table-node.d.ts +1 -5
  9. package/dist/cjs/operation-node/create-table-node.js +1 -31
  10. package/dist/cjs/operation-node/join-node.d.ts +2 -1
  11. package/dist/cjs/operation-node/join-node.js +8 -6
  12. package/dist/cjs/operation-node/operation-node-source.d.ts +1 -1
  13. package/dist/cjs/operation-node/operation-node-transformer.js +2 -1
  14. package/dist/cjs/operation-node/primitive-value-list-node.js +1 -1
  15. package/dist/cjs/operation-node/query-node.d.ts +4 -3
  16. package/dist/cjs/operation-node/query-node.js +10 -2
  17. package/dist/cjs/operation-node/select-query-node.d.ts +2 -1
  18. package/dist/cjs/operation-node/select-query-node.js +10 -2
  19. package/dist/cjs/parser/group-by-parser.d.ts +4 -0
  20. package/dist/cjs/parser/group-by-parser.js +9 -0
  21. package/dist/cjs/parser/join-parser.d.ts +6 -3
  22. package/dist/cjs/parser/order-by-parser.d.ts +2 -4
  23. package/dist/cjs/parser/order-by-parser.js +6 -3
  24. package/dist/cjs/parser/reference-parser.d.ts +1 -1
  25. package/dist/cjs/parser/reference-parser.js +1 -1
  26. package/dist/cjs/parser/table-parser.d.ts +8 -8
  27. package/dist/cjs/query-builder/function-builder.d.ts +6 -6
  28. package/dist/cjs/query-builder/function-builder.js +7 -7
  29. package/dist/cjs/query-builder/join-builder.js +8 -8
  30. package/dist/cjs/query-builder/query-builder.js +20 -22
  31. package/dist/cjs/query-compiler/compiled-query.d.ts +1 -1
  32. package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -3
  33. package/dist/cjs/query-compiler/default-query-compiler.js +23 -29
  34. package/dist/cjs/query-creator.d.ts +14 -11
  35. package/dist/cjs/query-creator.js +14 -11
  36. package/dist/cjs/raw-builder/raw-builder.d.ts +1 -1
  37. package/dist/cjs/raw-builder/raw-builder.js +6 -6
  38. package/dist/cjs/schema/alter-table-builder.d.ts +3 -0
  39. package/dist/cjs/schema/alter-table-builder.js +3 -0
  40. package/dist/cjs/schema/column-definition-builder.d.ts +14 -5
  41. package/dist/cjs/schema/create-schema-builder.js +1 -1
  42. package/dist/cjs/schema/create-table-builder.d.ts +55 -10
  43. package/dist/cjs/schema/create-table-builder.js +59 -17
  44. package/dist/cjs/schema/schema.d.ts +37 -2
  45. package/dist/cjs/schema/schema.js +36 -1
  46. package/dist/cjs/util/object-utils.d.ts +12 -11
  47. package/dist/cjs/util/object-utils.js +6 -2
  48. package/dist/esm/dialect/mysql/mysql-driver.js +8 -8
  49. package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +0 -2
  50. package/dist/esm/dialect/mysql/mysql-query-compiler.js +0 -29
  51. package/dist/esm/dialect/postgres/postgres-driver.js +5 -5
  52. package/dist/esm/operation-node/create-schema-node.d.ts +1 -1
  53. package/dist/esm/operation-node/create-schema-node.js +2 -2
  54. package/dist/esm/operation-node/create-table-node.d.ts +1 -5
  55. package/dist/esm/operation-node/create-table-node.js +1 -31
  56. package/dist/esm/operation-node/join-node.d.ts +2 -1
  57. package/dist/esm/operation-node/join-node.js +8 -6
  58. package/dist/esm/operation-node/operation-node-source.d.ts +1 -1
  59. package/dist/esm/operation-node/operation-node-transformer.js +2 -1
  60. package/dist/esm/operation-node/primitive-value-list-node.js +1 -1
  61. package/dist/esm/operation-node/query-node.d.ts +4 -3
  62. package/dist/esm/operation-node/query-node.js +10 -2
  63. package/dist/esm/operation-node/select-query-node.d.ts +2 -1
  64. package/dist/esm/operation-node/select-query-node.js +10 -2
  65. package/dist/esm/parser/group-by-parser.d.ts +4 -0
  66. package/dist/esm/parser/group-by-parser.js +5 -0
  67. package/dist/esm/parser/join-parser.d.ts +6 -3
  68. package/dist/esm/parser/order-by-parser.d.ts +2 -4
  69. package/dist/esm/parser/order-by-parser.js +6 -2
  70. package/dist/esm/parser/reference-parser.d.ts +1 -1
  71. package/dist/esm/parser/reference-parser.js +2 -2
  72. package/dist/esm/parser/table-parser.d.ts +8 -8
  73. package/dist/esm/query-builder/function-builder.d.ts +6 -6
  74. package/dist/esm/query-builder/function-builder.js +7 -7
  75. package/dist/esm/query-builder/join-builder.js +8 -8
  76. package/dist/esm/query-builder/query-builder.js +21 -23
  77. package/dist/esm/query-compiler/compiled-query.d.ts +1 -1
  78. package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -3
  79. package/dist/esm/query-compiler/default-query-compiler.js +23 -29
  80. package/dist/esm/query-creator.d.ts +14 -11
  81. package/dist/esm/query-creator.js +14 -11
  82. package/dist/esm/raw-builder/raw-builder.d.ts +1 -1
  83. package/dist/esm/raw-builder/raw-builder.js +6 -6
  84. package/dist/esm/schema/alter-table-builder.d.ts +3 -0
  85. package/dist/esm/schema/alter-table-builder.js +3 -0
  86. package/dist/esm/schema/column-definition-builder.d.ts +14 -5
  87. package/dist/esm/schema/create-schema-builder.js +1 -1
  88. package/dist/esm/schema/create-table-builder.d.ts +55 -10
  89. package/dist/esm/schema/create-table-builder.js +60 -18
  90. package/dist/esm/schema/schema.d.ts +37 -2
  91. package/dist/esm/schema/schema.js +36 -1
  92. package/dist/esm/util/object-utils.d.ts +12 -11
  93. package/dist/esm/util/object-utils.js +4 -1
  94. 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 know the
86
- * type the db driver outputs. Sometimes the output can be larger than the
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 know the
110
- * type the db driver outputs. Sometimes the output can be larger than the
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
- params: [column],
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, 'And', (0, filter_parser_js_1.parseOnFilter)(this.#props.parseContext, args)),
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.cloneWithOn(this.#props.joinNode, 'Or', (0, filter_parser_js_1.parseOnFilter)(this.#props.parseContext, args)),
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, 'And', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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.cloneWithOn(this.#props.joinNode, 'Or', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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, 'And', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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, 'And', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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.cloneWithOn(this.#props.joinNode, 'Or', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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.cloneWithOn(this.#props.joinNode, 'Or', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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, 'And', (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
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, 'And', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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.cloneWithWhere(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
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.cloneWithWhere(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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, 'And', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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, 'And', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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.cloneWithWhere(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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.cloneWithWhere(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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, 'And', (0, filter_parser_js_1.parseHavingFilter)(this.#props.parseContext, args)),
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, 'And', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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.cloneWithHaving(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseHavingFilter)(this.#props.parseContext, args)),
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.cloneWithHaving(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
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, 'And', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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, 'And', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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.cloneWithHaving(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
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.cloneWithHaving(this.#props.queryNode, 'Or', (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
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, order_by_item_node_js_1.OrderByItemNode.create((0, order_by_parser_js_1.parseOrderByExpression)(this.#props.parseContext, orderBy), (0, order_by_parser_js_1.parseOrderByDirectionExpression)(direction))),
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, reference_parser_js_1.parseReferenceExpressionOrList)(this.#props.parseContext, orderBy).map(group_by_item_node_js_1.GroupByItemNode.create)),
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 an insert, delete and update queries can have a returning clause');
965
+ throw new Error('only insert, delete and update queries can have a returning clause');
968
966
  }
969
967
  }
970
968
  function assertCanHaveOrderByClause(node) {
@@ -1,4 +1,4 @@
1
1
  export interface CompiledQuery {
2
2
  readonly sql: string;
3
- readonly bindings: ReadonlyArray<any>;
3
+ readonly parameters: ReadonlyArray<unknown>;
4
4
  }
@@ -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 numBindings(): number;
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(value: PrimitiveValue): void;
129
+ protected appendValue(parameter: unknown): void;
129
130
  protected getLeftIdentifierWrapper(): string;
130
131
  protected getRightIdentifierWrapper(): string;
131
132
  protected getCurrentParameterPlaceholder(): string;
132
- protected addBinding(binding: any): void;
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
- #sqlFragments = [];
11
- #bindings = [];
12
- get numBindings() {
13
- return this.#bindings.length;
9
+ #sql = '';
10
+ #parameters = [];
11
+ get numParameters() {
12
+ return this.#parameters.length;
14
13
  }
15
14
  compileQuery(node) {
16
- this.#sqlFragments = [];
17
- this.#bindings = [];
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
- bindings: this.#bindings,
20
+ parameters: this.#parameters,
22
21
  });
23
22
  }
24
23
  getSql() {
25
- return this.#sqlFragments.join('');
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
- if (node.isAutoIncrementing) {
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.#sqlFragments.push(str);
634
+ this.#sql += str;
641
635
  }
642
- appendValue(value) {
643
- this.addBinding(value);
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.numBindings;
647
+ return '$' + this.numParameters;
654
648
  }
655
- addBinding(binding) {
656
- this.#bindings.push(binding);
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: 'no wait',
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 against the given table/tables.
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 the value and pass the actual value in the `params` list. See
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 to provide
280
- * parameter bindings. `?` for values and `??` for identifiers such as column names
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 `??` bindings in
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 `??` bindings to provide `first_name` and `last_name` like
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 bindings
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 bindings.
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 `?` binding for it.
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, params?: any[]): RawBuilder<T>;
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 the value and pass the actual value in the `params` list. See
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 to provide
222
- * parameter bindings. `?` for values and `??` for identifiers such as column names
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 `??` bindings in
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 `??` bindings to provide `first_name` and `last_name` like
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 bindings
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 bindings.
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 `?` binding for it.
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, params) {
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
- params,
328
+ parameters,
326
329
  });
327
330
  }
328
331
  }
@@ -41,5 +41,5 @@ export interface RawBuilderProps {
41
41
  readonly queryId: QueryId;
42
42
  readonly executor: QueryExecutor;
43
43
  readonly sql: string;
44
- readonly params?: any;
44
+ readonly parameters?: any;
45
45
  }
@@ -28,24 +28,24 @@ class RawBuilder {
28
28
  });
29
29
  }
30
30
  toOperationNode() {
31
- const bindingRegex = /(\?\??)/g;
31
+ const parameterPlaceholderRegex = /(\?\??)/g;
32
32
  const sql = this.#props.sql;
33
- const params = this.#props.params ?? [];
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 = bindingRegex.exec(sql))) {
39
+ while ((match = parameterPlaceholderRegex.exec(sql))) {
40
40
  const str = match[1];
41
- if (paramIdx >= params.length) {
42
- throw new Error(`value not provided for all bindings in string ${sql}`);
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, params[paramIdx]));
48
+ argNodes.push(parseRawArg(str, parameters[paramIdx]));
49
49
  sqlIdx = match.index + str.length;
50
50
  ++paramIdx;
51
51
  }