kysely 0.23.3 → 0.23.5

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 (118) hide show
  1. package/README.md +25 -25
  2. package/dist/cjs/dialect/database-introspector.d.ts +4 -2
  3. package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
  4. package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
  5. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
  6. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-introspector.js +21 -15
  8. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
  9. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  10. package/dist/cjs/dialect/postgres/postgres-introspector.js +5 -3
  11. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  12. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  13. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +8 -7
  14. package/dist/cjs/index.d.ts +1 -0
  15. package/dist/cjs/index.js +1 -0
  16. package/dist/cjs/migration/migrator.d.ts +8 -3
  17. package/dist/cjs/migration/migrator.js +15 -5
  18. package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
  19. package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
  20. package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
  21. package/dist/cjs/operation-node/delete-query-node.d.ts +4 -1
  22. package/dist/cjs/operation-node/delete-query-node.js +11 -2
  23. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  24. package/dist/cjs/operation-node/operation-node-transformer.js +10 -1
  25. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  26. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  27. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  28. package/dist/cjs/operation-node/operator-node.d.ts +1 -1
  29. package/dist/cjs/operation-node/operator-node.js +1 -0
  30. package/dist/cjs/operation-node/using-node.d.ts +13 -0
  31. package/dist/cjs/operation-node/using-node.js +24 -0
  32. package/dist/cjs/parser/expression-parser.js +1 -1
  33. package/dist/cjs/parser/table-parser.d.ts +1 -0
  34. package/dist/cjs/parser/update-set-parser.d.ts +1 -1
  35. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  36. package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
  37. package/dist/cjs/query-builder/delete-query-builder.d.ts +103 -11
  38. package/dist/cjs/query-builder/delete-query-builder.js +40 -9
  39. package/dist/cjs/query-builder/function-module.d.ts +273 -39
  40. package/dist/cjs/query-builder/function-module.js +156 -34
  41. package/dist/cjs/query-builder/insert-query-builder.d.ts +25 -10
  42. package/dist/cjs/query-builder/insert-query-builder.js +32 -9
  43. package/dist/cjs/query-builder/select-query-builder.d.ts +51 -34
  44. package/dist/cjs/query-builder/select-query-builder.js +53 -29
  45. package/dist/cjs/query-builder/update-query-builder.d.ts +26 -10
  46. package/dist/cjs/query-builder/update-query-builder.js +33 -9
  47. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
  48. package/dist/cjs/query-compiler/default-query-compiler.js +12 -1
  49. package/dist/cjs/query-creator.d.ts +29 -0
  50. package/dist/cjs/query-creator.js +2 -21
  51. package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
  52. package/dist/cjs/raw-builder/raw-builder.js +8 -2
  53. package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
  54. package/dist/cjs/schema/alter-table-builder.js +8 -2
  55. package/dist/cjs/schema/create-index-builder.d.ts +6 -0
  56. package/dist/cjs/schema/create-index-builder.js +13 -0
  57. package/dist/cjs/schema/create-table-builder.d.ts +6 -2
  58. package/dist/cjs/schema/create-table-builder.js +9 -3
  59. package/dist/cjs/util/type-utils.d.ts +20 -1
  60. package/dist/esm/dialect/database-introspector.d.ts +4 -2
  61. package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
  62. package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
  63. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
  64. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  65. package/dist/esm/dialect/mysql/mysql-introspector.js +21 -15
  66. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
  67. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  68. package/dist/esm/dialect/postgres/postgres-introspector.js +5 -3
  69. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  70. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  71. package/dist/esm/dialect/sqlite/sqlite-introspector.js +8 -7
  72. package/dist/esm/index.d.ts +1 -0
  73. package/dist/esm/index.js +1 -0
  74. package/dist/esm/migration/migrator.d.ts +8 -3
  75. package/dist/esm/migration/migrator.js +15 -5
  76. package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
  77. package/dist/esm/operation-node/aggregate-function-node.js +2 -2
  78. package/dist/esm/operation-node/create-index-node.d.ts +1 -0
  79. package/dist/esm/operation-node/delete-query-node.d.ts +4 -1
  80. package/dist/esm/operation-node/delete-query-node.js +11 -2
  81. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  82. package/dist/esm/operation-node/operation-node-transformer.js +10 -1
  83. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  84. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  85. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  86. package/dist/esm/operation-node/operator-node.d.ts +1 -1
  87. package/dist/esm/operation-node/operator-node.js +1 -0
  88. package/dist/esm/operation-node/using-node.d.ts +13 -0
  89. package/dist/esm/operation-node/using-node.js +22 -0
  90. package/dist/esm/parser/expression-parser.js +2 -2
  91. package/dist/esm/parser/table-parser.d.ts +1 -0
  92. package/dist/esm/parser/update-set-parser.d.ts +1 -1
  93. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  94. package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
  95. package/dist/esm/query-builder/delete-query-builder.d.ts +103 -11
  96. package/dist/esm/query-builder/delete-query-builder.js +40 -9
  97. package/dist/esm/query-builder/function-module.d.ts +273 -39
  98. package/dist/esm/query-builder/function-module.js +156 -34
  99. package/dist/esm/query-builder/insert-query-builder.d.ts +25 -10
  100. package/dist/esm/query-builder/insert-query-builder.js +33 -10
  101. package/dist/esm/query-builder/select-query-builder.d.ts +51 -34
  102. package/dist/esm/query-builder/select-query-builder.js +53 -29
  103. package/dist/esm/query-builder/update-query-builder.d.ts +26 -10
  104. package/dist/esm/query-builder/update-query-builder.js +33 -9
  105. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
  106. package/dist/esm/query-compiler/default-query-compiler.js +12 -1
  107. package/dist/esm/query-creator.d.ts +29 -0
  108. package/dist/esm/query-creator.js +2 -21
  109. package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
  110. package/dist/esm/raw-builder/raw-builder.js +8 -2
  111. package/dist/esm/schema/alter-table-builder.d.ts +5 -1
  112. package/dist/esm/schema/alter-table-builder.js +8 -2
  113. package/dist/esm/schema/create-index-builder.d.ts +6 -0
  114. package/dist/esm/schema/create-index-builder.js +13 -0
  115. package/dist/esm/schema/create-table-builder.d.ts +6 -2
  116. package/dist/esm/schema/create-table-builder.js +9 -3
  117. package/dist/esm/util/type-utils.d.ts +20 -1
  118. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeleteQueryBuilder = void 0;
4
4
  const join_parser_js_1 = require("../parser/join-parser.js");
5
+ const table_parser_js_1 = require("../parser/table-parser.js");
5
6
  const select_parser_js_1 = require("../parser/select-parser.js");
6
7
  const query_node_js_1 = require("../operation-node/query-node.js");
7
8
  const prevent_await_js_1 = require("../util/prevent-await.js");
@@ -73,6 +74,12 @@ class DeleteQueryBuilder {
73
74
  queryNode: query_node_js_1.QueryNode.cloneWithoutWhere(this.#props.queryNode),
74
75
  });
75
76
  }
77
+ using(tables) {
78
+ return new DeleteQueryBuilder({
79
+ ...this.#props,
80
+ queryNode: delete_query_node_js_1.DeleteQueryNode.cloneWithUsing(this.#props.queryNode, (0, table_parser_js_1.parseTableExpressionOrList)(tables)),
81
+ });
82
+ }
76
83
  innerJoin(...args) {
77
84
  return new DeleteQueryBuilder({
78
85
  ...this.#props,
@@ -177,7 +184,7 @@ class DeleteQueryBuilder {
177
184
  * Simply calls the given function passing `this` as the only argument.
178
185
  *
179
186
  * If you want to conditionally call a method on `this`, see
180
- * the {@link if} method.
187
+ * the {@link $if} method.
181
188
  *
182
189
  * ### Examples
183
190
  *
@@ -190,13 +197,19 @@ class DeleteQueryBuilder {
190
197
  * }
191
198
  *
192
199
  * db.deleteFrom('person')
193
- * .call(log)
200
+ * .$call(log)
194
201
  * .execute()
195
202
  * ```
196
203
  */
197
- call(func) {
204
+ $call(func) {
198
205
  return func(this);
199
206
  }
207
+ /**
208
+ * @deprecated Use `$call` instead
209
+ */
210
+ call(func) {
211
+ return this.$call(func);
212
+ }
200
213
  /**
201
214
  * Call `func(this)` if `condition` is true.
202
215
  *
@@ -215,7 +228,7 @@ class DeleteQueryBuilder {
215
228
  * .deleteFrom('person')
216
229
  * .where('id', '=', id)
217
230
  * .returning(['id', 'first_name'])
218
- * .if(returnLastName, (qb) => qb.returning('last_name'))
231
+ * .$if(returnLastName, (qb) => qb.returning('last_name'))
219
232
  * .executeTakeFirstOrThrow()
220
233
  * }
221
234
  * ```
@@ -232,7 +245,7 @@ class DeleteQueryBuilder {
232
245
  * }
233
246
  * ```
234
247
  */
235
- if(condition, func) {
248
+ $if(condition, func) {
236
249
  if (condition) {
237
250
  return func(this);
238
251
  }
@@ -240,15 +253,27 @@ class DeleteQueryBuilder {
240
253
  ...this.#props,
241
254
  });
242
255
  }
256
+ /**
257
+ * @deprecated Use `$if` instead
258
+ */
259
+ if(condition, func) {
260
+ return this.$if(condition, func);
261
+ }
243
262
  /**
244
263
  * Change the output type of the query.
245
264
  *
246
265
  * You should only use this method as the last resort if the types
247
266
  * don't support your use case.
248
267
  */
249
- castTo() {
268
+ $castTo() {
250
269
  return new DeleteQueryBuilder(this.#props);
251
270
  }
271
+ /**
272
+ * @deprecated Use `$castTo` instead.
273
+ */
274
+ castTo() {
275
+ return this.$castTo();
276
+ }
252
277
  /**
253
278
  * Asserts that query's output row type equals the given type `T`.
254
279
  *
@@ -277,19 +302,25 @@ class DeleteQueryBuilder {
277
302
  * .deleteFrom('person')
278
303
  * .where('id', '=', person.id)
279
304
  * .returning('first_name')
280
- * .assertType<{ first_name: string }>()
305
+ * .$assertType<{ first_name: string }>()
281
306
  * )
282
307
  * .with('deleted_pet', (qb) => qb
283
308
  * .deleteFrom('pet')
284
309
  * .where('owner_id', '=', person.id)
285
310
  * .returning(['name as pet_name', 'species'])
286
- * .assertType<{ pet_name: string, species: Species }>()
311
+ * .$assertType<{ pet_name: string, species: Species }>()
287
312
  * )
288
313
  * .selectFrom(['deleted_person', 'deleted_pet'])
289
314
  * .selectAll()
290
315
  * .executeTakeFirstOrThrow()
291
316
  * ```
292
317
  */
318
+ $assertType() {
319
+ return new DeleteQueryBuilder(this.#props);
320
+ }
321
+ /**
322
+ * @deprecated Use `$assertType` instead.
323
+ */
293
324
  assertType() {
294
325
  return new DeleteQueryBuilder(this.#props);
295
326
  }
@@ -323,7 +354,7 @@ class DeleteQueryBuilder {
323
354
  return [
324
355
  new delete_result_js_1.DeleteResult(
325
356
  // TODO: remove numUpdatedOrDeletedRows.
326
- (result.numAffectedRows ?? result.numUpdatedOrDeletedRows)),
357
+ result.numAffectedRows ?? result.numUpdatedOrDeletedRows ?? 0n),
327
358
  ];
328
359
  }
329
360
  /**
@@ -41,8 +41,38 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
41
41
  /**
42
42
  * Calls the `avg` function for the column given as the argument.
43
43
  *
44
- * If this is used in a `select` statement the type of the selected expression
45
- * will be `number | string` by default. This is because Kysely can't know the
44
+ * This sql function calculates the average value for a given column.
45
+ *
46
+ * For additional functionality such as distinct, filtering and window functions,
47
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
48
+ * returned when calling this function.
49
+ *
50
+ * ### Examples
51
+ *
52
+ * ```ts
53
+ * const { avg } = db.fn
54
+ *
55
+ * db.selectFrom('toy')
56
+ * .select(avg('price').as('avg_price'))
57
+ * .execute()
58
+ * ```
59
+ *
60
+ * The generated SQL (PostgreSQL):
61
+ *
62
+ * ```sql
63
+ * select avg("price") as "avg_price" from "toy"
64
+ * ```
65
+ *
66
+ * You can limit column range to only columns participating in current query:
67
+ *
68
+ * ```ts
69
+ * db.selectFrom('toy')
70
+ * .select(qb => qb.fn.avg('price').as('avg_price'))
71
+ * .execute()
72
+ * ```
73
+ *
74
+ * If this function is used in a `select` statement, the type of the selected
75
+ * expression will be `number | string` by default. This is because Kysely can't know the
46
76
  * type the db driver outputs. Sometimes the output can be larger than the largest
47
77
  * javascript number and a string is returned instead. Most drivers allow you
48
78
  * to configure the output type of large numbers and Kysely can't know if you've
@@ -61,7 +91,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
61
91
  *
62
92
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
63
93
  * was used. It is highly recommended to include null in the output type union
64
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
94
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
65
95
  * function.
66
96
  *
67
97
  * ```ts
@@ -76,42 +106,153 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
76
106
  /**
77
107
  * Calls the `coalesce` function for given arguments.
78
108
  *
79
- * This function returns the first non-null value from left to right, commonly
109
+ * This sql function returns the first non-null value from left to right, commonly
80
110
  * used to provide a default scalar for nullable columns or functions.
81
111
  *
112
+ * If this function is used in a `select` statement, the type of the selected
113
+ * expression is inferred in the same manner that the sql function computes.
114
+ * A union of arguments' types - if a non-nullable argument exists, it stops
115
+ * there (ignoring any further arguments' types) and exludes null from the final
116
+ * union type.
117
+ *
118
+ * `(string | null, number | null)` is inferred as `string | number | null`.
119
+ *
120
+ * `(string | null, number, Date | null)` is inferred as `string | number`.
121
+ *
122
+ * `(number, string | null)` is inferred as `number`.
123
+ *
124
+ * ### Examples
125
+ *
82
126
  * ```ts
83
- * const { coalesce, max } = db.fn
127
+ * const { coalesce } = db.fn
84
128
  *
85
- * db.selectFrom('person')
86
- * .select(coalesce(max('age'), sql<number>`0`).as('max_age'))
87
- * .where('first_name', '=', 'Jennifer')
129
+ * db.selectFrom('participant')
130
+ * .select(coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname'))
131
+ * .where('room_id', '=', roomId)
88
132
  * .execute()
89
133
  * ```
90
134
  *
91
- * The generated SQL (postgres):
135
+ * The generated SQL (PostgreSQL):
92
136
  *
93
137
  * ```sql
94
- * select coalesce(max("age"), 0) as "max_age" from "person" where "first_name" = $1
138
+ * select coalesce("nickname", '<anonymous>') as "nickname"
139
+ * from "participant" where "room_id" = $1
95
140
  * ```
96
141
  *
97
- * If this is used in a `select` statement the type of the selected expression
98
- * is inferred in the same manner that the function computes. A union of arguments'
99
- * types - if a non-nullable argument exists, it stops there (ignoring any further
100
- * arguments' types) and exludes null from the final union type.
142
+ * You can limit column range to only columns participating in current query:
101
143
  *
102
- * Examples:
144
+ * ```ts
145
+ * db.selectFrom('participant')
146
+ * .select(qb =>
147
+ * qb.fn.coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname')
148
+ * )
149
+ * .where('room_id', '=', roomId)
150
+ * .execute()
151
+ * ```
103
152
  *
104
- * `(string | null, number | null)` is inferred as `string | number | null`.
153
+ * You can combine this function with other helpers in this module:
105
154
  *
106
- * `(string | null, number, Date | null)` is inferred as `string | number`.
155
+ * ```ts
156
+ * const { avg, coalesce } = db.fn
107
157
  *
108
- * `(number, string | null)` is inferred as `number`.
158
+ * db.selectFrom('person')
159
+ * .select(coalesce(avg<number | null>('age'), sql<number>`0`).as('avg_age'))
160
+ * .where('first_name', '=', 'Jennifer')
161
+ * .execute()
162
+ * ```
163
+ *
164
+ * The generated SQL (PostgreSQL):
165
+ *
166
+ * ```sql
167
+ * select coalesce(avg("age"), 0) as "avg_age" from "person" where "first_name" = $1
168
+ * ```
109
169
  */
110
170
  coalesce<V extends ReferenceExpression<DB, TB>, OV extends ReferenceExpression<DB, TB>[]>(value: V, ...otherValues: OV): RawBuilder<CoalesceReferenceExpressionList<DB, TB, [V, ...OV]>>;
111
171
  /**
112
172
  * Calls the `count` function for the column given as the argument.
113
173
  *
114
- * If this is used in a `select` statement the type of the selected expression
174
+ * When called with a column as argument, this sql function counts the number of rows where there
175
+ * is a non-null value in that column.
176
+ *
177
+ * For counting all rows nulls included (`count(*)`), see {@link countAll}.
178
+ *
179
+ * For additional functionality such as distinct, filtering and window functions,
180
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
181
+ * returned when calling this function.
182
+ *
183
+ * ### Examples
184
+ *
185
+ * ```ts
186
+ * const { count } = db.fn
187
+ *
188
+ * db.selectFrom('toy')
189
+ * .select(count('id').as('num_toys'))
190
+ * .execute()
191
+ * ```
192
+ *
193
+ * The generated SQL (PostgreSQL):
194
+ *
195
+ * ```sql
196
+ * select count("id") as "num_toys" from "toy"
197
+ * ```
198
+ *
199
+ * If this function is used in a `select` statement, the type of the selected
200
+ * expression will be `number | string | bigint` by default. This is because
201
+ * Kysely can't know the type the db driver outputs. Sometimes the output can
202
+ * be larger than the largest javascript number and a string is returned instead.
203
+ * Most drivers allow you to configure the output type of large numbers and Kysely
204
+ * can't know if you've done so.
205
+ *
206
+ * You can specify the output type of the expression by providing
207
+ * the type as the first type argument:
208
+ *
209
+ * ```ts
210
+ * const { count } = db.fn
211
+ *
212
+ * db.selectFrom('toy')
213
+ * .select(count<number>('id').as('num_toys'))
214
+ * .execute()
215
+ * ```
216
+ *
217
+ * You can limit column range to only columns participating in current query:
218
+ *
219
+ * ```ts
220
+ * db.selectFrom('toy')
221
+ * .select(qb => qb.fn.count('id').as('num_toys'))
222
+ * .execute()
223
+ * ```
224
+ */
225
+ count<O extends number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
226
+ /**
227
+ * Calls the `count` function with `*` or `table.*` as argument.
228
+ *
229
+ * When called with `*` as argument, this sql function counts the number of rows,
230
+ * nulls included.
231
+ *
232
+ * For counting rows with non-null values in a given column (`count(column)`),
233
+ * see {@link count}.
234
+ *
235
+ * For additional functionality such as filtering and window functions, refer
236
+ * to {@link AggregateFunctionBuilder}. An instance of this builder is returned
237
+ * when calling this function.
238
+ *
239
+ * ### Examples
240
+ *
241
+ * ```ts
242
+ * const { countAll } = db.fn
243
+ *
244
+ * db.selectFrom('toy')
245
+ * .select(countAll().as('num_toys'))
246
+ * .execute()
247
+ * ```
248
+ *
249
+ * The generated SQL (PostgreSQL):
250
+ *
251
+ * ```sql
252
+ * select count(*) as "num_toys" from "toy"
253
+ * ```
254
+ *
255
+ * If this is used in a `select` statement, the type of the selected expression
115
256
  * will be `number | string | bigint` by default. This is because Kysely
116
257
  * can't know the type the db driver outputs. Sometimes the output can be larger
117
258
  * than the largest javascript number and a string is returned instead. Most
@@ -122,27 +263,55 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
122
263
  * the type as the first type argument:
123
264
  *
124
265
  * ```ts
125
- * const { count } = db.fn
266
+ * const { countAll } = db.fn
126
267
  *
127
268
  * db.selectFrom('toy')
128
- * .select(count<number>('id').as('num_toys'))
269
+ * .select(countAll<number>().as('num_toys'))
129
270
  * .execute()
130
271
  * ```
131
272
  *
132
- * You can limit column range:
273
+ * Some databases, such as PostgreSQL, support scoping the function to a specific
274
+ * table:
133
275
  *
134
276
  * ```ts
277
+ * const { countAll } = db.fn
278
+ *
135
279
  * db.selectFrom('toy')
136
- * .select(qb => qb.fn.count<number>('id').as('num_toys'))
280
+ * .innerJoin('pet', 'pet.id', 'toy.pet_id')
281
+ * .select(countAll('toy').as('num_toys'))
282
+ * .execute()
283
+ * ```
284
+ *
285
+ * The generated SQL (PostgreSQL):
286
+ *
287
+ * ```sql
288
+ * select count("toy".*) as "num_toys"
289
+ * from "toy" inner join "pet" on "pet"."id" = "toy"."pet_id"
290
+ * ```
291
+ *
292
+ * You can limit table range to only tables participating in current query:
293
+ *
294
+ * ```ts
295
+ * db.selectFrom('toy')
296
+ * .innerJoin('pet', 'pet.id', 'toy.pet_id')
297
+ * .select(qb => qb.fn.countAll('toy').as('num_toys'))
137
298
  * .execute()
138
299
  * ```
139
300
  */
140
- count<O extends number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
301
+ countAll<O extends number | string | bigint, T extends TB = TB>(table: T): AggregateFunctionBuilder<DB, TB, O>;
302
+ countAll<O extends number | string | bigint>(): AggregateFunctionBuilder<DB, TB, O>;
141
303
  /**
142
304
  * Calls the `max` function for the column given as the argument.
143
305
  *
144
- * If this is used in a `select` statement the type of the selected expression
145
- * will be the referenced column's type.
306
+ * This sql function calculates the maximum value for a given column.
307
+ *
308
+ * For additional functionality such as distinct, filtering and window functions,
309
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
310
+ * returned when calling this function.
311
+ *
312
+ * If this function is used in a `select` statement, the type of the selected
313
+ * expression will be the referenced column's type. This is because the result
314
+ * is within the column's value range.
146
315
  *
147
316
  * ### Examples
148
317
  *
@@ -154,9 +323,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
154
323
  * .execute()
155
324
  * ```
156
325
  *
326
+ * The generated SQL (PostgreSQL):
327
+ *
328
+ * ```sql
329
+ * select max("price") as "max_price" from "toy"
330
+ * ```
331
+ *
332
+ * You can limit column range to only columns participating in current query:
333
+ *
334
+ * ```ts
335
+ * db.selectFrom('toy')
336
+ * .select(qb => qb.fn.max('price').as('max_price'))
337
+ * .execute()
338
+ * ```
339
+ *
157
340
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
158
341
  * was used. It is highly recommended to include null in the output type union
159
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
342
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
160
343
  * function.
161
344
  *
162
345
  * ```ts
@@ -172,8 +355,15 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
172
355
  /**
173
356
  * Calls the `min` function for the column given as the argument.
174
357
  *
175
- * If this is used in a `select` statement the type of the selected expression
176
- * will be the referenced column's type.
358
+ * This sql function calculates the minimum value for a given column.
359
+ *
360
+ * For additional functionality such as distinct, filtering and window functions,
361
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
362
+ * returned when calling this function.
363
+ *
364
+ * If this function is used in a `select` statement, the type of the selected
365
+ * expression will be the referenced column's type. This is because the result
366
+ * is within the column's value range.
177
367
  *
178
368
  * ### Examples
179
369
  *
@@ -185,9 +375,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
185
375
  * .execute()
186
376
  * ```
187
377
  *
378
+ * The generated SQL (PostgreSQL):
379
+ *
380
+ * ```sql
381
+ * select min("price") as "min_price" from "toy"
382
+ * ```
383
+ *
384
+ * You can limit column range to only columns participating in current query:
385
+ *
386
+ * ```ts
387
+ * db.selectFrom('toy')
388
+ * .select(qb => qb.fn.min('price').as('min_price'))
389
+ * .execute()
390
+ * ```
391
+ *
188
392
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
189
393
  * was used. It is highly recommended to include null in the output type union
190
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
394
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
191
395
  * function.
192
396
  *
193
397
  * ```ts
@@ -203,15 +407,45 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
203
407
  /**
204
408
  * Calls the `sum` function for the column given as the argument.
205
409
  *
206
- * If this is used in a `select` statement the type of the selected expression
207
- * will be `number | string | bigint` by default. This is because Kysely
208
- * can't know the type the db driver outputs. Sometimes the output can be larger
209
- * than the largest javascript number and a string is returned instead. Most
210
- * drivers allow you to configure the output type of large numbers and Kysely
211
- * can't know if you've done so.
410
+ * This sql function sums the values of a given column.
212
411
  *
213
- * You can specify the output type of the expression by providing
214
- * the type as the first type argument:
412
+ * For additional functionality such as distinct, filtering and window functions,
413
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
414
+ * returned when calling this function.
415
+ *
416
+ * ### Examples
417
+ *
418
+ * ```ts
419
+ * const { sum } = db.fn
420
+ *
421
+ * db.selectFrom('toy')
422
+ * .select(sum('price').as('total_price'))
423
+ * .execute()
424
+ * ```
425
+ *
426
+ * The generated SQL (PostgreSQL):
427
+ *
428
+ * ```sql
429
+ * select sum("price") as "total_price" from "toy"
430
+ * ```
431
+ *
432
+ * You can limit column range to only columns participating in current query:
433
+ *
434
+ * ```ts
435
+ * db.selectFrom('toy')
436
+ * .select(qb => qb.fn.sum('price').as('total_price'))
437
+ * .execute()
438
+ * ```
439
+ *
440
+ * If this function is used in a `select` statement, the type of the selected
441
+ * expression will be `number | string` by default. This is because Kysely can't know the
442
+ * type the db driver outputs. Sometimes the output can be larger than the largest
443
+ * javascript number and a string is returned instead. Most drivers allow you
444
+ * to configure the output type of large numbers and Kysely can't know if you've
445
+ * done so.
446
+ *
447
+ * You can specify the output type of the expression by providing the type as
448
+ * the first type argument:
215
449
  *
216
450
  * ```ts
217
451
  * const { sum } = db.fn
@@ -223,7 +457,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
223
457
  *
224
458
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
225
459
  * was used. It is highly recommended to include null in the output type union
226
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
460
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
227
461
  * function.
228
462
  *
229
463
  * ```ts