kysely 0.17.1 → 0.17.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 (67) hide show
  1. package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +19 -0
  2. package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
  3. package/dist/cjs/driver/default-connection-provider.js +2 -2
  4. package/dist/cjs/driver/dummy-driver.d.ts +8 -0
  5. package/dist/cjs/driver/dummy-driver.js +8 -0
  6. package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
  7. package/dist/cjs/driver/single-connection-provider.js +2 -2
  8. package/dist/cjs/parser/complex-expression-parser.d.ts +1 -1
  9. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
  10. package/dist/cjs/query-builder/delete-query-builder.d.ts +12 -5
  11. package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
  12. package/dist/cjs/query-builder/expression-builder.js +2 -2
  13. package/dist/cjs/query-builder/function-builder.js +2 -2
  14. package/dist/cjs/query-builder/on-conflict-builder.d.ts +24 -10
  15. package/dist/cjs/query-builder/select-query-builder.d.ts +12 -5
  16. package/dist/cjs/query-builder/update-query-builder.d.ts +12 -5
  17. package/dist/cjs/query-builder/where-interface.d.ts +12 -5
  18. package/dist/cjs/query-executor/default-query-executor.d.ts +8 -5
  19. package/dist/cjs/query-executor/default-query-executor.js +2 -2
  20. package/dist/cjs/query-executor/noop-query-executor.d.ts +7 -4
  21. package/dist/cjs/query-executor/noop-query-executor.js +2 -2
  22. package/dist/cjs/query-executor/query-executor-base.d.ts +62 -0
  23. package/dist/cjs/query-executor/query-executor-base.js +46 -0
  24. package/dist/cjs/query-executor/query-executor.d.ts +16 -17
  25. package/dist/cjs/query-executor/query-executor.js +0 -59
  26. package/dist/cjs/raw-builder/sql.d.ts +11 -3
  27. package/dist/cjs/raw-builder/sql.js +10 -2
  28. package/dist/cjs/schema/alter-table-builder.d.ts +24 -2
  29. package/dist/cjs/schema/alter-table-builder.js +20 -0
  30. package/dist/cjs/schema/column-definition-builder.d.ts +4 -2
  31. package/dist/cjs/schema/create-table-builder.d.ts +1 -1
  32. package/dist/cjs/schema/create-table-builder.js +1 -1
  33. package/dist/cjs/util/type-utils.d.ts +1 -1
  34. package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -0
  35. package/dist/esm/driver/default-connection-provider.d.ts +1 -1
  36. package/dist/esm/driver/default-connection-provider.js +2 -2
  37. package/dist/esm/driver/dummy-driver.d.ts +8 -0
  38. package/dist/esm/driver/dummy-driver.js +8 -0
  39. package/dist/esm/driver/single-connection-provider.d.ts +1 -1
  40. package/dist/esm/driver/single-connection-provider.js +2 -2
  41. package/dist/esm/parser/complex-expression-parser.d.ts +1 -1
  42. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
  43. package/dist/esm/query-builder/delete-query-builder.d.ts +12 -5
  44. package/dist/esm/query-builder/expression-builder.d.ts +1 -1
  45. package/dist/esm/query-builder/expression-builder.js +1 -1
  46. package/dist/esm/query-builder/function-builder.js +1 -1
  47. package/dist/esm/query-builder/on-conflict-builder.d.ts +24 -10
  48. package/dist/esm/query-builder/select-query-builder.d.ts +12 -5
  49. package/dist/esm/query-builder/update-query-builder.d.ts +12 -5
  50. package/dist/esm/query-builder/where-interface.d.ts +12 -5
  51. package/dist/esm/query-executor/default-query-executor.d.ts +8 -5
  52. package/dist/esm/query-executor/default-query-executor.js +2 -2
  53. package/dist/esm/query-executor/noop-query-executor.d.ts +7 -4
  54. package/dist/esm/query-executor/noop-query-executor.js +2 -2
  55. package/dist/esm/query-executor/query-executor-base.d.ts +62 -0
  56. package/dist/esm/query-executor/query-executor-base.js +43 -0
  57. package/dist/esm/query-executor/query-executor.d.ts +16 -17
  58. package/dist/esm/query-executor/query-executor.js +1 -57
  59. package/dist/esm/raw-builder/sql.d.ts +11 -3
  60. package/dist/esm/raw-builder/sql.js +10 -2
  61. package/dist/esm/schema/alter-table-builder.d.ts +24 -2
  62. package/dist/esm/schema/alter-table-builder.js +20 -0
  63. package/dist/esm/schema/column-definition-builder.d.ts +4 -2
  64. package/dist/esm/schema/create-table-builder.d.ts +1 -1
  65. package/dist/esm/schema/create-table-builder.js +1 -1
  66. package/dist/esm/util/type-utils.d.ts +1 -1
  67. package/package.json +9 -9
@@ -202,4 +202,23 @@ export interface MysqlSslOptions {
202
202
  * You can also connect to a MySQL server without properly providing the appropriate CA to trust. You should not do this.
203
203
  */
204
204
  rejectUnauthorized?: boolean;
205
+ charsetNumber?: number;
206
+ compress?: boolean;
207
+ authSwitchHandler?: (data: any, callback: () => void) => any;
208
+ connectAttributes?: {
209
+ [param: string]: any;
210
+ };
211
+ decimalNumbers?: boolean;
212
+ isServer?: boolean;
213
+ maxPreparedStatements?: number;
214
+ namedPlaceholders?: boolean;
215
+ nestTables?: boolean | string;
216
+ passwordSha1?: string;
217
+ pool?: any;
218
+ stream?: any;
219
+ uri?: string;
220
+ Promise?: any;
221
+ authPlugins?: {
222
+ [key: string]: any;
223
+ };
205
224
  }
@@ -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
  }
@@ -6,10 +6,10 @@ class DefaultConnectionProvider {
6
6
  constructor(driver) {
7
7
  this.#driver = driver;
8
8
  }
9
- async provideConnection(runner) {
9
+ async provideConnection(consumer) {
10
10
  const connection = await this.#driver.acquireConnection();
11
11
  try {
12
- return await runner(connection);
12
+ return await consumer(connection);
13
13
  }
14
14
  finally {
15
15
  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
  /**
@@ -28,6 +28,14 @@ exports.DummyDriver = void 0;
28
28
  * },
29
29
  * })
30
30
  * ```
31
+ *
32
+ * You can use it to build a query and compile it to SQL but trying to
33
+ * execute the query will throw an error.
34
+ *
35
+ * ```ts
36
+ * const { sql } = db.selectFrom('person').selectAll().compile()
37
+ * console.log(sql) // select * from "person"
38
+ * ```
31
39
  */
32
40
  class DummyDriver {
33
41
  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
  }
@@ -7,11 +7,11 @@ class SingleConnectionProvider {
7
7
  constructor(connection) {
8
8
  this.#connection = connection;
9
9
  }
10
- async provideConnection(runner) {
10
+ async provideConnection(consumer) {
11
11
  while (this.#runningPromise) {
12
12
  await this.#runningPromise;
13
13
  }
14
- const promise = this.#run(runner);
14
+ const promise = this.#run(consumer);
15
15
  this.#runningPromise = promise
16
16
  .then(() => {
17
17
  this.#runningPromise = undefined;
@@ -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>;
@@ -1,6 +1,7 @@
1
- import { DeleteQueryNode, UpdateQueryNode } from '../../index-nodeless.js';
1
+ import { DeleteQueryNode } from '../../operation-node/delete-query-node.js';
2
2
  import { OperationNodeTransformer } from '../../operation-node/operation-node-transformer.js';
3
3
  import { SelectQueryNode } from '../../operation-node/select-query-node.js';
4
+ import { UpdateQueryNode } from '../../operation-node/update-query-node.js';
4
5
  export declare class DeduplicateJoinsTransformer extends OperationNodeTransformer {
5
6
  #private;
6
7
  protected transformSelectQuery(node: SelectQueryNode): SelectQueryNode;
@@ -46,7 +46,13 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
46
46
  * ```
47
47
  *
48
48
  * Operator can be any supported operator or if the typings don't support it
49
- * you can always use `sql\`your operator\``.
49
+ * you can always use
50
+ *
51
+ * ```ts
52
+ * sql`your operator`
53
+ * ```
54
+ *
55
+ * The next example uses the `>` operator:
50
56
  *
51
57
  * ```ts
52
58
  * const persons = await db
@@ -62,8 +68,8 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
62
68
  * select * from "person" where "id" > $1
63
69
  * ```
64
70
  *
65
- * The `where` methods don't change the type of the query. You can add
66
- * conditional `where`s easily by doing something like this:
71
+ * `where` methods don't change the type of the query. You can add
72
+ * conditional statements easily by doing something like this:
67
73
  *
68
74
  * ```ts
69
75
  * let query = db
@@ -71,6 +77,8 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
71
77
  * .selectAll()
72
78
  *
73
79
  * if (firstName) {
80
+ * // The query builder is immutable. Remember to reassign
81
+ * // the result back to the query variable.
74
82
  * query = query.where('first_name', '=', firstName)
75
83
  * }
76
84
  *
@@ -78,8 +86,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
78
86
  * ```
79
87
  *
80
88
  * This is true for basically all methods execpt the `select` and
81
- * `returning` methods, which DO change the return type of the
82
- * query.
89
+ * `returning`, that __do__ change the return type of the query.
83
90
  *
84
91
  * Both the first and third argument can also be subqueries.
85
92
  * A subquery is defined by passing a function and calling
@@ -3,7 +3,7 @@ import { TableExpression, TableExpressionDatabase, TableExpressionTables } from
3
3
  import { FunctionBuilder } from './function-builder.js';
4
4
  import { ExtractTypeFromReferenceExpression, StringReference } from '../parser/reference-parser.js';
5
5
  import { RawBuilder } from '../raw-builder/raw-builder.js';
6
- import { QueryExecutor } from '../index-nodeless.js';
6
+ import { QueryExecutor } from '../query-executor/query-executor.js';
7
7
  export declare class ExpressionBuilder<DB, TB extends keyof DB> {
8
8
  #private;
9
9
  constructor(props: ExpressionBuilderProps);
@@ -9,8 +9,8 @@ const query_id_js_1 = require("../util/query-id.js");
9
9
  const function_builder_js_1 = require("./function-builder.js");
10
10
  const reference_parser_js_1 = require("../parser/reference-parser.js");
11
11
  const raw_builder_js_1 = require("../raw-builder/raw-builder.js");
12
- const index_nodeless_js_1 = require("../index-nodeless.js");
13
12
  const object_utils_js_1 = require("../util/object-utils.js");
13
+ const raw_node_js_1 = require("../operation-node/raw-node.js");
14
14
  class ExpressionBuilder {
15
15
  #props;
16
16
  constructor(props) {
@@ -100,7 +100,7 @@ class ExpressionBuilder {
100
100
  return new raw_builder_js_1.RawBuilder({
101
101
  queryId: (0, query_id_js_1.createQueryId)(),
102
102
  plugins: this.#props.executor.plugins,
103
- rawNode: index_nodeless_js_1.RawNode.createWithChild((0, reference_parser_js_1.parseStringReference)(reference)),
103
+ rawNode: raw_node_js_1.RawNode.createWithChild((0, reference_parser_js_1.parseStringReference)(reference)),
104
104
  });
105
105
  }
106
106
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunctionBuilder = void 0;
4
- const index_nodeless_js_1 = require("../index-nodeless.js");
4
+ const raw_node_js_1 = require("../operation-node/raw-node.js");
5
5
  const reference_parser_js_1 = require("../parser/reference-parser.js");
6
6
  const raw_builder_js_1 = require("../raw-builder/raw-builder.js");
7
7
  const query_id_js_1 = require("../util/query-id.js");
@@ -153,7 +153,7 @@ class FunctionBuilder {
153
153
  #oneArgFunction(fn, column) {
154
154
  return new raw_builder_js_1.RawBuilder({
155
155
  queryId: (0, query_id_js_1.createQueryId)(),
156
- rawNode: index_nodeless_js_1.RawNode.create([`${fn}(`, ')'], [(0, reference_parser_js_1.parseStringReference)(column)]),
156
+ rawNode: raw_node_js_1.RawNode.create([`${fn}(`, ')'], [(0, reference_parser_js_1.parseStringReference)(column)]),
157
157
  });
158
158
  }
159
159
  }
@@ -69,7 +69,13 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
69
69
  * ```
70
70
  *
71
71
  * Operator can be any supported operator or if the typings don't support it
72
- * you can always use `sql\`your operator\``.
72
+ * you can always use
73
+ *
74
+ * ```ts
75
+ * sql`your operator`
76
+ * ```
77
+ *
78
+ * The next example uses the `>` operator:
73
79
  *
74
80
  * ```ts
75
81
  * const persons = await db
@@ -85,8 +91,8 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
85
91
  * select * from "person" where "id" > $1
86
92
  * ```
87
93
  *
88
- * The `where` methods don't change the type of the query. You can add
89
- * conditional `where`s easily by doing something like this:
94
+ * `where` methods don't change the type of the query. You can add
95
+ * conditional statements easily by doing something like this:
90
96
  *
91
97
  * ```ts
92
98
  * let query = db
@@ -94,6 +100,8 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
94
100
  * .selectAll()
95
101
  *
96
102
  * if (firstName) {
103
+ * // The query builder is immutable. Remember to reassign
104
+ * // the result back to the query variable.
97
105
  * query = query.where('first_name', '=', firstName)
98
106
  * }
99
107
  *
@@ -101,8 +109,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
101
109
  * ```
102
110
  *
103
111
  * This is true for basically all methods execpt the `select` and
104
- * `returning` methods, which DO change the return type of the
105
- * query.
112
+ * `returning`, that __do__ change the return type of the query.
106
113
  *
107
114
  * Both the first and third argument can also be subqueries.
108
115
  * A subquery is defined by passing a function and calling
@@ -426,7 +433,13 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
426
433
  * ```
427
434
  *
428
435
  * Operator can be any supported operator or if the typings don't support it
429
- * you can always use `sql\`your operator\``.
436
+ * you can always use
437
+ *
438
+ * ```ts
439
+ * sql`your operator`
440
+ * ```
441
+ *
442
+ * The next example uses the `>` operator:
430
443
  *
431
444
  * ```ts
432
445
  * const persons = await db
@@ -442,8 +455,8 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
442
455
  * select * from "person" where "id" > $1
443
456
  * ```
444
457
  *
445
- * The `where` methods don't change the type of the query. You can add
446
- * conditional `where`s easily by doing something like this:
458
+ * `where` methods don't change the type of the query. You can add
459
+ * conditional statements easily by doing something like this:
447
460
  *
448
461
  * ```ts
449
462
  * let query = db
@@ -451,6 +464,8 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
451
464
  * .selectAll()
452
465
  *
453
466
  * if (firstName) {
467
+ * // The query builder is immutable. Remember to reassign
468
+ * // the result back to the query variable.
454
469
  * query = query.where('first_name', '=', firstName)
455
470
  * }
456
471
  *
@@ -458,8 +473,7 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
458
473
  * ```
459
474
  *
460
475
  * This is true for basically all methods execpt the `select` and
461
- * `returning` methods, which DO change the return type of the
462
- * query.
476
+ * `returning`, that __do__ change the return type of the query.
463
477
  *
464
478
  * Both the first and third argument can also be subqueries.
465
479
  * A subquery is defined by passing a function and calling
@@ -45,7 +45,13 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
45
45
  * ```
46
46
  *
47
47
  * Operator can be any supported operator or if the typings don't support it
48
- * you can always use `sql\`your operator\``.
48
+ * you can always use
49
+ *
50
+ * ```ts
51
+ * sql`your operator`
52
+ * ```
53
+ *
54
+ * The next example uses the `>` operator:
49
55
  *
50
56
  * ```ts
51
57
  * const persons = await db
@@ -61,8 +67,8 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
61
67
  * select * from "person" where "id" > $1
62
68
  * ```
63
69
  *
64
- * The `where` methods don't change the type of the query. You can add
65
- * conditional `where`s easily by doing something like this:
70
+ * `where` methods don't change the type of the query. You can add
71
+ * conditional statements easily by doing something like this:
66
72
  *
67
73
  * ```ts
68
74
  * let query = db
@@ -70,6 +76,8 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
70
76
  * .selectAll()
71
77
  *
72
78
  * if (firstName) {
79
+ * // The query builder is immutable. Remember to reassign
80
+ * // the result back to the query variable.
73
81
  * query = query.where('first_name', '=', firstName)
74
82
  * }
75
83
  *
@@ -77,8 +85,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
77
85
  * ```
78
86
  *
79
87
  * This is true for basically all methods execpt the `select` and
80
- * `returning` methods, which DO change the return type of the
81
- * query.
88
+ * `returning`, that __do__ change the return type of the query.
82
89
  *
83
90
  * Both the first and third argument can also be subqueries.
84
91
  * A subquery is defined by passing a function and calling
@@ -46,7 +46,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
46
46
  * ```
47
47
  *
48
48
  * Operator can be any supported operator or if the typings don't support it
49
- * you can always use `sql\`your operator\``.
49
+ * you can always use
50
+ *
51
+ * ```ts
52
+ * sql`your operator`
53
+ * ```
54
+ *
55
+ * The next example uses the `>` operator:
50
56
  *
51
57
  * ```ts
52
58
  * const persons = await db
@@ -62,8 +68,8 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
62
68
  * select * from "person" where "id" > $1
63
69
  * ```
64
70
  *
65
- * The `where` methods don't change the type of the query. You can add
66
- * conditional `where`s easily by doing something like this:
71
+ * `where` methods don't change the type of the query. You can add
72
+ * conditional statements easily by doing something like this:
67
73
  *
68
74
  * ```ts
69
75
  * let query = db
@@ -71,6 +77,8 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
71
77
  * .selectAll()
72
78
  *
73
79
  * if (firstName) {
80
+ * // The query builder is immutable. Remember to reassign
81
+ * // the result back to the query variable.
74
82
  * query = query.where('first_name', '=', firstName)
75
83
  * }
76
84
  *
@@ -78,8 +86,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
78
86
  * ```
79
87
  *
80
88
  * This is true for basically all methods execpt the `select` and
81
- * `returning` methods, which DO change the return type of the
82
- * query.
89
+ * `returning`, that __do__ change the return type of the query.
83
90
  *
84
91
  * Both the first and third argument can also be subqueries.
85
92
  * A subquery is defined by passing a function and calling
@@ -26,7 +26,13 @@ export interface WhereInterface<DB, TB extends keyof DB> {
26
26
  * ```
27
27
  *
28
28
  * Operator can be any supported operator or if the typings don't support it
29
- * you can always use `sql\`your operator\``.
29
+ * you can always use
30
+ *
31
+ * ```ts
32
+ * sql`your operator`
33
+ * ```
34
+ *
35
+ * The next example uses the `>` operator:
30
36
  *
31
37
  * ```ts
32
38
  * const persons = await db
@@ -42,8 +48,8 @@ export interface WhereInterface<DB, TB extends keyof DB> {
42
48
  * select * from "person" where "id" > $1
43
49
  * ```
44
50
  *
45
- * The `where` methods don't change the type of the query. You can add
46
- * conditional `where`s easily by doing something like this:
51
+ * `where` methods don't change the type of the query. You can add
52
+ * conditional statements easily by doing something like this:
47
53
  *
48
54
  * ```ts
49
55
  * let query = db
@@ -51,6 +57,8 @@ export interface WhereInterface<DB, TB extends keyof DB> {
51
57
  * .selectAll()
52
58
  *
53
59
  * if (firstName) {
60
+ * // The query builder is immutable. Remember to reassign
61
+ * // the result back to the query variable.
54
62
  * query = query.where('first_name', '=', firstName)
55
63
  * }
56
64
  *
@@ -58,8 +66,7 @@ export interface WhereInterface<DB, TB extends keyof DB> {
58
66
  * ```
59
67
  *
60
68
  * This is true for basically all methods execpt the `select` and
61
- * `returning` methods, which DO change the return type of the
62
- * query.
69
+ * `returning`, that __do__ change the return type of the query.
63
70
  *
64
71
  * Both the first and third argument can also be subqueries.
65
72
  * A subquery is defined by passing a function and calling
@@ -3,11 +3,14 @@ import { DatabaseConnection } from '../driver/database-connection.js';
3
3
  import { CompiledQuery } from '../query-compiler/compiled-query.js';
4
4
  import { RootOperationNode, QueryCompiler } from '../query-compiler/query-compiler.js';
5
5
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
6
- import { QueryExecutor } from './query-executor.js';
7
- import { DialectAdapter } from '../index-nodeless.js';
8
- export declare class DefaultQueryExecutor extends QueryExecutor {
6
+ import { QueryExecutorBase } from './query-executor-base.js';
7
+ import { DialectAdapter } from '../dialect/dialect-adapter.js';
8
+ export declare class DefaultQueryExecutor extends QueryExecutorBase {
9
9
  #private;
10
10
  constructor(compiler: QueryCompiler, adapter: DialectAdapter, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
11
+ /**
12
+ * Returns the adapter for the current dialect.
13
+ */
11
14
  get adapter(): DialectAdapter;
12
15
  /**
13
16
  * Compiles the transformed query into SQL. You usually want to pass
@@ -38,9 +41,9 @@ export declare class DefaultQueryExecutor extends QueryExecutor {
38
41
  /**
39
42
  * Returns a copy of this executor with a new connection provider.
40
43
  */
41
- withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
44
+ withConnectionProvider(connectionProvider: ConnectionProvider): DefaultQueryExecutor;
42
45
  /**
43
46
  * Returns a copy of this executor without any plugins.
44
47
  */
45
- withoutPlugins(): QueryExecutor;
48
+ withoutPlugins(): DefaultQueryExecutor;
46
49
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultQueryExecutor = void 0;
4
- const query_executor_js_1 = require("./query-executor.js");
5
- class DefaultQueryExecutor extends query_executor_js_1.QueryExecutor {
4
+ const query_executor_base_js_1 = require("./query-executor-base.js");
5
+ class DefaultQueryExecutor extends query_executor_base_js_1.QueryExecutorBase {
6
6
  #compiler;
7
7
  #adapter;
8
8
  #connectionProvider;
@@ -1,13 +1,16 @@
1
1
  import { CompiledQuery } from '../query-compiler/compiled-query.js';
2
- import { QueryExecutor } from './query-executor.js';
3
2
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
4
3
  import { DialectAdapter } from '../dialect/dialect-adapter.js';
4
+ import { QueryExecutorBase } from './query-executor-base.js';
5
5
  /**
6
6
  * A {@link QueryExecutor} subclass that can be used when you don't
7
7
  * have a {@link QueryCompiler}, {@link ConnectionProvider} or any
8
8
  * other needed things to actually execute queries.
9
9
  */
10
- export declare class NoopQueryExecutor extends QueryExecutor {
10
+ export declare class NoopQueryExecutor extends QueryExecutorBase {
11
+ /**
12
+ * Returns the adapter for the current dialect.
13
+ */
11
14
  get adapter(): DialectAdapter;
12
15
  /**
13
16
  * Compiles the transformed query into SQL. You usually want to pass
@@ -23,7 +26,7 @@ export declare class NoopQueryExecutor extends QueryExecutor {
23
26
  /**
24
27
  * Returns a copy of this executor with a new connection provider.
25
28
  */
26
- withConnectionProvider(): QueryExecutor;
29
+ withConnectionProvider(): NoopQueryExecutor;
27
30
  /**
28
31
  * Returns a copy of this executor with a plugin added as the
29
32
  * last plugin.
@@ -42,6 +45,6 @@ export declare class NoopQueryExecutor extends QueryExecutor {
42
45
  /**
43
46
  * Returns a copy of this executor without any plugins.
44
47
  */
45
- withoutPlugins(): QueryExecutor;
48
+ withoutPlugins(): NoopQueryExecutor;
46
49
  }
47
50
  export declare const NOOP_QUERY_EXECUTOR: NoopQueryExecutor;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NOOP_QUERY_EXECUTOR = exports.NoopQueryExecutor = void 0;
4
- const query_executor_js_1 = require("./query-executor.js");
4
+ const query_executor_base_js_1 = require("./query-executor-base.js");
5
5
  /**
6
6
  * A {@link QueryExecutor} subclass that can be used when you don't
7
7
  * have a {@link QueryCompiler}, {@link ConnectionProvider} or any
8
8
  * other needed things to actually execute queries.
9
9
  */
10
- class NoopQueryExecutor extends query_executor_js_1.QueryExecutor {
10
+ class NoopQueryExecutor extends query_executor_base_js_1.QueryExecutorBase {
11
11
  get adapter() {
12
12
  throw new Error('this query cannot be compiled to SQL');
13
13
  }
@@ -0,0 +1,62 @@
1
+ import { ConnectionProvider } from '../driver/connection-provider.js';
2
+ import { DatabaseConnection, QueryResult } from '../driver/database-connection.js';
3
+ import { CompiledQuery } from '../query-compiler/compiled-query.js';
4
+ import { RootOperationNode } from '../query-compiler/query-compiler.js';
5
+ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
6
+ import { QueryId } from '../util/query-id.js';
7
+ import { DialectAdapter } from '../dialect/dialect-adapter.js';
8
+ import { QueryExecutor } from './query-executor.js';
9
+ export declare abstract class QueryExecutorBase implements QueryExecutor {
10
+ #private;
11
+ constructor(plugins?: ReadonlyArray<KyselyPlugin>);
12
+ abstract get adapter(): DialectAdapter;
13
+ /**
14
+ * Returns all installed plugins.
15
+ */
16
+ get plugins(): ReadonlyArray<KyselyPlugin>;
17
+ /**
18
+ * Given the query the user has built (expressed as an operation node tree)
19
+ * this method runs it through all plugins' `transformQuery` methods and
20
+ * returns the result.
21
+ */
22
+ transformQuery<T extends RootOperationNode>(node: T, queryId: QueryId): T;
23
+ /**
24
+ * Compiles the transformed query into SQL. You usually want to pass
25
+ * the output of {@link transformQuery} into this method but you can
26
+ * compile any query using this method.
27
+ */
28
+ abstract compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
29
+ /**
30
+ * Provides a connection for the callback and takes care of disposing
31
+ * the connection after the callback has been run.
32
+ */
33
+ abstract provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
34
+ /**
35
+ * Executes a compiled query and runs the result through all plugins'
36
+ * `transformResult` method.
37
+ */
38
+ executeQuery<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
39
+ /**
40
+ * Returns a copy of this executor with a new connection provider.
41
+ */
42
+ abstract withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutorBase;
43
+ /**
44
+ * Returns a copy of this executor with a plugin added as the
45
+ * last plugin.
46
+ */
47
+ abstract withPlugin(plugin: KyselyPlugin): QueryExecutorBase;
48
+ /**
49
+ * Returns a copy of this executor with a list of plugins added
50
+ * as the last plugins.
51
+ */
52
+ abstract withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutorBase;
53
+ /**
54
+ * Returns a copy of this executor with a plugin added as the
55
+ * first plugin.
56
+ */
57
+ abstract withPluginAtFront(plugin: KyselyPlugin): QueryExecutorBase;
58
+ /**
59
+ * Returns a copy of this executor without any plugins.
60
+ */
61
+ abstract withoutPlugins(): QueryExecutorBase;
62
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryExecutorBase = void 0;
4
+ const object_utils_js_1 = require("../util/object-utils.js");
5
+ const NO_PLUGINS = (0, object_utils_js_1.freeze)([]);
6
+ class QueryExecutorBase {
7
+ #plugins;
8
+ constructor(plugins = NO_PLUGINS) {
9
+ this.#plugins = plugins;
10
+ }
11
+ get plugins() {
12
+ return this.#plugins;
13
+ }
14
+ transformQuery(node, queryId) {
15
+ for (const plugin of this.#plugins) {
16
+ const transformedNode = plugin.transformQuery({ node, queryId });
17
+ // We need to do a runtime check here. There is no good way
18
+ // to write types that enforce this constraint.
19
+ if (transformedNode.kind === node.kind) {
20
+ node = transformedNode;
21
+ }
22
+ else {
23
+ throw new Error([
24
+ `KyselyPlugin.transformQuery must return a node`,
25
+ `of the same kind that was given to it.`,
26
+ `The plugin was given a ${node.kind}`,
27
+ `but it returned a ${transformedNode.kind}`,
28
+ ].join(' '));
29
+ }
30
+ }
31
+ return node;
32
+ }
33
+ async executeQuery(compiledQuery, queryId) {
34
+ return await this.provideConnection(async (connection) => {
35
+ const result = await connection.executeQuery(compiledQuery);
36
+ return this.#transformResult(result, queryId);
37
+ });
38
+ }
39
+ async #transformResult(result, queryId) {
40
+ for (const plugin of this.#plugins) {
41
+ result = await plugin.transformResult({ result, queryId });
42
+ }
43
+ return result;
44
+ }
45
+ }
46
+ exports.QueryExecutorBase = QueryExecutorBase;