kysely 0.23.4 → 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.
- package/README.md +3 -1
- package/dist/cjs/dialect/database-introspector.d.ts +4 -2
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
- package/dist/cjs/operation-node/delete-query-node.d.ts +1 -1
- package/dist/cjs/operation-node/delete-query-node.js +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -2
- package/dist/cjs/parser/expression-parser.js +1 -1
- package/dist/cjs/parser/table-parser.d.ts +1 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -5
- package/dist/cjs/query-builder/delete-query-builder.js +1 -1
- package/dist/cjs/query-builder/function-module.d.ts +273 -39
- package/dist/cjs/query-builder/function-module.js +156 -34
- package/dist/cjs/query-builder/insert-query-builder.d.ts +4 -5
- package/dist/cjs/query-builder/insert-query-builder.js +0 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +8 -7
- package/dist/cjs/query-builder/update-query-builder.d.ts +5 -5
- package/dist/cjs/query-builder/update-query-builder.js +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.js +1 -1
- package/dist/cjs/query-creator.d.ts +29 -0
- package/dist/cjs/query-creator.js +2 -21
- package/dist/cjs/util/type-utils.d.ts +5 -4
- package/dist/esm/dialect/database-introspector.d.ts +4 -2
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/esm/operation-node/aggregate-function-node.js +2 -2
- package/dist/esm/operation-node/delete-query-node.d.ts +1 -1
- package/dist/esm/operation-node/delete-query-node.js +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +2 -2
- package/dist/esm/parser/expression-parser.js +2 -2
- package/dist/esm/parser/table-parser.d.ts +1 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/esm/query-builder/delete-query-builder.d.ts +5 -5
- package/dist/esm/query-builder/delete-query-builder.js +1 -1
- package/dist/esm/query-builder/function-module.d.ts +273 -39
- package/dist/esm/query-builder/function-module.js +156 -34
- package/dist/esm/query-builder/insert-query-builder.d.ts +4 -5
- package/dist/esm/query-builder/insert-query-builder.js +0 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +8 -7
- package/dist/esm/query-builder/update-query-builder.d.ts +5 -5
- package/dist/esm/query-builder/update-query-builder.js +1 -1
- package/dist/esm/query-compiler/default-query-compiler.js +1 -1
- package/dist/esm/query-creator.d.ts +29 -0
- package/dist/esm/query-creator.js +2 -21
- package/dist/esm/util/type-utils.d.ts +5 -4
- package/package.json +1 -1
|
@@ -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
|
-
*
|
|
45
|
-
*
|
|
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
|
|
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
|
|
127
|
+
* const { coalesce } = db.fn
|
|
84
128
|
*
|
|
85
|
-
* db.selectFrom('
|
|
86
|
-
* .select(coalesce(
|
|
87
|
-
* .where('
|
|
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 (
|
|
135
|
+
* The generated SQL (PostgreSQL):
|
|
92
136
|
*
|
|
93
137
|
* ```sql
|
|
94
|
-
* select coalesce(
|
|
138
|
+
* select coalesce("nickname", '<anonymous>') as "nickname"
|
|
139
|
+
* from "participant" where "room_id" = $1
|
|
95
140
|
* ```
|
|
96
141
|
*
|
|
97
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
153
|
+
* You can combine this function with other helpers in this module:
|
|
105
154
|
*
|
|
106
|
-
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* const { avg, coalesce } = db.fn
|
|
107
157
|
*
|
|
108
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
266
|
+
* const { countAll } = db.fn
|
|
126
267
|
*
|
|
127
268
|
* db.selectFrom('toy')
|
|
128
|
-
* .select(
|
|
269
|
+
* .select(countAll<number>().as('num_toys'))
|
|
129
270
|
* .execute()
|
|
130
271
|
* ```
|
|
131
272
|
*
|
|
132
|
-
*
|
|
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
|
-
* .
|
|
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
|
-
|
|
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
|
-
*
|
|
145
|
-
*
|
|
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
|
|
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
|
-
*
|
|
176
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
214
|
-
*
|
|
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
|
|
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
|