kysely 0.17.0 → 0.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/cjs/driver/connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.js +2 -2
- package/dist/cjs/driver/dummy-driver.d.ts +8 -0
- package/dist/cjs/driver/dummy-driver.js +8 -0
- package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/single-connection-provider.js +2 -2
- package/dist/cjs/kysely.js +23 -29
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -1
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +12 -5
- package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-builder/function-builder.js +2 -2
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +24 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +12 -5
- package/dist/cjs/query-builder/update-query-builder.d.ts +12 -5
- package/dist/cjs/query-builder/where-interface.d.ts +12 -5
- package/dist/cjs/query-executor/default-query-executor.d.ts +14 -7
- package/dist/cjs/query-executor/default-query-executor.js +4 -6
- package/dist/cjs/query-executor/noop-query-executor.d.ts +12 -6
- package/dist/cjs/query-executor/noop-query-executor.js +3 -3
- package/dist/cjs/query-executor/query-executor-base.d.ts +62 -0
- package/dist/cjs/query-executor/query-executor-base.js +46 -0
- package/dist/cjs/query-executor/query-executor.d.ts +15 -15
- package/dist/cjs/query-executor/query-executor.js +0 -57
- package/dist/cjs/raw-builder/sql.d.ts +11 -3
- package/dist/cjs/raw-builder/sql.js +10 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +24 -2
- package/dist/cjs/schema/alter-table-builder.js +20 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +4 -2
- package/dist/cjs/schema/create-table-builder.d.ts +1 -1
- package/dist/cjs/schema/create-table-builder.js +1 -1
- package/dist/cjs/util/type-utils.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/esm/driver/connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.js +2 -2
- package/dist/esm/driver/dummy-driver.d.ts +8 -0
- package/dist/esm/driver/dummy-driver.js +8 -0
- package/dist/esm/driver/single-connection-provider.d.ts +1 -1
- package/dist/esm/driver/single-connection-provider.js +2 -2
- package/dist/esm/kysely.js +23 -29
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -1
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +12 -5
- package/dist/esm/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-builder/function-builder.js +1 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +24 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +12 -5
- package/dist/esm/query-builder/update-query-builder.d.ts +12 -5
- package/dist/esm/query-builder/where-interface.d.ts +12 -5
- package/dist/esm/query-executor/default-query-executor.d.ts +14 -7
- package/dist/esm/query-executor/default-query-executor.js +4 -6
- package/dist/esm/query-executor/noop-query-executor.d.ts +12 -6
- package/dist/esm/query-executor/noop-query-executor.js +3 -3
- package/dist/esm/query-executor/query-executor-base.d.ts +62 -0
- package/dist/esm/query-executor/query-executor-base.js +43 -0
- package/dist/esm/query-executor/query-executor.d.ts +15 -15
- package/dist/esm/query-executor/query-executor.js +1 -55
- package/dist/esm/raw-builder/sql.d.ts +11 -3
- package/dist/esm/raw-builder/sql.js +10 -2
- package/dist/esm/schema/alter-table-builder.d.ts +24 -2
- package/dist/esm/schema/alter-table-builder.js +20 -0
- package/dist/esm/schema/column-definition-builder.d.ts +4 -2
- package/dist/esm/schema/create-table-builder.d.ts +1 -1
- package/dist/esm/schema/create-table-builder.js +1 -1
- package/dist/esm/util/type-utils.d.ts +1 -1
- package/package.json +9 -9
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
66
|
-
* conditional
|
|
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
|
|
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 '../
|
|
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);
|
|
@@ -7,8 +7,8 @@ import { createQueryId } from '../util/query-id.js';
|
|
|
7
7
|
import { FunctionBuilder } from './function-builder.js';
|
|
8
8
|
import { parseStringReference, } from '../parser/reference-parser.js';
|
|
9
9
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
10
|
-
import { RawNode } from '../index-nodeless.js';
|
|
11
10
|
import { freeze } from '../util/object-utils.js';
|
|
11
|
+
import { RawNode } from '../operation-node/raw-node.js';
|
|
12
12
|
export class ExpressionBuilder {
|
|
13
13
|
#props;
|
|
14
14
|
constructor(props) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="./function-builder.d.ts" />
|
|
2
|
-
import { RawNode } from '../
|
|
2
|
+
import { RawNode } from '../operation-node/raw-node.js';
|
|
3
3
|
import { parseStringReference, } from '../parser/reference-parser.js';
|
|
4
4
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
5
5
|
import { createQueryId } from '../util/query-id.js';
|
|
@@ -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
|
|
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
|
-
*
|
|
89
|
-
* conditional
|
|
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
|
|
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
|
|
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
|
-
*
|
|
446
|
-
* conditional
|
|
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
|
|
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
|
|
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
|
-
*
|
|
65
|
-
* conditional
|
|
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
|
|
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
|
|
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
|
-
*
|
|
66
|
-
* conditional
|
|
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
|
|
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
|
|
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
|
-
*
|
|
46
|
-
* conditional
|
|
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
|
|
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
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { ConnectionProvider } from '../driver/connection-provider.js';
|
|
2
|
-
import {
|
|
2
|
+
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 {
|
|
7
|
-
import { DialectAdapter } from '../
|
|
8
|
-
export declare class DefaultQueryExecutor extends
|
|
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
|
|
@@ -15,7 +18,11 @@ export declare class DefaultQueryExecutor extends QueryExecutor {
|
|
|
15
18
|
* compile any query using this method.
|
|
16
19
|
*/
|
|
17
20
|
compileQuery(node: RootOperationNode): CompiledQuery;
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Provides a connection for the callback and takes care of disposing
|
|
23
|
+
* the connection after the callback has been run.
|
|
24
|
+
*/
|
|
25
|
+
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
19
26
|
/**
|
|
20
27
|
* Returns a copy of this executor with a list of plugins added
|
|
21
28
|
* as the last plugins.
|
|
@@ -34,9 +41,9 @@ export declare class DefaultQueryExecutor extends QueryExecutor {
|
|
|
34
41
|
/**
|
|
35
42
|
* Returns a copy of this executor with a new connection provider.
|
|
36
43
|
*/
|
|
37
|
-
withConnectionProvider(connectionProvider: ConnectionProvider):
|
|
44
|
+
withConnectionProvider(connectionProvider: ConnectionProvider): DefaultQueryExecutor;
|
|
38
45
|
/**
|
|
39
46
|
* Returns a copy of this executor without any plugins.
|
|
40
47
|
*/
|
|
41
|
-
withoutPlugins():
|
|
48
|
+
withoutPlugins(): DefaultQueryExecutor;
|
|
42
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./default-query-executor.d.ts" />
|
|
2
|
-
import {
|
|
3
|
-
export class DefaultQueryExecutor extends
|
|
2
|
+
import { QueryExecutorBase } from './query-executor-base.js';
|
|
3
|
+
export class DefaultQueryExecutor extends QueryExecutorBase {
|
|
4
4
|
#compiler;
|
|
5
5
|
#adapter;
|
|
6
6
|
#connectionProvider;
|
|
@@ -16,10 +16,8 @@ export class DefaultQueryExecutor extends QueryExecutor {
|
|
|
16
16
|
compileQuery(node) {
|
|
17
17
|
return this.#compiler.compileQuery(node);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
return this.#connectionProvider.
|
|
21
|
-
return connection.executeQuery(compiledQuery);
|
|
22
|
-
});
|
|
19
|
+
provideConnection(consumer) {
|
|
20
|
+
return this.#connectionProvider.provideConnection(consumer);
|
|
23
21
|
}
|
|
24
22
|
withPlugins(plugins) {
|
|
25
23
|
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [...this.plugins, ...plugins]);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { QueryResult } from '../driver/database-connection.js';
|
|
2
1
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
3
|
-
import { QueryExecutor } from './query-executor.js';
|
|
4
2
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
5
3
|
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
4
|
+
import { QueryExecutorBase } from './query-executor-base.js';
|
|
6
5
|
/**
|
|
7
6
|
* A {@link QueryExecutor} subclass that can be used when you don't
|
|
8
7
|
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
|
|
9
8
|
* other needed things to actually execute queries.
|
|
10
9
|
*/
|
|
11
|
-
export declare class NoopQueryExecutor extends
|
|
10
|
+
export declare class NoopQueryExecutor extends QueryExecutorBase {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the adapter for the current dialect.
|
|
13
|
+
*/
|
|
12
14
|
get adapter(): DialectAdapter;
|
|
13
15
|
/**
|
|
14
16
|
* Compiles the transformed query into SQL. You usually want to pass
|
|
@@ -16,11 +18,15 @@ export declare class NoopQueryExecutor extends QueryExecutor {
|
|
|
16
18
|
* compile any query using this method.
|
|
17
19
|
*/
|
|
18
20
|
compileQuery(): CompiledQuery;
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Provides a connection for the callback and takes care of disposing
|
|
23
|
+
* the connection after the callback has been run.
|
|
24
|
+
*/
|
|
25
|
+
provideConnection<T>(): Promise<T>;
|
|
20
26
|
/**
|
|
21
27
|
* Returns a copy of this executor with a new connection provider.
|
|
22
28
|
*/
|
|
23
|
-
withConnectionProvider():
|
|
29
|
+
withConnectionProvider(): NoopQueryExecutor;
|
|
24
30
|
/**
|
|
25
31
|
* Returns a copy of this executor with a plugin added as the
|
|
26
32
|
* last plugin.
|
|
@@ -39,6 +45,6 @@ export declare class NoopQueryExecutor extends QueryExecutor {
|
|
|
39
45
|
/**
|
|
40
46
|
* Returns a copy of this executor without any plugins.
|
|
41
47
|
*/
|
|
42
|
-
withoutPlugins():
|
|
48
|
+
withoutPlugins(): NoopQueryExecutor;
|
|
43
49
|
}
|
|
44
50
|
export declare const NOOP_QUERY_EXECUTOR: NoopQueryExecutor;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference types="./noop-query-executor.d.ts" />
|
|
2
|
-
import {
|
|
2
|
+
import { QueryExecutorBase } from './query-executor-base.js';
|
|
3
3
|
/**
|
|
4
4
|
* A {@link QueryExecutor} subclass that can be used when you don't
|
|
5
5
|
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
|
|
6
6
|
* other needed things to actually execute queries.
|
|
7
7
|
*/
|
|
8
|
-
export class NoopQueryExecutor extends
|
|
8
|
+
export class NoopQueryExecutor extends QueryExecutorBase {
|
|
9
9
|
get adapter() {
|
|
10
10
|
throw new Error('this query cannot be compiled to SQL');
|
|
11
11
|
}
|
|
12
12
|
compileQuery() {
|
|
13
13
|
throw new Error('this query cannot be compiled to SQL');
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
provideConnection() {
|
|
16
16
|
throw new Error('this query cannot be executed');
|
|
17
17
|
}
|
|
18
18
|
withConnectionProvider() {
|
|
@@ -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,43 @@
|
|
|
1
|
+
/// <reference types="./query-executor-base.d.ts" />
|
|
2
|
+
import { freeze } from '../util/object-utils.js';
|
|
3
|
+
const NO_PLUGINS = freeze([]);
|
|
4
|
+
export class QueryExecutorBase {
|
|
5
|
+
#plugins;
|
|
6
|
+
constructor(plugins = NO_PLUGINS) {
|
|
7
|
+
this.#plugins = plugins;
|
|
8
|
+
}
|
|
9
|
+
get plugins() {
|
|
10
|
+
return this.#plugins;
|
|
11
|
+
}
|
|
12
|
+
transformQuery(node, queryId) {
|
|
13
|
+
for (const plugin of this.#plugins) {
|
|
14
|
+
const transformedNode = plugin.transformQuery({ node, queryId });
|
|
15
|
+
// We need to do a runtime check here. There is no good way
|
|
16
|
+
// to write types that enforce this constraint.
|
|
17
|
+
if (transformedNode.kind === node.kind) {
|
|
18
|
+
node = transformedNode;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error([
|
|
22
|
+
`KyselyPlugin.transformQuery must return a node`,
|
|
23
|
+
`of the same kind that was given to it.`,
|
|
24
|
+
`The plugin was given a ${node.kind}`,
|
|
25
|
+
`but it returned a ${transformedNode.kind}`,
|
|
26
|
+
].join(' '));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return node;
|
|
30
|
+
}
|
|
31
|
+
async executeQuery(compiledQuery, queryId) {
|
|
32
|
+
return await this.provideConnection(async (connection) => {
|
|
33
|
+
const result = await connection.executeQuery(compiledQuery);
|
|
34
|
+
return this.#transformResult(result, queryId);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async #transformResult(result, queryId) {
|
|
38
|
+
for (const plugin of this.#plugins) {
|
|
39
|
+
result = await plugin.transformResult({ result, queryId });
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -6,15 +6,19 @@ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
|
6
6
|
import { QueryId } from '../util/query-id.js';
|
|
7
7
|
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
8
8
|
/**
|
|
9
|
-
* This
|
|
9
|
+
* This interface abstracts away the details of how to compile a query into SQL
|
|
10
10
|
* and execute it. Instead of passing around all those details, {@link SelectQueryBuilder}
|
|
11
11
|
* and other classes that execute queries can just pass around and instance of
|
|
12
12
|
* `QueryExecutor`.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export interface QueryExecutor extends ConnectionProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Returns the adapter for the current dialect.
|
|
17
|
+
*/
|
|
18
|
+
get adapter(): DialectAdapter;
|
|
19
|
+
/**
|
|
20
|
+
* Returns all installed plugins.
|
|
21
|
+
*/
|
|
18
22
|
get plugins(): ReadonlyArray<KyselyPlugin>;
|
|
19
23
|
/**
|
|
20
24
|
* Given the query the user has built (expressed as an operation node tree)
|
|
@@ -27,37 +31,33 @@ export declare abstract class QueryExecutor {
|
|
|
27
31
|
* the output of {@link transformQuery} into this method but you can
|
|
28
32
|
* compile any query using this method.
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
|
|
31
35
|
/**
|
|
32
36
|
* Executes a compiled query and runs the result through all plugins'
|
|
33
37
|
* `transformResult` method.
|
|
34
38
|
*/
|
|
35
39
|
executeQuery<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
36
|
-
/**
|
|
37
|
-
* Executes a compiled query.
|
|
38
|
-
*/
|
|
39
|
-
protected abstract executeQueryImpl<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
40
40
|
/**
|
|
41
41
|
* Returns a copy of this executor with a new connection provider.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
|
|
44
44
|
/**
|
|
45
45
|
* Returns a copy of this executor with a plugin added as the
|
|
46
46
|
* last plugin.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
withPlugin(plugin: KyselyPlugin): QueryExecutor;
|
|
49
49
|
/**
|
|
50
50
|
* Returns a copy of this executor with a list of plugins added
|
|
51
51
|
* as the last plugins.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutor;
|
|
54
54
|
/**
|
|
55
55
|
* Returns a copy of this executor with a plugin added as the
|
|
56
56
|
* first plugin.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
withPluginAtFront(plugin: KyselyPlugin): QueryExecutor;
|
|
59
59
|
/**
|
|
60
60
|
* Returns a copy of this executor without any plugins.
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
withoutPlugins(): QueryExecutor;
|
|
63
63
|
}
|