kysely 0.27.0 → 0.27.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 (68) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/dialect/mssql/mssql-introspector.js +8 -6
  3. package/dist/cjs/expression/expression-wrapper.d.ts +13 -3
  4. package/dist/cjs/expression/expression-wrapper.js +12 -0
  5. package/dist/cjs/migration/migrator.d.ts +19 -2
  6. package/dist/cjs/migration/migrator.js +77 -43
  7. package/dist/cjs/operation-node/insert-query-node.d.ts +1 -0
  8. package/dist/cjs/operation-node/limit-node.d.ts +2 -3
  9. package/dist/cjs/operation-node/limit-node.js +1 -2
  10. package/dist/cjs/operation-node/offset-node.d.ts +2 -3
  11. package/dist/cjs/operation-node/offset-node.js +1 -2
  12. package/dist/cjs/operation-node/operation-node-transformer.js +2 -0
  13. package/dist/cjs/operation-node/select-modifier-node.d.ts +2 -1
  14. package/dist/cjs/operation-node/select-modifier-node.js +2 -1
  15. package/dist/cjs/query-builder/aggregate-function-builder.d.ts +17 -0
  16. package/dist/cjs/query-builder/aggregate-function-builder.js +21 -0
  17. package/dist/cjs/query-builder/case-builder.d.ts +2 -2
  18. package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -4
  19. package/dist/cjs/query-builder/delete-query-builder.js +4 -3
  20. package/dist/cjs/query-builder/function-module.d.ts +1 -1
  21. package/dist/cjs/query-builder/insert-query-builder.d.ts +9 -6
  22. package/dist/cjs/query-builder/insert-query-builder.js +173 -2
  23. package/dist/cjs/query-builder/json-path-builder.d.ts +2 -1
  24. package/dist/cjs/query-builder/json-path-builder.js +3 -0
  25. package/dist/cjs/query-builder/select-query-builder.d.ts +11 -9
  26. package/dist/cjs/query-builder/select-query-builder.js +12 -10
  27. package/dist/cjs/query-builder/update-query-builder.d.ts +5 -6
  28. package/dist/cjs/query-builder/update-query-builder.js +2 -2
  29. package/dist/cjs/query-compiler/default-query-compiler.js +8 -0
  30. package/dist/cjs/raw-builder/raw-builder.d.ts +11 -1
  31. package/dist/cjs/raw-builder/raw-builder.js +3 -0
  32. package/dist/cjs/raw-builder/sql.js +9 -2
  33. package/dist/cjs/util/object-utils.d.ts +1 -1
  34. package/dist/cjs/util/object-utils.js +1 -1
  35. package/dist/esm/dialect/mssql/mssql-introspector.js +8 -6
  36. package/dist/esm/expression/expression-wrapper.d.ts +13 -3
  37. package/dist/esm/expression/expression-wrapper.js +12 -0
  38. package/dist/esm/migration/migrator.d.ts +19 -2
  39. package/dist/esm/migration/migrator.js +76 -42
  40. package/dist/esm/operation-node/insert-query-node.d.ts +1 -0
  41. package/dist/esm/operation-node/limit-node.d.ts +2 -3
  42. package/dist/esm/operation-node/limit-node.js +1 -2
  43. package/dist/esm/operation-node/offset-node.d.ts +2 -3
  44. package/dist/esm/operation-node/offset-node.js +1 -2
  45. package/dist/esm/operation-node/operation-node-transformer.js +2 -0
  46. package/dist/esm/operation-node/select-modifier-node.d.ts +2 -1
  47. package/dist/esm/operation-node/select-modifier-node.js +2 -1
  48. package/dist/esm/query-builder/aggregate-function-builder.d.ts +17 -0
  49. package/dist/esm/query-builder/aggregate-function-builder.js +21 -0
  50. package/dist/esm/query-builder/case-builder.d.ts +2 -2
  51. package/dist/esm/query-builder/delete-query-builder.d.ts +5 -4
  52. package/dist/esm/query-builder/delete-query-builder.js +4 -3
  53. package/dist/esm/query-builder/function-module.d.ts +1 -1
  54. package/dist/esm/query-builder/insert-query-builder.d.ts +9 -6
  55. package/dist/esm/query-builder/insert-query-builder.js +173 -2
  56. package/dist/esm/query-builder/json-path-builder.d.ts +2 -1
  57. package/dist/esm/query-builder/json-path-builder.js +3 -0
  58. package/dist/esm/query-builder/select-query-builder.d.ts +11 -9
  59. package/dist/esm/query-builder/select-query-builder.js +13 -11
  60. package/dist/esm/query-builder/update-query-builder.d.ts +5 -6
  61. package/dist/esm/query-builder/update-query-builder.js +2 -2
  62. package/dist/esm/query-compiler/default-query-compiler.js +8 -0
  63. package/dist/esm/raw-builder/raw-builder.d.ts +11 -1
  64. package/dist/esm/raw-builder/raw-builder.js +3 -0
  65. package/dist/esm/raw-builder/sql.js +9 -2
  66. package/dist/esm/util/object-utils.d.ts +1 -1
  67. package/dist/esm/util/object-utils.js +1 -1
  68. package/package.json +5 -11
@@ -138,7 +138,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
138
138
  * from "person"
139
139
  * ```
140
140
  */
141
- agg<O, RE extends ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
141
+ agg<O, RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
142
142
  /**
143
143
  * Calls the `avg` function for the column or expression given as the argument.
144
144
  *
@@ -1,7 +1,7 @@
1
1
  import { OperationNodeSource } from '../operation-node/operation-node-source.js';
2
2
  import { CompiledQuery } from '../query-compiler/compiled-query.js';
3
3
  import { SelectExpression, SelectCallback } from '../parser/select-parser.js';
4
- import { InsertObjectOrList, InsertObjectOrListFactory } from '../parser/insert-values-parser.js';
4
+ import { InsertExpression } from '../parser/insert-values-parser.js';
5
5
  import { InsertQueryNode } from '../operation-node/insert-query-node.js';
6
6
  import { QueryNode } from '../operation-node/query-node.js';
7
7
  import { NarrowPartial, SimplifyResult, SimplifySingleResult } from '../util/type-utils.js';
@@ -184,8 +184,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
184
184
  * }))
185
185
  * ```
186
186
  */
187
- values(insert: InsertObjectOrList<DB, TB>): InsertQueryBuilder<DB, TB, O>;
188
- values(insert: InsertObjectOrListFactory<DB, TB>): InsertQueryBuilder<DB, TB, O>;
187
+ values(insert: InsertExpression<DB, TB>): InsertQueryBuilder<DB, TB, O>;
189
188
  /**
190
189
  * Sets the columns to insert.
191
190
  *
@@ -240,6 +239,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
240
239
  * ```
241
240
  */
242
241
  expression(expression: ExpressionOrFactory<DB, TB, any>): InsertQueryBuilder<DB, TB, O>;
242
+ /**
243
+ * Creates an `insert into "person" default values` query.
244
+ */
245
+ defaultValues(): InsertQueryBuilder<DB, TB, O>;
243
246
  /**
244
247
  * Changes an `insert into` query to an `insert ignore into` query.
245
248
  *
@@ -563,10 +566,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
563
566
  /**
564
567
  * Change the output type of the query.
565
568
  *
566
- * You should only use this method as the last resort if the types
567
- * don't support your use case.
569
+ * This method call doesn't change the SQL in any way. This methods simply
570
+ * returns a copy of this `InsertQueryBuilder` with a new output type.
568
571
  */
569
- $castTo<T>(): InsertQueryBuilder<DB, TB, T>;
572
+ $castTo<C>(): InsertQueryBuilder<DB, TB, C>;
570
573
  /**
571
574
  * Narrows (parts of) the output type of the query.
572
575
  *
@@ -20,6 +20,166 @@ class InsertQueryBuilder {
20
20
  constructor(props) {
21
21
  this.#props = (0, object_utils_js_1.freeze)(props);
22
22
  }
23
+ /**
24
+ * Sets the values to insert for an {@link Kysely.insertInto | insert} query.
25
+ *
26
+ * This method takes an object whose keys are column names and values are
27
+ * values to insert. In addition to the column's type, the values can be
28
+ * raw {@link sql} snippets or select queries.
29
+ *
30
+ * You must provide all fields you haven't explicitly marked as nullable
31
+ * or optional using {@link Generated} or {@link ColumnType}.
32
+ *
33
+ * The return value of an `insert` query is an instance of {@link InsertResult}. The
34
+ * {@link InsertResult.insertId | insertId} field holds the auto incremented primary
35
+ * key if the database returned one.
36
+ *
37
+ * On PostgreSQL and some other dialects, you need to call `returning` to get
38
+ * something out of the query.
39
+ *
40
+ * Also see the {@link expression} method for inserting the result of a select
41
+ * query or any other expression.
42
+ *
43
+ * ### Examples
44
+ *
45
+ * <!-- siteExample("insert", "Single row", 10) -->
46
+ *
47
+ * Insert a single row:
48
+ *
49
+ * ```ts
50
+ * const result = await db
51
+ * .insertInto('person')
52
+ * .values({
53
+ * first_name: 'Jennifer',
54
+ * last_name: 'Aniston',
55
+ * age: 40
56
+ * })
57
+ * .executeTakeFirst()
58
+ *
59
+ * // `insertId` is only available on dialects that
60
+ * // automatically return the id of the inserted row
61
+ * // such as MySQL and SQLite. On PostgreSQL, for example,
62
+ * // you need to add a `returning` clause to the query to
63
+ * // get anything out. See the "returning data" example.
64
+ * console.log(result.insertId)
65
+ * ```
66
+ *
67
+ * The generated SQL (MySQL):
68
+ *
69
+ * ```sql
70
+ * insert into `person` (`first_name`, `last_name`, `age`) values (?, ?, ?)
71
+ * ```
72
+ *
73
+ * <!-- siteExample("insert", "Multiple rows", 20) -->
74
+ *
75
+ * On dialects that support it (for example PostgreSQL) you can insert multiple
76
+ * rows by providing an array. Note that the return value is once again very
77
+ * dialect-specific. Some databases may only return the id of the *last* inserted
78
+ * row and some return nothing at all unless you call `returning`.
79
+ *
80
+ * ```ts
81
+ * await db
82
+ * .insertInto('person')
83
+ * .values([{
84
+ * first_name: 'Jennifer',
85
+ * last_name: 'Aniston',
86
+ * age: 40,
87
+ * }, {
88
+ * first_name: 'Arnold',
89
+ * last_name: 'Schwarzenegger',
90
+ * age: 70,
91
+ * }])
92
+ * .execute()
93
+ * ```
94
+ *
95
+ * The generated SQL (PostgreSQL):
96
+ *
97
+ * ```sql
98
+ * insert into "person" ("first_name", "last_name", "age") values (($1, $2, $3), ($4, $5, $6))
99
+ * ```
100
+ *
101
+ * <!-- siteExample("insert", "Returning data", 30) -->
102
+ *
103
+ * On supported dialects like PostgreSQL you need to chain `returning` to the query to get
104
+ * the inserted row's columns (or any other expression) as the return value. `returning`
105
+ * works just like `select`. Refer to `select` method's examples and documentation for
106
+ * more info.
107
+ *
108
+ * ```ts
109
+ * const result = await db
110
+ * .insertInto('person')
111
+ * .values({
112
+ * first_name: 'Jennifer',
113
+ * last_name: 'Aniston',
114
+ * age: 40,
115
+ * })
116
+ * .returning(['id', 'first_name as name'])
117
+ * .executeTakeFirstOrThrow()
118
+ * ```
119
+ *
120
+ * The generated SQL (PostgreSQL):
121
+ *
122
+ * ```sql
123
+ * insert into "person" ("first_name", "last_name", "age") values ($1, $2, $3) returning "id", "first_name" as "name"
124
+ * ```
125
+ *
126
+ * <!-- siteExample("insert", "Complex values", 40) -->
127
+ *
128
+ * In addition to primitives, the values can also be arbitrary expressions.
129
+ * You can build the expressions by using a callback and calling the methods
130
+ * on the expression builder passed to it:
131
+ *
132
+ * ```ts
133
+ * import { sql } from 'kysely'
134
+ *
135
+ * const ani = "Ani"
136
+ * const ston = "ston"
137
+ *
138
+ * const result = await db
139
+ * .insertInto('person')
140
+ * .values(({ ref, selectFrom, fn }) => ({
141
+ * first_name: 'Jennifer',
142
+ * last_name: sql`concat(${ani}, ${ston})`,
143
+ * middle_name: ref('first_name'),
144
+ * age: selectFrom('person')
145
+ * .select(fn.avg<number>('age')
146
+ * .as('avg_age')),
147
+ * }))
148
+ * .executeTakeFirst()
149
+ * ```
150
+ *
151
+ * The generated SQL (PostgreSQL):
152
+ *
153
+ * ```sql
154
+ * insert into "person" (
155
+ * "first_name",
156
+ * "last_name",
157
+ * "middle_name",
158
+ * "age"
159
+ * )
160
+ * values (
161
+ * $1,
162
+ * concat($2, $3),
163
+ * "first_name",
164
+ * (select avg("age") as "avg_age" from "person")
165
+ * )
166
+ * ```
167
+ *
168
+ * You can also use the callback version of subqueries or raw expressions:
169
+ *
170
+ * ```ts
171
+ * db.with('jennifer', (db) => db
172
+ * .selectFrom('person')
173
+ * .where('first_name', '=', 'Jennifer')
174
+ * .select(['id', 'first_name', 'gender'])
175
+ * .limit(1)
176
+ * ).insertInto('pet').values((eb) => ({
177
+ * owner_id: eb.selectFrom('jennifer').select('id'),
178
+ * name: eb.selectFrom('jennifer').select('first_name'),
179
+ * species: 'cat',
180
+ * }))
181
+ * ```
182
+ */
23
183
  values(insert) {
24
184
  const [columns, values] = (0, insert_values_parser_js_1.parseInsertExpression)(insert);
25
185
  return new InsertQueryBuilder({
@@ -98,6 +258,17 @@ class InsertQueryBuilder {
98
258
  }),
99
259
  });
100
260
  }
261
+ /**
262
+ * Creates an `insert into "person" default values` query.
263
+ */
264
+ defaultValues() {
265
+ return new InsertQueryBuilder({
266
+ ...this.#props,
267
+ queryNode: insert_query_node_js_1.InsertQueryNode.cloneWith(this.#props.queryNode, {
268
+ defaultValues: true,
269
+ }),
270
+ });
271
+ }
101
272
  /**
102
273
  * Changes an `insert into` query to an `insert ignore into` query.
103
274
  *
@@ -398,8 +569,8 @@ class InsertQueryBuilder {
398
569
  /**
399
570
  * Change the output type of the query.
400
571
  *
401
- * You should only use this method as the last resort if the types
402
- * don't support your use case.
572
+ * This method call doesn't change the SQL in any way. This methods simply
573
+ * returns a copy of this `InsertQueryBuilder` with a new output type.
403
574
  */
404
575
  $castTo() {
405
576
  return new InsertQueryBuilder(this.#props);
@@ -232,7 +232,8 @@ export declare class TraversedJSONPathBuilder<S, O> extends JSONPathBuilder<S, O
232
232
  * This method call doesn't change the SQL in any way. This methods simply
233
233
  * returns a copy of this `JSONPathBuilder` with a new output type.
234
234
  */
235
- $castTo<T>(): JSONPathBuilder<T>;
235
+ $castTo<C>(): JSONPathBuilder<C>;
236
+ $notNull(): JSONPathBuilder<Exclude<O, null>>;
236
237
  /**
237
238
  * Creates the OperationNode that describes how to compile this expression into SQL.
238
239
  *
@@ -165,6 +165,9 @@ class TraversedJSONPathBuilder extends JSONPathBuilder {
165
165
  $castTo() {
166
166
  return new JSONPathBuilder(this.#node);
167
167
  }
168
+ $notNull() {
169
+ return new JSONPathBuilder(this.#node);
170
+ }
168
171
  toOperationNode() {
169
172
  return this.#node;
170
173
  }
@@ -25,6 +25,7 @@ import { Streamable } from '../util/streamable.js';
25
25
  import { ExpressionOrFactory } from '../parser/expression-parser.js';
26
26
  import { ExpressionWrapper } from '../expression/expression-wrapper.js';
27
27
  import { SelectQueryBuilderExpression } from './select-query-builder-expression.js';
28
+ import { ValueExpression } from '../parser/value-parser.js';
28
29
  export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInterface<DB, TB>, HavingInterface<DB, TB>, SelectQueryBuilderExpression<O>, Compilable<O>, Explainable, Streamable<O> {
29
30
  /**
30
31
  * Adds a `where` expression to the query.
@@ -674,19 +675,19 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
674
675
  /**
675
676
  * Adds the `for update` modifier to a select query on supported databases.
676
677
  */
677
- forUpdate(): SelectQueryBuilder<DB, TB, O>;
678
+ forUpdate(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
678
679
  /**
679
680
  * Adds the `for share` modifier to a select query on supported databases.
680
681
  */
681
- forShare(): SelectQueryBuilder<DB, TB, O>;
682
+ forShare(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
682
683
  /**
683
684
  * Adds the `for key share` modifier to a select query on supported databases.
684
685
  */
685
- forKeyShare(): SelectQueryBuilder<DB, TB, O>;
686
+ forKeyShare(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
686
687
  /**
687
688
  * Adds the `for no key update` modifier to a select query on supported databases.
688
689
  */
689
- forNoKeyUpdate(): SelectQueryBuilder<DB, TB, O>;
690
+ forNoKeyUpdate(of?: TableOrList<TB>): SelectQueryBuilder<DB, TB, O>;
690
691
  /**
691
692
  * Adds the `skip locked` modifier to a select query on supported databases.
692
693
  */
@@ -1161,7 +1162,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
1161
1162
  * .limit(10)
1162
1163
  * ```
1163
1164
  */
1164
- limit(limit: number): SelectQueryBuilder<DB, TB, O>;
1165
+ limit(limit: ValueExpression<DB, TB, number>): SelectQueryBuilder<DB, TB, O>;
1165
1166
  /**
1166
1167
  * Adds an offset clause to the query.
1167
1168
  *
@@ -1177,7 +1178,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
1177
1178
  * .limit(10)
1178
1179
  * ```
1179
1180
  */
1180
- offset(offset: number): SelectQueryBuilder<DB, TB, O>;
1181
+ offset(offset: ValueExpression<DB, TB, number>): SelectQueryBuilder<DB, TB, O>;
1181
1182
  /**
1182
1183
  * Combines another select query or raw expression to this query using `union`.
1183
1184
  *
@@ -1549,10 +1550,10 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
1549
1550
  /**
1550
1551
  * Change the output type of the query.
1551
1552
  *
1552
- * You should only use this method as the last resort if the types
1553
- * don't support your use case.
1553
+ * This method call doesn't change the SQL in any way. This methods simply
1554
+ * returns a copy of this `SelectQueryBuilder` with a new output type.
1554
1555
  */
1555
- $castTo<T>(): SelectQueryBuilder<DB, TB, T>;
1556
+ $castTo<C>(): SelectQueryBuilder<DB, TB, C>;
1556
1557
  /**
1557
1558
  * Changes the output type from an object to a tuple.
1558
1559
  *
@@ -1831,4 +1832,5 @@ type OuterJoinedBuilder<DB, TB extends keyof DB, O, A extends keyof any, R> = Se
1831
1832
  type OuterJoinedBuilderDB<DB, TB extends keyof DB, A extends keyof any, R> = DrainOuterGeneric<{
1832
1833
  [C in keyof DB | A]: C extends A ? Nullable<R> : C extends TB ? Nullable<DB[C]> : C extends keyof DB ? DB[C] : never;
1833
1834
  }>;
1835
+ type TableOrList<TB extends keyof any> = (TB & string) | ReadonlyArray<TB & string>;
1834
1836
  export {};
@@ -4,6 +4,7 @@ exports.createSelectQueryBuilder = void 0;
4
4
  const alias_node_js_1 = require("../operation-node/alias-node.js");
5
5
  const select_modifier_node_js_1 = require("../operation-node/select-modifier-node.js");
6
6
  const join_parser_js_1 = require("../parser/join-parser.js");
7
+ const table_parser_js_1 = require("../parser/table-parser.js");
7
8
  const select_parser_js_1 = require("../parser/select-parser.js");
8
9
  const reference_parser_js_1 = require("../parser/reference-parser.js");
9
10
  const select_query_node_js_1 = require("../operation-node/select-query-node.js");
@@ -19,6 +20,7 @@ const identifier_node_js_1 = require("../operation-node/identifier-node.js");
19
20
  const set_operation_parser_js_1 = require("../parser/set-operation-parser.js");
20
21
  const binary_operation_parser_js_1 = require("../parser/binary-operation-parser.js");
21
22
  const expression_wrapper_js_1 = require("../expression/expression-wrapper.js");
23
+ const value_parser_js_1 = require("../parser/value-parser.js");
22
24
  class SelectQueryBuilderImpl {
23
25
  #props;
24
26
  constructor(props) {
@@ -84,28 +86,28 @@ class SelectQueryBuilderImpl {
84
86
  queryNode: select_query_node_js_1.SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('Distinct')),
85
87
  });
86
88
  }
87
- forUpdate() {
89
+ forUpdate(of) {
88
90
  return new SelectQueryBuilderImpl({
89
91
  ...this.#props,
90
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForUpdate')),
92
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForUpdate', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
91
93
  });
92
94
  }
93
- forShare() {
95
+ forShare(of) {
94
96
  return new SelectQueryBuilderImpl({
95
97
  ...this.#props,
96
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForShare')),
98
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForShare', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
97
99
  });
98
100
  }
99
- forKeyShare() {
101
+ forKeyShare(of) {
100
102
  return new SelectQueryBuilderImpl({
101
103
  ...this.#props,
102
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForKeyShare')),
104
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForKeyShare', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
103
105
  });
104
106
  }
105
- forNoKeyUpdate() {
107
+ forNoKeyUpdate(of) {
106
108
  return new SelectQueryBuilderImpl({
107
109
  ...this.#props,
108
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForNoKeyUpdate')),
110
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithEndModifier(this.#props.queryNode, select_modifier_node_js_1.SelectModifierNode.create('ForNoKeyUpdate', of ? (0, object_utils_js_1.asArray)(of).map(table_parser_js_1.parseTable) : undefined)),
109
111
  });
110
112
  }
111
113
  skipLocked() {
@@ -177,13 +179,13 @@ class SelectQueryBuilderImpl {
177
179
  limit(limit) {
178
180
  return new SelectQueryBuilderImpl({
179
181
  ...this.#props,
180
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create(limit)),
182
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create((0, value_parser_js_1.parseValueExpression)(limit))),
181
183
  });
182
184
  }
183
185
  offset(offset) {
184
186
  return new SelectQueryBuilderImpl({
185
187
  ...this.#props,
186
- queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOffset(this.#props.queryNode, offset_node_js_1.OffsetNode.create(offset)),
188
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithOffset(this.#props.queryNode, offset_node_js_1.OffsetNode.create((0, value_parser_js_1.parseValueExpression)(offset))),
187
189
  });
188
190
  }
189
191
  union(expression) {
@@ -8,7 +8,7 @@ import { ReferenceExpression } from '../parser/reference-parser.js';
8
8
  import { QueryNode } from '../operation-node/query-node.js';
9
9
  import { DrainOuterGeneric, NarrowPartial, Nullable, ShallowRecord, SimplifyResult, SimplifySingleResult, SqlBool } from '../util/type-utils.js';
10
10
  import { UpdateQueryNode } from '../operation-node/update-query-node.js';
11
- import { UpdateObject, UpdateObjectFactory, ExtractUpdateTypeFromReferenceExpression } from '../parser/update-set-parser.js';
11
+ import { UpdateObjectExpression, ExtractUpdateTypeFromReferenceExpression } from '../parser/update-set-parser.js';
12
12
  import { Compilable } from '../util/compilable.js';
13
13
  import { QueryExecutor } from '../query-executor/query-executor.js';
14
14
  import { QueryId } from '../util/query-id.js';
@@ -695,8 +695,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
695
695
  * where "id" = $5
696
696
  * ```
697
697
  */
698
- set(update: UpdateObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
699
- set(update: UpdateObjectFactory<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
698
+ set(update: UpdateObjectExpression<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
700
699
  set<RE extends ReferenceExpression<DB, UT>>(key: RE, value: ValueExpression<DB, TB, ExtractUpdateTypeFromReferenceExpression<DB, UT, RE>>): UpdateQueryBuilder<DB, UT, TB, O>;
701
700
  /**
702
701
  * Allows you to return data from modified rows.
@@ -829,10 +828,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
829
828
  /**
830
829
  * Change the output type of the query.
831
830
  *
832
- * You should only use this method as the last resort if the types
833
- * don't support your use case.
831
+ * This method call doesn't change the SQL in any way. This methods simply
832
+ * returns a copy of this `UpdateQueryBuilder` with a new output type.
834
833
  */
835
- $castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
834
+ $castTo<C>(): UpdateQueryBuilder<DB, UT, TB, C>;
836
835
  /**
837
836
  * Narrows (parts of) the output type of the query.
838
837
  *
@@ -156,8 +156,8 @@ class UpdateQueryBuilder {
156
156
  /**
157
157
  * Change the output type of the query.
158
158
  *
159
- * You should only use this method as the last resort if the types
160
- * don't support your use case.
159
+ * This method call doesn't change the SQL in any way. This methods simply
160
+ * returns a copy of this `UpdateQueryBuilder` with a new output type.
161
161
  */
162
162
  $castTo() {
163
163
  return new UpdateQueryBuilder(this.#props);
@@ -164,6 +164,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
164
164
  this.append(' ');
165
165
  this.visitNode(node.values);
166
166
  }
167
+ if (node.defaultValues) {
168
+ this.append(' ');
169
+ this.append('default values');
170
+ }
167
171
  if (node.onConflict) {
168
172
  this.append(' ');
169
173
  this.visitNode(node.onConflict);
@@ -869,6 +873,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
869
873
  else {
870
874
  this.append(SELECT_MODIFIER_SQL[node.modifier]);
871
875
  }
876
+ if (node.of) {
877
+ this.append(' of ');
878
+ this.compileList(node.of, ', ');
879
+ }
872
880
  }
873
881
  visitCreateType(node) {
874
882
  this.append('create type ');
@@ -130,7 +130,17 @@ export interface RawBuilder<O> extends AliasableExpression<O> {
130
130
  * This method call doesn't change the SQL in any way. This methods simply
131
131
  * returns a copy of this `RawBuilder` with a new output type.
132
132
  */
133
- $castTo<T>(): RawBuilder<T>;
133
+ $castTo<C>(): RawBuilder<C>;
134
+ /**
135
+ * Omit null from the expression's type.
136
+ *
137
+ * This function can be useful in cases where you know an expression can't be
138
+ * null, but Kysely is unable to infer it.
139
+ *
140
+ * This method call doesn't change the SQL in any way. This methods simply
141
+ * returns a copy of `this` with a new output type.
142
+ */
143
+ $notNull(): RawBuilder<Exclude<O, null>>;
134
144
  /**
135
145
  * Adds a plugin for this SQL snippet.
136
146
  */
@@ -24,6 +24,9 @@ class RawBuilderImpl {
24
24
  $castTo() {
25
25
  return new RawBuilderImpl({ ...this.#props });
26
26
  }
27
+ $notNull() {
28
+ return new RawBuilderImpl(this.#props);
29
+ }
27
30
  withPlugin(plugin) {
28
31
  return new RawBuilderImpl({
29
32
  ...this.#props,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sql = void 0;
4
4
  const identifier_node_js_1 = require("../operation-node/identifier-node.js");
5
+ const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
5
6
  const raw_node_js_1 = require("../operation-node/raw-node.js");
6
7
  const value_node_js_1 = require("../operation-node/value-node.js");
7
8
  const reference_parser_js_1 = require("../parser/reference-parser.js");
@@ -12,7 +13,7 @@ const raw_builder_js_1 = require("./raw-builder.js");
12
13
  exports.sql = Object.assign((sqlFragments, ...parameters) => {
13
14
  return (0, raw_builder_js_1.createRawBuilder)({
14
15
  queryId: (0, query_id_js_1.createQueryId)(),
15
- rawNode: raw_node_js_1.RawNode.create(sqlFragments, parameters?.map(value_parser_js_1.parseValueExpression) ?? []),
16
+ rawNode: raw_node_js_1.RawNode.create(sqlFragments, parameters?.map(parseParameter) ?? []),
16
17
  });
17
18
  }, {
18
19
  ref(columnReference) {
@@ -64,7 +65,7 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
64
65
  const nodes = new Array(2 * array.length - 1);
65
66
  const sep = separator.toOperationNode();
66
67
  for (let i = 0; i < array.length; ++i) {
67
- nodes[2 * i] = (0, value_parser_js_1.parseValueExpression)(array[i]);
68
+ nodes[2 * i] = parseParameter(array[i]);
68
69
  if (i !== array.length - 1) {
69
70
  nodes[2 * i + 1] = sep;
70
71
  }
@@ -75,3 +76,9 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
75
76
  });
76
77
  },
77
78
  });
79
+ function parseParameter(param) {
80
+ if ((0, operation_node_source_js_1.isOperationNodeSource)(param)) {
81
+ return param.toOperationNode();
82
+ }
83
+ return (0, value_parser_js_1.parseValueExpression)(param);
84
+ }
@@ -16,7 +16,7 @@ export declare function isArrayBufferOrView(obj: unknown): obj is ArrayBuffer |
16
16
  export declare function isPlainObject(obj: unknown): obj is Record<string, unknown>;
17
17
  export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
18
18
  export declare function freeze<T>(obj: T): Readonly<T>;
19
- export declare function asArray<T>(arg: T | T[]): T[];
19
+ export declare function asArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
20
20
  export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
21
21
  export declare function isReadonlyArray(arg: unknown): arg is ReadonlyArray<unknown>;
22
22
  export declare function noop<T>(obj: T): T;
@@ -74,7 +74,7 @@ function freeze(obj) {
74
74
  }
75
75
  exports.freeze = freeze;
76
76
  function asArray(arg) {
77
- if (Array.isArray(arg)) {
77
+ if (isReadonlyArray(arg)) {
78
78
  return arg;
79
79
  }
80
80
  else {
@@ -65,12 +65,14 @@ export class MssqlIntrospector {
65
65
  const tableDictionary = {};
66
66
  for (const rawColumn of rawColumns) {
67
67
  const key = `${rawColumn.table_schema_name}.${rawColumn.table_name}`;
68
- const table = (tableDictionary[key] ||= freeze({
69
- columns: [],
70
- isView: rawColumn.table_type === 'V ',
71
- name: rawColumn.table_name,
72
- schema: rawColumn.table_schema_name ?? undefined,
73
- }));
68
+ const table = (tableDictionary[key] =
69
+ tableDictionary[key] ||
70
+ freeze({
71
+ columns: [],
72
+ isView: rawColumn.table_type === 'V ',
73
+ name: rawColumn.table_name,
74
+ schema: rawColumn.table_schema_name ?? undefined,
75
+ }));
74
76
  table.columns.push(freeze({
75
77
  dataType: rawColumn.type_name,
76
78
  dataTypeSchema: rawColumn.type_schema_name ?? undefined,
@@ -243,7 +243,17 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Al
243
243
  * This method call doesn't change the SQL in any way. This methods simply
244
244
  * returns a copy of this `ExpressionWrapper` with a new output type.
245
245
  */
246
- $castTo<T>(): ExpressionWrapper<DB, TB, T>;
246
+ $castTo<C>(): ExpressionWrapper<DB, TB, C>;
247
+ /**
248
+ * Omit null from the expression's type.
249
+ *
250
+ * This function can be useful in cases where you know an expression can't be
251
+ * null, but Kysely is unable to infer it.
252
+ *
253
+ * This method call doesn't change the SQL in any way. This methods simply
254
+ * returns a copy of `this` with a new output type.
255
+ */
256
+ $notNull(): ExpressionWrapper<DB, TB, Exclude<T, null>>;
247
257
  /**
248
258
  * Creates the OperationNode that describes how to compile this expression into SQL.
249
259
  *
@@ -397,7 +407,7 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
397
407
  * This method call doesn't change the SQL in any way. This methods simply
398
408
  * returns a copy of this `OrWrapper` with a new output type.
399
409
  */
400
- $castTo<T extends SqlBool>(): OrWrapper<DB, TB, T>;
410
+ $castTo<C extends SqlBool>(): OrWrapper<DB, TB, C>;
401
411
  /**
402
412
  * Creates the OperationNode that describes how to compile this expression into SQL.
403
413
  *
@@ -533,7 +543,7 @@ export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> impl
533
543
  * This method call doesn't change the SQL in any way. This methods simply
534
544
  * returns a copy of this `AndWrapper` with a new output type.
535
545
  */
536
- $castTo<T extends SqlBool>(): AndWrapper<DB, TB, T>;
546
+ $castTo<C extends SqlBool>(): AndWrapper<DB, TB, C>;
537
547
  /**
538
548
  * Creates the OperationNode that describes how to compile this expression into SQL.
539
549
  *
@@ -33,6 +33,18 @@ export class ExpressionWrapper {
33
33
  $castTo() {
34
34
  return new ExpressionWrapper(this.#node);
35
35
  }
36
+ /**
37
+ * Omit null from the expression's type.
38
+ *
39
+ * This function can be useful in cases where you know an expression can't be
40
+ * null, but Kysely is unable to infer it.
41
+ *
42
+ * This method call doesn't change the SQL in any way. This methods simply
43
+ * returns a copy of `this` with a new output type.
44
+ */
45
+ $notNull() {
46
+ return new ExpressionWrapper(this.#node);
47
+ }
36
48
  toOperationNode() {
37
49
  return this.#node;
38
50
  }