kysely 0.17.1 → 0.18.0

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 (100) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +19 -0
  3. package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
  4. package/dist/cjs/driver/default-connection-provider.js +2 -2
  5. package/dist/cjs/driver/dummy-driver.d.ts +8 -0
  6. package/dist/cjs/driver/dummy-driver.js +8 -0
  7. package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
  8. package/dist/cjs/driver/single-connection-provider.js +2 -2
  9. package/dist/cjs/operation-node/alias-node.d.ts +2 -2
  10. package/dist/cjs/operation-node/alias-node.js +1 -2
  11. package/dist/cjs/operation-node/operation-node-transformer.js +1 -0
  12. package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
  13. package/dist/cjs/operation-node/update-query-node.js +11 -2
  14. package/dist/cjs/parser/complex-expression-parser.d.ts +1 -1
  15. package/dist/cjs/parser/reference-parser.js +2 -1
  16. package/dist/cjs/parser/table-parser.js +2 -1
  17. package/dist/cjs/parser/update-set-parser.d.ts +3 -3
  18. package/dist/cjs/parser/with-parser.d.ts +2 -2
  19. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
  20. package/dist/cjs/query-builder/delete-query-builder.d.ts +12 -5
  21. package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
  22. package/dist/cjs/query-builder/expression-builder.js +2 -2
  23. package/dist/cjs/query-builder/function-builder.js +2 -2
  24. package/dist/cjs/query-builder/insert-query-builder.d.ts +1 -1
  25. package/dist/cjs/query-builder/on-conflict-builder.d.ts +25 -11
  26. package/dist/cjs/query-builder/select-query-builder.d.ts +15 -6
  27. package/dist/cjs/query-builder/select-query-builder.js +5 -5
  28. package/dist/cjs/query-builder/update-query-builder.d.ts +69 -33
  29. package/dist/cjs/query-builder/update-query-builder.js +7 -0
  30. package/dist/cjs/query-builder/where-interface.d.ts +12 -5
  31. package/dist/cjs/query-compiler/default-query-compiler.js +4 -0
  32. package/dist/cjs/query-creator.d.ts +1 -1
  33. package/dist/cjs/query-executor/default-query-executor.d.ts +8 -5
  34. package/dist/cjs/query-executor/default-query-executor.js +2 -2
  35. package/dist/cjs/query-executor/noop-query-executor.d.ts +7 -4
  36. package/dist/cjs/query-executor/noop-query-executor.js +2 -2
  37. package/dist/cjs/query-executor/query-executor-base.d.ts +62 -0
  38. package/dist/cjs/query-executor/query-executor-base.js +46 -0
  39. package/dist/cjs/query-executor/query-executor.d.ts +16 -17
  40. package/dist/cjs/query-executor/query-executor.js +0 -59
  41. package/dist/cjs/raw-builder/raw-builder.d.ts +32 -2
  42. package/dist/cjs/raw-builder/raw-builder.js +5 -26
  43. package/dist/cjs/raw-builder/sql.d.ts +11 -3
  44. package/dist/cjs/raw-builder/sql.js +10 -2
  45. package/dist/cjs/schema/alter-table-builder.d.ts +24 -2
  46. package/dist/cjs/schema/alter-table-builder.js +20 -0
  47. package/dist/cjs/schema/column-definition-builder.d.ts +4 -2
  48. package/dist/cjs/schema/create-table-builder.d.ts +1 -1
  49. package/dist/cjs/schema/create-table-builder.js +1 -1
  50. package/dist/cjs/util/type-utils.d.ts +1 -1
  51. package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -0
  52. package/dist/esm/driver/default-connection-provider.d.ts +1 -1
  53. package/dist/esm/driver/default-connection-provider.js +2 -2
  54. package/dist/esm/driver/dummy-driver.d.ts +8 -0
  55. package/dist/esm/driver/dummy-driver.js +8 -0
  56. package/dist/esm/driver/single-connection-provider.d.ts +1 -1
  57. package/dist/esm/driver/single-connection-provider.js +2 -2
  58. package/dist/esm/operation-node/alias-node.d.ts +2 -2
  59. package/dist/esm/operation-node/alias-node.js +1 -2
  60. package/dist/esm/operation-node/operation-node-transformer.js +1 -0
  61. package/dist/esm/operation-node/update-query-node.d.ts +3 -0
  62. package/dist/esm/operation-node/update-query-node.js +11 -2
  63. package/dist/esm/parser/complex-expression-parser.d.ts +1 -1
  64. package/dist/esm/parser/reference-parser.js +2 -1
  65. package/dist/esm/parser/table-parser.js +2 -1
  66. package/dist/esm/parser/update-set-parser.d.ts +3 -3
  67. package/dist/esm/parser/with-parser.d.ts +2 -2
  68. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
  69. package/dist/esm/query-builder/delete-query-builder.d.ts +12 -5
  70. package/dist/esm/query-builder/expression-builder.d.ts +1 -1
  71. package/dist/esm/query-builder/expression-builder.js +1 -1
  72. package/dist/esm/query-builder/function-builder.js +1 -1
  73. package/dist/esm/query-builder/insert-query-builder.d.ts +1 -1
  74. package/dist/esm/query-builder/on-conflict-builder.d.ts +25 -11
  75. package/dist/esm/query-builder/select-query-builder.d.ts +15 -6
  76. package/dist/esm/query-builder/select-query-builder.js +5 -5
  77. package/dist/esm/query-builder/update-query-builder.d.ts +69 -33
  78. package/dist/esm/query-builder/update-query-builder.js +7 -0
  79. package/dist/esm/query-builder/where-interface.d.ts +12 -5
  80. package/dist/esm/query-compiler/default-query-compiler.js +4 -0
  81. package/dist/esm/query-creator.d.ts +1 -1
  82. package/dist/esm/query-executor/default-query-executor.d.ts +8 -5
  83. package/dist/esm/query-executor/default-query-executor.js +2 -2
  84. package/dist/esm/query-executor/noop-query-executor.d.ts +7 -4
  85. package/dist/esm/query-executor/noop-query-executor.js +2 -2
  86. package/dist/esm/query-executor/query-executor-base.d.ts +62 -0
  87. package/dist/esm/query-executor/query-executor-base.js +43 -0
  88. package/dist/esm/query-executor/query-executor.d.ts +16 -17
  89. package/dist/esm/query-executor/query-executor.js +1 -57
  90. package/dist/esm/raw-builder/raw-builder.d.ts +32 -2
  91. package/dist/esm/raw-builder/raw-builder.js +5 -26
  92. package/dist/esm/raw-builder/sql.d.ts +11 -3
  93. package/dist/esm/raw-builder/sql.js +10 -2
  94. package/dist/esm/schema/alter-table-builder.d.ts +24 -2
  95. package/dist/esm/schema/alter-table-builder.js +20 -0
  96. package/dist/esm/schema/column-definition-builder.d.ts +4 -2
  97. package/dist/esm/schema/create-table-builder.d.ts +1 -1
  98. package/dist/esm/schema/create-table-builder.js +1 -1
  99. package/dist/esm/util/type-utils.d.ts +1 -1
  100. package/package.json +9 -9
@@ -1,61 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryExecutor = void 0;
4
- const object_utils_js_1 = require("../util/object-utils.js");
5
- const NO_PLUGINS = (0, object_utils_js_1.freeze)([]);
6
- /**
7
- * This class abstracts away the details of how to compile a query into SQL
8
- * and execute it. Instead of passing around all those details, {@link SelectQueryBuilder}
9
- * and other classes that execute queries can just pass around and instance of
10
- * `QueryExecutor`.
11
- */
12
- class QueryExecutor {
13
- #plugins;
14
- constructor(plugins) {
15
- this.#plugins = plugins ?? NO_PLUGINS;
16
- }
17
- get plugins() {
18
- return this.#plugins;
19
- }
20
- /**
21
- * Given the query the user has built (expressed as an operation node tree)
22
- * this method runs it through all plugins' `transformQuery` methods and
23
- * returns the result.
24
- */
25
- transformQuery(node, queryId) {
26
- for (const plugin of this.#plugins) {
27
- const transformedNode = plugin.transformQuery({ node, queryId });
28
- // We need to do a runtime check here. There is no good way
29
- // to write types that enforce this constraint.
30
- if (transformedNode.kind === node.kind) {
31
- node = transformedNode;
32
- }
33
- else {
34
- throw new Error([
35
- `KyselyPlugin.transformQuery must return a node`,
36
- `of the same kind that was given to it.`,
37
- `The plugin was given a ${node.kind}`,
38
- `but it returned a ${transformedNode.kind}`,
39
- ].join(' '));
40
- }
41
- }
42
- return node;
43
- }
44
- /**
45
- * Executes a compiled query and runs the result through all plugins'
46
- * `transformResult` method.
47
- */
48
- async executeQuery(compiledQuery, queryId) {
49
- return await this.provideConnection(async (connection) => {
50
- const result = await connection.executeQuery(compiledQuery);
51
- return this.#transformResult(result, queryId);
52
- });
53
- }
54
- async #transformResult(result, queryId) {
55
- for (const plugin of this.#plugins) {
56
- result = await plugin.transformResult({ result, queryId });
57
- }
58
- return result;
59
- }
60
- }
61
- exports.QueryExecutor = QueryExecutor;
@@ -5,6 +5,7 @@ import { RawNode } from '../operation-node/raw-node.js';
5
5
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
6
6
  import { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
7
7
  import { QueryId } from '../util/query-id.js';
8
+ import { AnyRawBuilder } from '../util/type-utils.js';
8
9
  /**
9
10
  * An instance of this class can be used to create raw SQL snippets or queries.
10
11
  *
@@ -38,8 +39,37 @@ export declare class RawBuilder<O = unknown> implements OperationNodeSource {
38
39
  * select concat(first_name, ' ', last_name) as "full_name"
39
40
  * from "person"
40
41
  * ```
42
+ *
43
+ * You can also pass in a raw SQL snippet but in that case you must
44
+ * provide the alias as the only type argument:
45
+ *
46
+ * ```ts
47
+ * const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
48
+ *
49
+ * // The alias is `t(a, b)` which specifies the column names
50
+ * // in addition to the table name. We must tell kysely that
51
+ * // columns of the table can be referenced through `t`
52
+ * // by providing an explicit type argument.
53
+ * const aliasedValues = values.as<'t'>(sql`t(a, b)`)
54
+ *
55
+ * await db
56
+ * .insertInto('person')
57
+ * .columns(['first_name', 'last_name'])
58
+ * .expression(
59
+ * db.selectFrom(aliasedValues).select(['t.a', 't.b'])
60
+ * )
61
+ * ```
62
+ *
63
+ * The generated SQL (PostgreSQL):
64
+ *
65
+ * ```ts
66
+ * insert into "person" ("first_name", "last_name")
67
+ * from (values (1, 'foo')) as t(a, b)
68
+ * select "t"."a", "t"."b"
69
+ * ```
41
70
  */
42
71
  as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
72
+ as<A extends string = never>(alias: AnyRawBuilder): AliasedRawBuilder<O, A>;
43
73
  /**
44
74
  * Change the output type of the raw expression.
45
75
  *
@@ -67,9 +97,9 @@ export declare class AliasedRawBuilder<O = unknown, A extends string = never> im
67
97
  * which causes this type to be equal to AliasedRawBuilder with any A
68
98
  * as long as O is the same.
69
99
  */
70
- protected get alias(): A;
100
+ protected get alias(): A | AnyRawBuilder;
71
101
  toOperationNode(): AliasNode;
72
- constructor(rawBuilder: RawBuilder<O>, alias: A);
102
+ constructor(rawBuilder: RawBuilder<O>, alias: A | AnyRawBuilder);
73
103
  }
74
104
  export interface RawBuilderProps {
75
105
  readonly queryId: QueryId;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AliasedRawBuilder = exports.RawBuilder = void 0;
4
4
  const alias_node_js_1 = require("../operation-node/alias-node.js");
5
+ const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
5
6
  const prevent_await_js_1 = require("../util/prevent-await.js");
6
7
  const object_utils_js_1 = require("../util/object-utils.js");
7
8
  const noop_query_executor_js_1 = require("../query-executor/noop-query-executor.js");
9
+ const identifier_node_js_1 = require("../operation-node/identifier-node.js");
8
10
  /**
9
11
  * An instance of this class can be used to create raw SQL snippets or queries.
10
12
  *
@@ -16,31 +18,6 @@ class RawBuilder {
16
18
  constructor(props) {
17
19
  this.#props = (0, object_utils_js_1.freeze)(props);
18
20
  }
19
- /**
20
- * Returns an aliased version of the SQL expression.
21
- *
22
- * In addition to slapping `as "the_alias"` to the end of the SQL,
23
- * this method also provides strict typing:
24
- *
25
- * ```ts
26
- * const result = await db
27
- * .selectFrom('person')
28
- * .select(
29
- * sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
30
- * )
31
- * .executeTakeFirstOrThrow()
32
- *
33
- * // `full_name: string` field exists in the result type.
34
- * console.log(result.full_name)
35
- * ```
36
- *
37
- * The generated SQL (PostgreSQL):
38
- *
39
- * ```ts
40
- * select concat(first_name, ' ', last_name) as "full_name"
41
- * from "person"
42
- * ```
43
- */
44
21
  as(alias) {
45
22
  return new AliasedRawBuilder(this, alias);
46
23
  }
@@ -103,7 +80,9 @@ class AliasedRawBuilder {
103
80
  return this.#alias;
104
81
  }
105
82
  toOperationNode() {
106
- return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), this.#alias);
83
+ return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), (0, operation_node_source_js_1.isOperationNodeSource)(this.#alias)
84
+ ? this.#alias.toOperationNode()
85
+ : identifier_node_js_1.IdentifierNode.create(this.#alias));
107
86
  }
108
87
  constructor(rawBuilder, alias) {
109
88
  this.#rawBuilder = rawBuilder;
@@ -221,7 +221,7 @@ export interface Sql {
221
221
  * sql.id('first_name')
222
222
  * ]
223
223
  *
224
- * sql`BEFORE ${sql.array(things, sql`::varchar, `)} AFTER`
224
+ * sql`BEFORE ${sql.join(things, sql`::varchar, `)} AFTER`
225
225
  * ```
226
226
  *
227
227
  * The generated SQL (PostgreSQL):
@@ -281,7 +281,7 @@ export interface Sql {
281
281
  * from "person"
282
282
  * where birthdate between $1 and $2
283
283
  * and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
284
- * order by concate(first_name, ' ', last_name)
284
+ * order by concat(first_name, ' ', last_name)
285
285
  * ```
286
286
  *
287
287
  * SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
@@ -313,7 +313,15 @@ export interface Sql {
313
313
  * .select([
314
314
  * 'first_name',
315
315
  * 'last_name',
316
- * (eb) => sql<string>`concat(${eb.ref('first_name')}, ' ', ${eb.ref('last_name')})`.as('full_name')
316
+ * (eb) => {
317
+ * // The `eb.ref` method is type-safe and only accepts
318
+ * // column references that are possible.
319
+ * const firstName = eb.ref('first_name')
320
+ * const lastName = eb.ref('last_name')
321
+ *
322
+ * const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
323
+ * return fullName.as('full_name')
324
+ * }
317
325
  * ])
318
326
  * ```
319
327
  *
@@ -58,7 +58,7 @@ const raw_builder_js_1 = require("./raw-builder.js");
58
58
  * from "person"
59
59
  * where birthdate between $1 and $2
60
60
  * and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
61
- * order by concate(first_name, ' ', last_name)
61
+ * order by concat(first_name, ' ', last_name)
62
62
  * ```
63
63
  *
64
64
  * SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
@@ -90,7 +90,15 @@ const raw_builder_js_1 = require("./raw-builder.js");
90
90
  * .select([
91
91
  * 'first_name',
92
92
  * 'last_name',
93
- * (eb) => sql<string>`concat(${eb.ref('first_name')}, ' ', ${eb.ref('last_name')})`.as('full_name')
93
+ * (eb) => {
94
+ * // The `eb.ref` method is type-safe and only accepts
95
+ * // column references that are possible.
96
+ * const firstName = eb.ref('first_name')
97
+ * const lastName = eb.ref('last_name')
98
+ *
99
+ * const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
100
+ * return fullName.as('full_name')
101
+ * }
94
102
  * ])
95
103
  * ```
96
104
  *
@@ -23,6 +23,13 @@ export declare class AlterTableBuilder {
23
23
  alterColumn(column: string): AlterColumnBuilder;
24
24
  dropColumn(column: string): AlterTableExecutor;
25
25
  renameColumn(column: string, newColumn: string): AlterTableExecutor;
26
+ /**
27
+ * See {@link CreateTableBuilder.addColumn}
28
+ *
29
+ * Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
30
+ * and doesn't take a callback as the last argument. This is because you can only
31
+ * add one column per `ALTER TABLE` query.
32
+ */
26
33
  addColumn(columnName: string, dataType: DataTypeExpression): AlterTableAddColumnBuilder;
27
34
  /**
28
35
  * Creates an `alter table modify column` query. The `modify column` statement
@@ -30,8 +37,21 @@ export declare class AlterTableBuilder {
30
37
  * should use the `alterColumn` method.
31
38
  */
32
39
  modifyColumn(columnName: string, dataType: DataTypeExpression): AlterTableModifyColumnBuilder;
40
+ /**
41
+ * See {@link CreateTableBuilder.addUniqueConstraint}
42
+ */
33
43
  addUniqueConstraint(constraintName: string, columns: string[]): AlterTableExecutor;
44
+ /**
45
+ * See {@link CreateTableBuilder.addCheckConstraint}
46
+ */
34
47
  addCheckConstraint(constraintName: string, checkExpression: AnyRawBuilder): AlterTableExecutor;
48
+ /**
49
+ * See {@link CreateTableBuilder.addForeignKeyConstraint}
50
+ *
51
+ * Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
52
+ * the constraint builder and doesn't take a callback as the last argument. This
53
+ * is because you can only add one column per `ALTER TABLE` query.
54
+ */
35
55
  addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
36
56
  }
37
57
  export interface AlterTableBuilderProps {
@@ -142,7 +162,8 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
142
162
  * .execute()
143
163
  * ```
144
164
  *
145
- * Raw {@link sql} expressions are also supported:
165
+ * Values passed to `defaultTo` are interpreted as value literals by default. You can define
166
+ * an arbitrary SQL expression using the {@link sql} template tag:
146
167
  *
147
168
  * ```ts
148
169
  * import { sql } from 'kysely'
@@ -306,7 +327,8 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
306
327
  * .execute()
307
328
  * ```
308
329
  *
309
- * Raw {@link sql} expressions are also supported:
330
+ * Values passed to `defaultTo` are interpreted as value literals by default. You can define
331
+ * an arbitrary SQL expression using the {@link sql} template tag:
310
332
  *
311
333
  * ```ts
312
334
  * import { sql } from 'kysely'
@@ -68,6 +68,13 @@ class AlterTableBuilder {
68
68
  }),
69
69
  });
70
70
  }
71
+ /**
72
+ * See {@link CreateTableBuilder.addColumn}
73
+ *
74
+ * Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
75
+ * and doesn't take a callback as the last argument. This is because you can only
76
+ * add one column per `ALTER TABLE` query.
77
+ */
71
78
  addColumn(columnName, dataType) {
72
79
  return new AlterTableAddColumnBuilder({
73
80
  ...this.#props,
@@ -85,6 +92,9 @@ class AlterTableBuilder {
85
92
  columnBuilder: new column_definition_builder_js_1.ColumnDefinitionBuilder(column_definition_node_js_1.ColumnDefinitionNode.create(columnName, (0, data_type_parser_js_1.parseDataTypeExpression)(dataType))),
86
93
  });
87
94
  }
95
+ /**
96
+ * See {@link CreateTableBuilder.addUniqueConstraint}
97
+ */
88
98
  addUniqueConstraint(constraintName, columns) {
89
99
  return new AlterTableExecutor({
90
100
  ...this.#props,
@@ -93,6 +103,9 @@ class AlterTableBuilder {
93
103
  }),
94
104
  });
95
105
  }
106
+ /**
107
+ * See {@link CreateTableBuilder.addCheckConstraint}
108
+ */
96
109
  addCheckConstraint(constraintName, checkExpression) {
97
110
  return new AlterTableExecutor({
98
111
  ...this.#props,
@@ -101,6 +114,13 @@ class AlterTableBuilder {
101
114
  }),
102
115
  });
103
116
  }
117
+ /**
118
+ * See {@link CreateTableBuilder.addForeignKeyConstraint}
119
+ *
120
+ * Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
121
+ * the constraint builder and doesn't take a callback as the last argument. This
122
+ * is because you can only add one column per `ALTER TABLE` query.
123
+ */
104
124
  addForeignKeyConstraint(constraintName, columns, targetTable, targetColumns) {
105
125
  return new AlterTableAddForeignKeyConstraintBuilder({
106
126
  ...this.#props,
@@ -83,7 +83,8 @@ export interface ColumnDefinitionBuilderInterface {
83
83
  * .execute()
84
84
  * ```
85
85
  *
86
- * Raw {@link sql} expressions are also supported:
86
+ * Values passed to `defaultTo` are interpreted as value literals by default. You can define
87
+ * an arbitrary SQL expression using the {@link sql} template tag:
87
88
  *
88
89
  * ```ts
89
90
  * import { sql } from 'kysely'
@@ -241,7 +242,8 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
241
242
  * .execute()
242
243
  * ```
243
244
  *
244
- * Raw {@link sql} expressions are also supported:
245
+ * Values passed to `defaultTo` are interpreted as value literals by default. You can define
246
+ * an arbitrary SQL expression using the {@link sql} template tag:
245
247
  *
246
248
  * ```ts
247
249
  * import { sql } from 'kysely'
@@ -136,7 +136,7 @@ export declare class CreateTableBuilder<TB extends string, C extends string = ne
136
136
  * )
137
137
  * ```
138
138
  *
139
- * Add constraintfor multiple columns:
139
+ * Add constraint for multiple columns:
140
140
  *
141
141
  * ```ts
142
142
  * addForeignKeyConstraint(
@@ -186,7 +186,7 @@ class CreateTableBuilder {
186
186
  * )
187
187
  * ```
188
188
  *
189
- * Add constraintfor multiple columns:
189
+ * Add constraint for multiple columns:
190
190
  *
191
191
  * ```ts
192
192
  * addForeignKeyConstraint(
@@ -74,7 +74,7 @@ export declare type ExtractColumnType<DB, TB extends keyof DB, C> = {
74
74
  * movie: Movie
75
75
  * }
76
76
  *
77
- * type Columns = AnyColumn<Database, 'person' | 'pet'>
77
+ * type Columns = AnyColumnWithTable<Database, 'person' | 'pet'>
78
78
  *
79
79
  * // Columns == 'person.id' | 'pet.name' | 'pet.species'
80
80
  * ```
@@ -162,6 +162,25 @@ export interface MysqlDialectConfig {
162
162
  * If keep-alive is enabled users can supply an initial delay.
163
163
  */
164
164
  keepAliveInitialDelay?: number;
165
+ charsetNumber?: number;
166
+ compress?: boolean;
167
+ authSwitchHandler?: (data: any, callback: () => void) => any;
168
+ connectAttributes?: {
169
+ [param: string]: any;
170
+ };
171
+ decimalNumbers?: boolean;
172
+ isServer?: boolean;
173
+ maxPreparedStatements?: number;
174
+ namedPlaceholders?: boolean;
175
+ nestTables?: boolean | string;
176
+ passwordSha1?: string;
177
+ pool?: any;
178
+ stream?: any;
179
+ uri?: string;
180
+ Promise?: any;
181
+ authPlugins?: {
182
+ [key: string]: any;
183
+ };
165
184
  /**
166
185
  * Called once for each created connection.
167
186
  *
@@ -8,5 +8,5 @@ export declare class DefaultConnectionProvider implements ConnectionProvider {
8
8
  * Provides a connection for the callback and takes care of disposing
9
9
  * the connection after the callback has been run.
10
10
  */
11
- provideConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
11
+ provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
12
12
  }
@@ -4,10 +4,10 @@ export class DefaultConnectionProvider {
4
4
  constructor(driver) {
5
5
  this.#driver = driver;
6
6
  }
7
- async provideConnection(runner) {
7
+ async provideConnection(consumer) {
8
8
  const connection = await this.#driver.acquireConnection();
9
9
  try {
10
- return await runner(connection);
10
+ return await consumer(connection);
11
11
  }
12
12
  finally {
13
13
  await this.#driver.releaseConnection(connection);
@@ -27,6 +27,14 @@ import { Driver } from './driver.js';
27
27
  * },
28
28
  * })
29
29
  * ```
30
+ *
31
+ * You can use it to build a query and compile it to SQL but trying to
32
+ * execute the query will throw an error.
33
+ *
34
+ * ```ts
35
+ * const { sql } = db.selectFrom('person').selectAll().compile()
36
+ * console.log(sql) // select * from "person"
37
+ * ```
30
38
  */
31
39
  export declare class DummyDriver implements Driver {
32
40
  /**
@@ -26,6 +26,14 @@
26
26
  * },
27
27
  * })
28
28
  * ```
29
+ *
30
+ * You can use it to build a query and compile it to SQL but trying to
31
+ * execute the query will throw an error.
32
+ *
33
+ * ```ts
34
+ * const { sql } = db.selectFrom('person').selectAll().compile()
35
+ * console.log(sql) // select * from "person"
36
+ * ```
29
37
  */
30
38
  export class DummyDriver {
31
39
  async init() {
@@ -7,5 +7,5 @@ export declare class SingleConnectionProvider implements ConnectionProvider {
7
7
  * Provides a connection for the callback and takes care of disposing
8
8
  * the connection after the callback has been run.
9
9
  */
10
- provideConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
10
+ provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
11
11
  }
@@ -5,11 +5,11 @@ export class SingleConnectionProvider {
5
5
  constructor(connection) {
6
6
  this.#connection = connection;
7
7
  }
8
- async provideConnection(runner) {
8
+ async provideConnection(consumer) {
9
9
  while (this.#runningPromise) {
10
10
  await this.#runningPromise;
11
11
  }
12
- const promise = this.#run(runner);
12
+ const promise = this.#run(consumer);
13
13
  this.#runningPromise = promise
14
14
  .then(() => {
15
15
  this.#runningPromise = undefined;
@@ -9,12 +9,12 @@ export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | Se
9
9
  export interface AliasNode extends OperationNode {
10
10
  readonly kind: 'AliasNode';
11
11
  readonly node: AliasNodeChild;
12
- readonly alias: IdentifierNode;
12
+ readonly alias: IdentifierNode | RawNode;
13
13
  }
14
14
  /**
15
15
  * @internal
16
16
  */
17
17
  export declare const AliasNode: Readonly<{
18
18
  is(node: OperationNode): node is AliasNode;
19
- create(node: AliasNodeChild, alias: string): AliasNode;
19
+ create(node: AliasNodeChild, alias: IdentifierNode | RawNode): AliasNode;
20
20
  }>;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="./alias-node.d.ts" />
2
2
  import { freeze } from '../util/object-utils.js';
3
- import { IdentifierNode } from './identifier-node.js';
4
3
  /**
5
4
  * @internal
6
5
  */
@@ -12,7 +11,7 @@ export const AliasNode = freeze({
12
11
  return freeze({
13
12
  kind: 'AliasNode',
14
13
  node,
15
- alias: IdentifierNode.create(alias),
14
+ alias,
16
15
  });
17
16
  },
18
17
  });
@@ -331,6 +331,7 @@ export class OperationNodeTransformer {
331
331
  return {
332
332
  kind: 'UpdateQueryNode',
333
333
  table: this.transformNode(node.table),
334
+ from: this.transformNode(node.from),
334
335
  joins: this.transformNodeList(node.joins),
335
336
  where: this.transformNode(node.where),
336
337
  updates: this.transformNodeList(node.updates),
@@ -7,10 +7,12 @@ import { ReturningNode } from './returning-node.js';
7
7
  import { ValueListNode } from './value-list-node.js';
8
8
  import { WhereNode } from './where-node.js';
9
9
  import { WithNode } from './with-node.js';
10
+ import { FromNode } from './from-node.js';
10
11
  export declare type UpdateValuesNode = ValueListNode | PrimitiveValueListNode;
11
12
  export interface UpdateQueryNode extends OperationNode {
12
13
  readonly kind: 'UpdateQueryNode';
13
14
  readonly table: TableExpressionNode;
15
+ readonly from?: FromNode;
14
16
  readonly joins?: ReadonlyArray<JoinNode>;
15
17
  readonly where?: WhereNode;
16
18
  readonly updates?: ReadonlyArray<ColumnUpdateNode>;
@@ -23,5 +25,6 @@ export interface UpdateQueryNode extends OperationNode {
23
25
  export declare const UpdateQueryNode: Readonly<{
24
26
  is(node: OperationNode): node is UpdateQueryNode;
25
27
  create(table: TableExpressionNode, withNode?: WithNode | undefined): UpdateQueryNode;
28
+ cloneWithFromItems(updateQuery: UpdateQueryNode, fromItems: ReadonlyArray<TableExpressionNode>): UpdateQueryNode;
26
29
  cloneWithUpdates(updateQuery: UpdateQueryNode, updates: ReadonlyArray<ColumnUpdateNode>): UpdateQueryNode;
27
30
  }>;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="./update-query-node.d.ts" />
2
2
  import { freeze } from '../util/object-utils.js';
3
+ import { FromNode } from './from-node.js';
3
4
  /**
4
5
  * @internal
5
6
  */
@@ -8,11 +9,19 @@ export const UpdateQueryNode = freeze({
8
9
  return node.kind === 'UpdateQueryNode';
9
10
  },
10
11
  create(table, withNode) {
11
- return {
12
+ return freeze({
12
13
  kind: 'UpdateQueryNode',
13
14
  table,
14
15
  ...(withNode && { with: withNode }),
15
- };
16
+ });
17
+ },
18
+ cloneWithFromItems(updateQuery, fromItems) {
19
+ return freeze({
20
+ ...updateQuery,
21
+ from: updateQuery.from
22
+ ? FromNode.cloneWithFroms(updateQuery.from, fromItems)
23
+ : FromNode.create(fromItems),
24
+ });
16
25
  },
17
26
  cloneWithUpdates(updateQuery, updates) {
18
27
  return freeze({
@@ -1,7 +1,7 @@
1
- import { RawBuilder } from '../index-nodeless.js';
2
1
  import { AliasNode } from '../operation-node/alias-node.js';
3
2
  import { RawNode } from '../operation-node/raw-node.js';
4
3
  import { SelectQueryNode } from '../operation-node/select-query-node.js';
4
+ import { RawBuilder } from '../raw-builder/raw-builder.js';
5
5
  import { AliasedQueryBuilderFactory, AliasedRawBuilderFactory, AnyAliasedQueryBuilder, AnyAliasedRawBuilder, AnySelectQueryBuilder, SelectQueryBuilderFactory, RawBuilderFactory } from '../util/type-utils.js';
6
6
  export declare type ComplexExpression<DB, TB extends keyof DB, V = any> = AnySelectQueryBuilder | SelectQueryBuilderFactory<DB, TB> | RawBuilder<V> | RawBuilderFactory<DB, TB>;
7
7
  export declare type AliasedComplexExpression<DB, TB extends keyof DB> = AnyAliasedQueryBuilder | AliasedQueryBuilderFactory<DB, TB> | AnyAliasedRawBuilder | AliasedRawBuilderFactory<DB, TB>;
@@ -6,6 +6,7 @@ import { TableNode } from '../operation-node/table-node.js';
6
6
  import { isReadonlyArray, isString } from '../util/object-utils.js';
7
7
  import { parseComplexExpression, } from './complex-expression-parser.js';
8
8
  import { isDynamicReferenceBuilder, } from '../dynamic/dynamic-reference-builder.js';
9
+ import { IdentifierNode } from '../operation-node/identifier-node.js';
9
10
  export function parseReferenceExpressionOrList(arg) {
10
11
  if (isReadonlyArray(arg)) {
11
12
  return arg.map((it) => parseReferenceExpression(it));
@@ -45,7 +46,7 @@ export function parseAliasedStringReference(ref) {
45
46
  const ALIAS_SEPARATOR = ' as ';
46
47
  if (ref.includes(ALIAS_SEPARATOR)) {
47
48
  const [columnRef, alias] = ref.split(ALIAS_SEPARATOR).map(trim);
48
- return AliasNode.create(parseStringReference(columnRef), alias);
49
+ return AliasNode.create(parseStringReference(columnRef), IdentifierNode.create(alias));
49
50
  }
50
51
  else {
51
52
  return parseStringReference(ref);
@@ -3,6 +3,7 @@ import { isReadonlyArray, isString } from '../util/object-utils.js';
3
3
  import { AliasNode } from '../operation-node/alias-node.js';
4
4
  import { TableNode } from '../operation-node/table-node.js';
5
5
  import { parseAliasedComplexExpression, } from './complex-expression-parser.js';
6
+ import { IdentifierNode } from '../operation-node/identifier-node.js';
6
7
  export function parseTableExpressionOrList(table) {
7
8
  if (isReadonlyArray(table)) {
8
9
  return table.map((it) => parseTableExpression(it));
@@ -23,7 +24,7 @@ export function parseAliasedTable(from) {
23
24
  const ALIAS_SEPARATOR = ' as ';
24
25
  if (from.includes(ALIAS_SEPARATOR)) {
25
26
  const [table, alias] = from.split(ALIAS_SEPARATOR).map(trim);
26
- return AliasNode.create(parseTable(table), alias);
27
+ return AliasNode.create(parseTable(table), IdentifierNode.create(alias));
27
28
  }
28
29
  else {
29
30
  return parseTable(from);
@@ -1,7 +1,7 @@
1
1
  import { ColumnUpdateNode } from '../operation-node/column-update-node.js';
2
2
  import { UpdateKeys, UpdateType } from '../util/column-type.js';
3
3
  import { ValueExpression } from './value-parser.js';
4
- export declare type MutationObject<DB, TB extends keyof DB> = {
5
- [C in UpdateKeys<DB[TB]>]?: ValueExpression<DB, TB, UpdateType<DB[TB][C]>>;
4
+ export declare type MutationObject<DB, TB extends keyof DB, TM extends keyof DB> = {
5
+ [C in UpdateKeys<DB[TM]>]?: ValueExpression<DB, TB, UpdateType<DB[TM][C]>>;
6
6
  };
7
- export declare function parseUpdateObject(row: MutationObject<any, any>): ReadonlyArray<ColumnUpdateNode>;
7
+ export declare function parseUpdateObject(row: MutationObject<any, any, any>): ReadonlyArray<ColumnUpdateNode>;