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.
- package/README.md +25 -25
- package/dist/cjs/dialect/database-introspector.d.ts +4 -2
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +21 -15
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +5 -3
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +8 -7
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/migration/migrator.d.ts +8 -3
- package/dist/cjs/migration/migrator.js +15 -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/create-index-node.d.ts +1 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +4 -1
- package/dist/cjs/operation-node/delete-query-node.js +11 -2
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +10 -1
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.js +1 -0
- package/dist/cjs/operation-node/using-node.d.ts +13 -0
- package/dist/cjs/operation-node/using-node.js +24 -0
- package/dist/cjs/parser/expression-parser.js +1 -1
- package/dist/cjs/parser/table-parser.d.ts +1 -0
- package/dist/cjs/parser/update-set-parser.d.ts +1 -1
- 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 +103 -11
- package/dist/cjs/query-builder/delete-query-builder.js +40 -9
- 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 +25 -10
- package/dist/cjs/query-builder/insert-query-builder.js +32 -9
- package/dist/cjs/query-builder/select-query-builder.d.ts +51 -34
- package/dist/cjs/query-builder/select-query-builder.js +53 -29
- package/dist/cjs/query-builder/update-query-builder.d.ts +26 -10
- package/dist/cjs/query-builder/update-query-builder.js +33 -9
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +12 -1
- package/dist/cjs/query-creator.d.ts +29 -0
- package/dist/cjs/query-creator.js +2 -21
- package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
- package/dist/cjs/raw-builder/raw-builder.js +8 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
- package/dist/cjs/schema/alter-table-builder.js +8 -2
- package/dist/cjs/schema/create-index-builder.d.ts +6 -0
- package/dist/cjs/schema/create-index-builder.js +13 -0
- package/dist/cjs/schema/create-table-builder.d.ts +6 -2
- package/dist/cjs/schema/create-table-builder.js +9 -3
- package/dist/cjs/util/type-utils.d.ts +20 -1
- package/dist/esm/dialect/database-introspector.d.ts +4 -2
- package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +21 -15
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +5 -3
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +8 -7
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/migration/migrator.d.ts +8 -3
- package/dist/esm/migration/migrator.js +15 -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/create-index-node.d.ts +1 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +4 -1
- package/dist/esm/operation-node/delete-query-node.js +11 -2
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +10 -1
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.js +1 -0
- package/dist/esm/operation-node/using-node.d.ts +13 -0
- package/dist/esm/operation-node/using-node.js +22 -0
- package/dist/esm/parser/expression-parser.js +2 -2
- package/dist/esm/parser/table-parser.d.ts +1 -0
- package/dist/esm/parser/update-set-parser.d.ts +1 -1
- 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 +103 -11
- package/dist/esm/query-builder/delete-query-builder.js +40 -9
- 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 +25 -10
- package/dist/esm/query-builder/insert-query-builder.js +33 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +51 -34
- package/dist/esm/query-builder/select-query-builder.js +53 -29
- package/dist/esm/query-builder/update-query-builder.d.ts +26 -10
- package/dist/esm/query-builder/update-query-builder.js +33 -9
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +12 -1
- package/dist/esm/query-creator.d.ts +29 -0
- package/dist/esm/query-creator.js +2 -21
- package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
- package/dist/esm/raw-builder/raw-builder.js +8 -2
- package/dist/esm/schema/alter-table-builder.d.ts +5 -1
- package/dist/esm/schema/alter-table-builder.js +8 -2
- package/dist/esm/schema/create-index-builder.d.ts +6 -0
- package/dist/esm/schema/create-index-builder.js +13 -0
- package/dist/esm/schema/create-table-builder.d.ts +6 -2
- package/dist/esm/schema/create-table-builder.js +9 -3
- package/dist/esm/util/type-utils.d.ts +20 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ exports.FunctionModule = void 0;
|
|
|
4
4
|
const aggregate_function_node_js_1 = require("../operation-node/aggregate-function-node.js");
|
|
5
5
|
const coalesce_parser_js_1 = require("../parser/coalesce-parser.js");
|
|
6
6
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
7
|
+
const select_parser_js_1 = require("../parser/select-parser.js");
|
|
7
8
|
const raw_builder_js_1 = require("../raw-builder/raw-builder.js");
|
|
8
9
|
const query_id_js_1 = require("../util/query-id.js");
|
|
9
10
|
const aggregate_function_builder_js_1 = require("./aggregate-function-builder.js");
|
|
@@ -44,6 +45,7 @@ class FunctionModule {
|
|
|
44
45
|
this.avg = this.avg.bind(this);
|
|
45
46
|
this.coalesce = this.coalesce.bind(this);
|
|
46
47
|
this.count = this.count.bind(this);
|
|
48
|
+
this.countAll = this.countAll.bind(this);
|
|
47
49
|
this.max = this.max.bind(this);
|
|
48
50
|
this.min = this.min.bind(this);
|
|
49
51
|
this.sum = this.sum.bind(this);
|
|
@@ -51,8 +53,38 @@ class FunctionModule {
|
|
|
51
53
|
/**
|
|
52
54
|
* Calls the `avg` function for the column given as the argument.
|
|
53
55
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
+
* This sql function calculates the average value for a given column.
|
|
57
|
+
*
|
|
58
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
59
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
60
|
+
* returned when calling this function.
|
|
61
|
+
*
|
|
62
|
+
* ### Examples
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* const { avg } = db.fn
|
|
66
|
+
*
|
|
67
|
+
* db.selectFrom('toy')
|
|
68
|
+
* .select(avg('price').as('avg_price'))
|
|
69
|
+
* .execute()
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* The generated SQL (PostgreSQL):
|
|
73
|
+
*
|
|
74
|
+
* ```sql
|
|
75
|
+
* select avg("price") as "avg_price" from "toy"
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* You can limit column range to only columns participating in current query:
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* db.selectFrom('toy')
|
|
82
|
+
* .select(qb => qb.fn.avg('price').as('avg_price'))
|
|
83
|
+
* .execute()
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
87
|
+
* expression will be `number | string` by default. This is because Kysely can't know the
|
|
56
88
|
* type the db driver outputs. Sometimes the output can be larger than the largest
|
|
57
89
|
* javascript number and a string is returned instead. Most drivers allow you
|
|
58
90
|
* to configure the output type of large numbers and Kysely can't know if you've
|
|
@@ -71,7 +103,7 @@ class FunctionModule {
|
|
|
71
103
|
*
|
|
72
104
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
73
105
|
* was used. It is highly recommended to include null in the output type union
|
|
74
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
106
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
75
107
|
* function.
|
|
76
108
|
*
|
|
77
109
|
* ```ts
|
|
@@ -90,36 +122,66 @@ class FunctionModule {
|
|
|
90
122
|
/**
|
|
91
123
|
* Calls the `coalesce` function for given arguments.
|
|
92
124
|
*
|
|
93
|
-
* This function returns the first non-null value from left to right, commonly
|
|
125
|
+
* This sql function returns the first non-null value from left to right, commonly
|
|
94
126
|
* used to provide a default scalar for nullable columns or functions.
|
|
95
127
|
*
|
|
128
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
129
|
+
* expression is inferred in the same manner that the sql function computes.
|
|
130
|
+
* A union of arguments' types - if a non-nullable argument exists, it stops
|
|
131
|
+
* there (ignoring any further arguments' types) and exludes null from the final
|
|
132
|
+
* union type.
|
|
133
|
+
*
|
|
134
|
+
* `(string | null, number | null)` is inferred as `string | number | null`.
|
|
135
|
+
*
|
|
136
|
+
* `(string | null, number, Date | null)` is inferred as `string | number`.
|
|
137
|
+
*
|
|
138
|
+
* `(number, string | null)` is inferred as `number`.
|
|
139
|
+
*
|
|
140
|
+
* ### Examples
|
|
141
|
+
*
|
|
96
142
|
* ```ts
|
|
97
|
-
* const { coalesce
|
|
143
|
+
* const { coalesce } = db.fn
|
|
98
144
|
*
|
|
99
|
-
* db.selectFrom('
|
|
100
|
-
* .select(coalesce(
|
|
101
|
-
* .where('
|
|
145
|
+
* db.selectFrom('participant')
|
|
146
|
+
* .select(coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname'))
|
|
147
|
+
* .where('room_id', '=', roomId)
|
|
102
148
|
* .execute()
|
|
103
149
|
* ```
|
|
104
150
|
*
|
|
105
|
-
* The generated SQL (
|
|
151
|
+
* The generated SQL (PostgreSQL):
|
|
106
152
|
*
|
|
107
153
|
* ```sql
|
|
108
|
-
* select coalesce(
|
|
154
|
+
* select coalesce("nickname", '<anonymous>') as "nickname"
|
|
155
|
+
* from "participant" where "room_id" = $1
|
|
109
156
|
* ```
|
|
110
157
|
*
|
|
111
|
-
*
|
|
112
|
-
* is inferred in the same manner that the function computes. A union of arguments'
|
|
113
|
-
* types - if a non-nullable argument exists, it stops there (ignoring any further
|
|
114
|
-
* arguments' types) and exludes null from the final union type.
|
|
158
|
+
* You can limit column range to only columns participating in current query:
|
|
115
159
|
*
|
|
116
|
-
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* db.selectFrom('participant')
|
|
162
|
+
* .select(qb =>
|
|
163
|
+
* qb.fn.coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname')
|
|
164
|
+
* )
|
|
165
|
+
* .where('room_id', '=', roomId)
|
|
166
|
+
* .execute()
|
|
167
|
+
* ```
|
|
117
168
|
*
|
|
118
|
-
*
|
|
169
|
+
* You can combine this function with other helpers in this module:
|
|
119
170
|
*
|
|
120
|
-
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* const { avg, coalesce } = db.fn
|
|
121
173
|
*
|
|
122
|
-
*
|
|
174
|
+
* db.selectFrom('person')
|
|
175
|
+
* .select(coalesce(avg<number | null>('age'), sql<number>`0`).as('avg_age'))
|
|
176
|
+
* .where('first_name', '=', 'Jennifer')
|
|
177
|
+
* .execute()
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* The generated SQL (PostgreSQL):
|
|
181
|
+
*
|
|
182
|
+
* ```sql
|
|
183
|
+
* select coalesce(avg("age"), 0) as "avg_age" from "person" where "first_name" = $1
|
|
184
|
+
* ```
|
|
123
185
|
*/
|
|
124
186
|
coalesce(value, ...otherValues) {
|
|
125
187
|
return new raw_builder_js_1.RawBuilder({
|
|
@@ -130,11 +192,36 @@ class FunctionModule {
|
|
|
130
192
|
/**
|
|
131
193
|
* Calls the `count` function for the column given as the argument.
|
|
132
194
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
195
|
+
* When called with a column as argument, this sql function counts the number of rows where there
|
|
196
|
+
* is a non-null value in that column.
|
|
197
|
+
*
|
|
198
|
+
* For counting all rows nulls included (`count(*)`), see {@link countAll}.
|
|
199
|
+
*
|
|
200
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
201
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
202
|
+
* returned when calling this function.
|
|
203
|
+
*
|
|
204
|
+
* ### Examples
|
|
205
|
+
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* const { count } = db.fn
|
|
208
|
+
*
|
|
209
|
+
* db.selectFrom('toy')
|
|
210
|
+
* .select(count('id').as('num_toys'))
|
|
211
|
+
* .execute()
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* The generated SQL (PostgreSQL):
|
|
215
|
+
*
|
|
216
|
+
* ```sql
|
|
217
|
+
* select count("id") as "num_toys" from "toy"
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
221
|
+
* expression will be `number | string | bigint` by default. This is because
|
|
222
|
+
* Kysely can't know the type the db driver outputs. Sometimes the output can
|
|
223
|
+
* be larger than the largest javascript number and a string is returned instead.
|
|
224
|
+
* Most drivers allow you to configure the output type of large numbers and Kysely
|
|
138
225
|
* can't know if you've done so.
|
|
139
226
|
*
|
|
140
227
|
* You can specify the output type of the expression by providing
|
|
@@ -148,11 +235,11 @@ class FunctionModule {
|
|
|
148
235
|
* .execute()
|
|
149
236
|
* ```
|
|
150
237
|
*
|
|
151
|
-
* You can limit column range:
|
|
238
|
+
* You can limit column range to only columns participating in current query:
|
|
152
239
|
*
|
|
153
240
|
* ```ts
|
|
154
241
|
* db.selectFrom('toy')
|
|
155
|
-
* .select(qb => qb.fn.count
|
|
242
|
+
* .select(qb => qb.fn.count('id').as('num_toys'))
|
|
156
243
|
* .execute()
|
|
157
244
|
* ```
|
|
158
245
|
*/
|
|
@@ -161,6 +248,11 @@ class FunctionModule {
|
|
|
161
248
|
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('count', (0, reference_parser_js_1.parseSimpleReferenceExpression)(column)),
|
|
162
249
|
});
|
|
163
250
|
}
|
|
251
|
+
countAll(table) {
|
|
252
|
+
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
253
|
+
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('count', (0, select_parser_js_1.parseSelectAll)(table)[0].selection),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
164
256
|
max(column) {
|
|
165
257
|
return new aggregate_function_builder_js_1.AggregateFunctionBuilder({
|
|
166
258
|
aggregateFunctionNode: aggregate_function_node_js_1.AggregateFunctionNode.create('max', (0, reference_parser_js_1.parseSimpleReferenceExpression)(column)),
|
|
@@ -174,15 +266,45 @@ class FunctionModule {
|
|
|
174
266
|
/**
|
|
175
267
|
* Calls the `sum` function for the column given as the argument.
|
|
176
268
|
*
|
|
177
|
-
*
|
|
178
|
-
* will be `number | string | bigint` by default. This is because Kysely
|
|
179
|
-
* can't know the type the db driver outputs. Sometimes the output can be larger
|
|
180
|
-
* than the largest javascript number and a string is returned instead. Most
|
|
181
|
-
* drivers allow you to configure the output type of large numbers and Kysely
|
|
182
|
-
* can't know if you've done so.
|
|
269
|
+
* This sql function sums the values of a given column.
|
|
183
270
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
271
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
272
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
273
|
+
* returned when calling this function.
|
|
274
|
+
*
|
|
275
|
+
* ### Examples
|
|
276
|
+
*
|
|
277
|
+
* ```ts
|
|
278
|
+
* const { sum } = db.fn
|
|
279
|
+
*
|
|
280
|
+
* db.selectFrom('toy')
|
|
281
|
+
* .select(sum('price').as('total_price'))
|
|
282
|
+
* .execute()
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* The generated SQL (PostgreSQL):
|
|
286
|
+
*
|
|
287
|
+
* ```sql
|
|
288
|
+
* select sum("price") as "total_price" from "toy"
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* You can limit column range to only columns participating in current query:
|
|
292
|
+
*
|
|
293
|
+
* ```ts
|
|
294
|
+
* db.selectFrom('toy')
|
|
295
|
+
* .select(qb => qb.fn.sum('price').as('total_price'))
|
|
296
|
+
* .execute()
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
300
|
+
* expression will be `number | string` by default. This is because Kysely can't know the
|
|
301
|
+
* type the db driver outputs. Sometimes the output can be larger than the largest
|
|
302
|
+
* javascript number and a string is returned instead. Most drivers allow you
|
|
303
|
+
* to configure the output type of large numbers and Kysely can't know if you've
|
|
304
|
+
* done so.
|
|
305
|
+
*
|
|
306
|
+
* You can specify the output type of the expression by providing the type as
|
|
307
|
+
* the first type argument:
|
|
186
308
|
*
|
|
187
309
|
* ```ts
|
|
188
310
|
* const { sum } = db.fn
|
|
@@ -194,7 +316,7 @@ class FunctionModule {
|
|
|
194
316
|
*
|
|
195
317
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
196
318
|
* was used. It is highly recommended to include null in the output type union
|
|
197
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
319
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
198
320
|
* function.
|
|
199
321
|
*
|
|
200
322
|
* ```ts
|
|
@@ -3,7 +3,7 @@ import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
|
3
3
|
import { SelectExpression } from '../parser/select-parser.js';
|
|
4
4
|
import { InsertObject } from '../parser/insert-values-parser.js';
|
|
5
5
|
import { InsertQueryNode } from '../operation-node/insert-query-node.js';
|
|
6
|
-
import { MergePartial,
|
|
6
|
+
import { MergePartial, SimplifyResult, SimplifySingleResult } from '../util/type-utils.js';
|
|
7
7
|
import { UpdateObject } from '../parser/update-set-parser.js';
|
|
8
8
|
import { Compilable } from '../util/compilable.js';
|
|
9
9
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
@@ -259,7 +259,6 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
259
259
|
* .doUpdateSet({ species: 'hamster' })
|
|
260
260
|
* )
|
|
261
261
|
* .execute()
|
|
262
|
-
* .execute()
|
|
263
262
|
* ```
|
|
264
263
|
*
|
|
265
264
|
* The generated SQL (PostgreSQL):
|
|
@@ -456,7 +455,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
456
455
|
* Simply calls the given function passing `this` as the only argument.
|
|
457
456
|
*
|
|
458
457
|
* If you want to conditionally call a method on `this`, see
|
|
459
|
-
* the {@link if} method.
|
|
458
|
+
* the {@link $if} method.
|
|
460
459
|
*
|
|
461
460
|
* ### Examples
|
|
462
461
|
*
|
|
@@ -470,10 +469,14 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
470
469
|
*
|
|
471
470
|
* db.updateTable('person')
|
|
472
471
|
* .set(values)
|
|
473
|
-
*
|
|
472
|
+
* .$call(log)
|
|
474
473
|
* .execute()
|
|
475
474
|
* ```
|
|
476
475
|
*/
|
|
476
|
+
$call<T>(func: (qb: this) => T): T;
|
|
477
|
+
/**
|
|
478
|
+
* @deprecated Use `$call` instead
|
|
479
|
+
*/
|
|
477
480
|
call<T>(func: (qb: this) => T): T;
|
|
478
481
|
/**
|
|
479
482
|
* Call `func(this)` if `condition` is true.
|
|
@@ -493,7 +496,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
493
496
|
* .insertInto('person')
|
|
494
497
|
* .values(values)
|
|
495
498
|
* .returning(['id', 'first_name'])
|
|
496
|
-
*
|
|
499
|
+
* .$if(returnLastName, (qb) => qb.returning('last_name'))
|
|
497
500
|
* .executeTakeFirstOrThrow()
|
|
498
501
|
* }
|
|
499
502
|
* ```
|
|
@@ -510,6 +513,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
510
513
|
* }
|
|
511
514
|
* ```
|
|
512
515
|
*/
|
|
516
|
+
$if<O2>(condition: boolean, func: (qb: this) => InsertQueryBuilder<DB, TB, O2>): InsertQueryBuilder<DB, TB, O2 extends InsertResult ? InsertResult : O extends InsertResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
517
|
+
/**
|
|
518
|
+
* @deprecated Use `$if` instead
|
|
519
|
+
*/
|
|
513
520
|
if<O2>(condition: boolean, func: (qb: this) => InsertQueryBuilder<DB, TB, O2>): InsertQueryBuilder<DB, TB, O2 extends InsertResult ? InsertResult : O extends InsertResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
514
521
|
/**
|
|
515
522
|
* Change the output type of the query.
|
|
@@ -517,6 +524,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
517
524
|
* You should only use this method as the last resort if the types
|
|
518
525
|
* don't support your use case.
|
|
519
526
|
*/
|
|
527
|
+
$castTo<T>(): InsertQueryBuilder<DB, TB, T>;
|
|
528
|
+
/**
|
|
529
|
+
* @deprecated Use `$castTo` instead.
|
|
530
|
+
*/
|
|
520
531
|
castTo<T>(): InsertQueryBuilder<DB, TB, T>;
|
|
521
532
|
/**
|
|
522
533
|
* Asserts that query's output row type equals the given type `T`.
|
|
@@ -546,19 +557,23 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
546
557
|
* .insertInto('person')
|
|
547
558
|
* .values(person)
|
|
548
559
|
* .returning('id')
|
|
549
|
-
*
|
|
560
|
+
* .$assertType<{ id: string }>()
|
|
550
561
|
* )
|
|
551
562
|
* .with('new_pet', (qb) => qb
|
|
552
563
|
* .insertInto('pet')
|
|
553
564
|
* .values({ owner_id: (eb) => eb.selectFrom('new_person').select('id'), ...pet })
|
|
554
565
|
* .returning(['name as pet_name', 'species'])
|
|
555
|
-
*
|
|
566
|
+
* .$assertType<{ pet_name: string, species: Species }>()
|
|
556
567
|
* )
|
|
557
568
|
* .selectFrom(['new_person', 'new_pet'])
|
|
558
569
|
* .selectAll()
|
|
559
570
|
* .executeTakeFirstOrThrow()
|
|
560
571
|
* ```
|
|
561
572
|
*/
|
|
573
|
+
$assertType<T extends O>(): O extends T ? InsertQueryBuilder<DB, TB, T> : KyselyTypeError<`$assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
574
|
+
/**
|
|
575
|
+
* @deprecated Use `$assertType` instead.
|
|
576
|
+
*/
|
|
562
577
|
assertType<T extends O>(): O extends T ? InsertQueryBuilder<DB, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
563
578
|
/**
|
|
564
579
|
* Returns a copy of this InsertQueryBuilder instance with the given plugin installed.
|
|
@@ -571,12 +586,12 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
571
586
|
*
|
|
572
587
|
* Also see the {@link executeTakeFirst} and {@link executeTakeFirstOrThrow} methods.
|
|
573
588
|
*/
|
|
574
|
-
execute(): Promise<O[]>;
|
|
589
|
+
execute(): Promise<SimplifyResult<O>[]>;
|
|
575
590
|
/**
|
|
576
591
|
* Executes the query and returns the first result or undefined if
|
|
577
592
|
* the query returned no result.
|
|
578
593
|
*/
|
|
579
|
-
executeTakeFirst(): Promise<
|
|
594
|
+
executeTakeFirst(): Promise<SimplifySingleResult<O>>;
|
|
580
595
|
/**
|
|
581
596
|
* Executes the query and returns the first result or throws if
|
|
582
597
|
* the query returned no result.
|
|
@@ -585,7 +600,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
585
600
|
* provide a custom error class as the only argument to throw a different
|
|
586
601
|
* error.
|
|
587
602
|
*/
|
|
588
|
-
executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<O
|
|
603
|
+
executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<SimplifyResult<O>>;
|
|
589
604
|
/**
|
|
590
605
|
* Executes query with `explain` statement before `insert` keyword.
|
|
591
606
|
*
|
|
@@ -161,7 +161,6 @@ class InsertQueryBuilder {
|
|
|
161
161
|
* .doUpdateSet({ species: 'hamster' })
|
|
162
162
|
* )
|
|
163
163
|
* .execute()
|
|
164
|
-
* .execute()
|
|
165
164
|
* ```
|
|
166
165
|
*
|
|
167
166
|
* The generated SQL (PostgreSQL):
|
|
@@ -320,7 +319,7 @@ class InsertQueryBuilder {
|
|
|
320
319
|
* Simply calls the given function passing `this` as the only argument.
|
|
321
320
|
*
|
|
322
321
|
* If you want to conditionally call a method on `this`, see
|
|
323
|
-
* the {@link if} method.
|
|
322
|
+
* the {@link $if} method.
|
|
324
323
|
*
|
|
325
324
|
* ### Examples
|
|
326
325
|
*
|
|
@@ -334,13 +333,19 @@ class InsertQueryBuilder {
|
|
|
334
333
|
*
|
|
335
334
|
* db.updateTable('person')
|
|
336
335
|
* .set(values)
|
|
337
|
-
*
|
|
336
|
+
* .$call(log)
|
|
338
337
|
* .execute()
|
|
339
338
|
* ```
|
|
340
339
|
*/
|
|
341
|
-
call(func) {
|
|
340
|
+
$call(func) {
|
|
342
341
|
return func(this);
|
|
343
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* @deprecated Use `$call` instead
|
|
345
|
+
*/
|
|
346
|
+
call(func) {
|
|
347
|
+
return this.$call(func);
|
|
348
|
+
}
|
|
344
349
|
/**
|
|
345
350
|
* Call `func(this)` if `condition` is true.
|
|
346
351
|
*
|
|
@@ -359,7 +364,7 @@ class InsertQueryBuilder {
|
|
|
359
364
|
* .insertInto('person')
|
|
360
365
|
* .values(values)
|
|
361
366
|
* .returning(['id', 'first_name'])
|
|
362
|
-
*
|
|
367
|
+
* .$if(returnLastName, (qb) => qb.returning('last_name'))
|
|
363
368
|
* .executeTakeFirstOrThrow()
|
|
364
369
|
* }
|
|
365
370
|
* ```
|
|
@@ -376,7 +381,7 @@ class InsertQueryBuilder {
|
|
|
376
381
|
* }
|
|
377
382
|
* ```
|
|
378
383
|
*/
|
|
379
|
-
if(condition, func) {
|
|
384
|
+
$if(condition, func) {
|
|
380
385
|
if (condition) {
|
|
381
386
|
return func(this);
|
|
382
387
|
}
|
|
@@ -384,15 +389,27 @@ class InsertQueryBuilder {
|
|
|
384
389
|
...this.#props,
|
|
385
390
|
});
|
|
386
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* @deprecated Use `$if` instead
|
|
394
|
+
*/
|
|
395
|
+
if(condition, func) {
|
|
396
|
+
return this.$if(condition, func);
|
|
397
|
+
}
|
|
387
398
|
/**
|
|
388
399
|
* Change the output type of the query.
|
|
389
400
|
*
|
|
390
401
|
* You should only use this method as the last resort if the types
|
|
391
402
|
* don't support your use case.
|
|
392
403
|
*/
|
|
393
|
-
castTo() {
|
|
404
|
+
$castTo() {
|
|
394
405
|
return new InsertQueryBuilder(this.#props);
|
|
395
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* @deprecated Use `$castTo` instead.
|
|
409
|
+
*/
|
|
410
|
+
castTo() {
|
|
411
|
+
return this.$castTo();
|
|
412
|
+
}
|
|
396
413
|
/**
|
|
397
414
|
* Asserts that query's output row type equals the given type `T`.
|
|
398
415
|
*
|
|
@@ -421,19 +438,25 @@ class InsertQueryBuilder {
|
|
|
421
438
|
* .insertInto('person')
|
|
422
439
|
* .values(person)
|
|
423
440
|
* .returning('id')
|
|
424
|
-
*
|
|
441
|
+
* .$assertType<{ id: string }>()
|
|
425
442
|
* )
|
|
426
443
|
* .with('new_pet', (qb) => qb
|
|
427
444
|
* .insertInto('pet')
|
|
428
445
|
* .values({ owner_id: (eb) => eb.selectFrom('new_person').select('id'), ...pet })
|
|
429
446
|
* .returning(['name as pet_name', 'species'])
|
|
430
|
-
*
|
|
447
|
+
* .$assertType<{ pet_name: string, species: Species }>()
|
|
431
448
|
* )
|
|
432
449
|
* .selectFrom(['new_person', 'new_pet'])
|
|
433
450
|
* .selectAll()
|
|
434
451
|
* .executeTakeFirstOrThrow()
|
|
435
452
|
* ```
|
|
436
453
|
*/
|
|
454
|
+
$assertType() {
|
|
455
|
+
return new InsertQueryBuilder(this.#props);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* @deprecated Use `$assertType` instead.
|
|
459
|
+
*/
|
|
437
460
|
assertType() {
|
|
438
461
|
return new InsertQueryBuilder(this.#props);
|
|
439
462
|
}
|