kysely 0.26.1 → 0.26.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.
- package/README.md +6 -6
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +3 -3
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +3 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +3 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +4 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.js +2 -2
- package/dist/cjs/driver/runtime-driver.js +17 -2
- package/dist/cjs/expression/expression-builder.d.ts +298 -27
- package/dist/cjs/expression/expression-builder.js +36 -26
- package/dist/cjs/expression/expression-wrapper.d.ts +177 -8
- package/dist/cjs/expression/expression-wrapper.js +4 -4
- package/dist/cjs/expression/expression.d.ts +64 -1
- package/dist/cjs/helpers/mysql.d.ts +11 -8
- package/dist/cjs/helpers/mysql.js +21 -32
- package/dist/cjs/helpers/postgres.d.ts +8 -5
- package/dist/cjs/helpers/postgres.js +8 -5
- package/dist/cjs/helpers/sqlite.d.ts +164 -0
- package/dist/cjs/helpers/sqlite.js +180 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/kysely.d.ts +4 -3
- package/dist/cjs/kysely.js +1 -1
- package/dist/cjs/operation-node/common-table-expression-node.d.ts +4 -0
- package/dist/cjs/operation-node/common-table-expression-node.js +6 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +1 -1
- package/dist/cjs/operation-node/delete-query-node.js +3 -3
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +8 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +3 -3
- package/dist/cjs/operation-node/operator-node.js +3 -0
- package/dist/cjs/operation-node/order-by-node.d.ts +2 -2
- package/dist/cjs/operation-node/order-by-node.js +4 -4
- package/dist/cjs/operation-node/over-node.d.ts +1 -1
- package/dist/cjs/operation-node/over-node.js +3 -3
- package/dist/cjs/operation-node/select-query-node.d.ts +5 -4
- package/dist/cjs/operation-node/select-query-node.js +13 -7
- package/dist/cjs/operation-node/tuple-node.d.ts +12 -0
- package/dist/cjs/operation-node/tuple-node.js +18 -0
- package/dist/cjs/parser/binary-operation-parser.d.ts +11 -7
- package/dist/cjs/parser/binary-operation-parser.js +35 -46
- package/dist/cjs/parser/expression-parser.d.ts +9 -4
- package/dist/cjs/parser/join-parser.d.ts +2 -2
- package/dist/cjs/parser/join-parser.js +2 -3
- package/dist/cjs/parser/order-by-parser.d.ts +6 -2
- package/dist/cjs/parser/order-by-parser.js +41 -7
- package/dist/cjs/parser/parse-utils.js +2 -2
- package/dist/cjs/parser/reference-parser.js +1 -1
- package/dist/cjs/parser/select-parser.d.ts +5 -5
- package/dist/cjs/parser/set-operation-parser.d.ts +3 -1
- package/dist/cjs/parser/set-operation-parser.js +13 -4
- package/dist/cjs/parser/tuple-parser.d.ts +47 -0
- package/dist/cjs/parser/tuple-parser.js +2 -0
- package/dist/cjs/parser/value-parser.d.ts +4 -2
- package/dist/cjs/parser/value-parser.js +12 -1
- package/dist/cjs/parser/with-parser.d.ts +3 -2
- package/dist/cjs/parser/with-parser.js +16 -4
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +3 -3
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +4 -8
- package/dist/cjs/plugin/parse-json-results/parse-json-results-plugin.d.ts +13 -0
- package/dist/cjs/plugin/parse-json-results/parse-json-results-plugin.js +50 -14
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +5 -5
- package/dist/cjs/query-builder/aggregate-function-builder.js +2 -2
- package/dist/cjs/query-builder/case-builder.js +8 -4
- package/dist/cjs/query-builder/cte-builder.d.ts +20 -0
- package/dist/cjs/query-builder/cte-builder.js +39 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +34 -7
- package/dist/cjs/query-builder/delete-query-builder.js +3 -3
- package/dist/cjs/query-builder/function-module.d.ts +41 -6
- package/dist/cjs/query-builder/function-module.js +3 -0
- package/dist/cjs/query-builder/having-interface.d.ts +2 -5
- package/dist/cjs/query-builder/join-builder.d.ts +2 -6
- package/dist/cjs/query-builder/join-builder.js +2 -2
- package/dist/cjs/query-builder/json-path-builder.d.ts +59 -3
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +65 -12
- package/dist/cjs/query-builder/on-conflict-builder.js +4 -4
- package/dist/cjs/query-builder/over-builder.js +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +201 -65
- package/dist/cjs/query-builder/select-query-builder.js +72 -924
- package/dist/cjs/query-builder/update-query-builder.d.ts +34 -7
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-builder/where-interface.d.ts +32 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +39 -7
- package/dist/cjs/query-creator.d.ts +74 -2
- package/dist/cjs/query-creator.js +83 -6
- package/dist/cjs/raw-builder/raw-builder.d.ts +88 -49
- package/dist/cjs/raw-builder/raw-builder.js +18 -45
- package/dist/cjs/raw-builder/sql.js +8 -8
- package/dist/cjs/schema/alter-table-builder.d.ts +4 -0
- package/dist/cjs/schema/alter-table-builder.js +12 -0
- package/dist/cjs/schema/create-index-builder.d.ts +1 -1
- package/dist/cjs/schema/create-index-builder.js +1 -1
- package/dist/cjs/util/column-type.d.ts +7 -6
- package/dist/cjs/util/json-object-args.d.ts +3 -0
- package/dist/cjs/util/json-object-args.js +35 -0
- package/dist/cjs/util/object-utils.d.ts +1 -0
- package/dist/cjs/util/object-utils.js +9 -1
- package/dist/cjs/util/type-utils.d.ts +10 -10
- package/dist/esm/dialect/dialect-adapter-base.d.ts +3 -3
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +3 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +3 -2
- package/dist/esm/dialect/postgres/postgres-adapter.js +2 -2
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +2 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +4 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.js +2 -2
- package/dist/esm/driver/runtime-driver.js +17 -2
- package/dist/esm/expression/expression-builder.d.ts +298 -27
- package/dist/esm/expression/expression-builder.js +40 -30
- package/dist/esm/expression/expression-wrapper.d.ts +177 -8
- package/dist/esm/expression/expression-wrapper.js +5 -5
- package/dist/esm/expression/expression.d.ts +64 -1
- package/dist/esm/helpers/mysql.d.ts +11 -8
- package/dist/esm/helpers/mysql.js +21 -32
- package/dist/esm/helpers/postgres.d.ts +8 -5
- package/dist/esm/helpers/postgres.js +8 -5
- package/dist/esm/helpers/sqlite.d.ts +164 -0
- package/dist/esm/helpers/sqlite.js +175 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/kysely.d.ts +4 -3
- package/dist/esm/kysely.js +1 -1
- package/dist/esm/operation-node/common-table-expression-node.d.ts +4 -0
- package/dist/esm/operation-node/common-table-expression-node.js +6 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +1 -1
- package/dist/esm/operation-node/delete-query-node.js +3 -3
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +8 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +3 -3
- package/dist/esm/operation-node/operator-node.js +3 -0
- package/dist/esm/operation-node/order-by-node.d.ts +2 -2
- package/dist/esm/operation-node/order-by-node.js +4 -4
- package/dist/esm/operation-node/over-node.d.ts +1 -1
- package/dist/esm/operation-node/over-node.js +3 -3
- package/dist/esm/operation-node/select-query-node.d.ts +5 -4
- package/dist/esm/operation-node/select-query-node.js +13 -7
- package/dist/esm/operation-node/tuple-node.d.ts +12 -0
- package/dist/esm/operation-node/tuple-node.js +16 -0
- package/dist/esm/parser/binary-operation-parser.d.ts +11 -7
- package/dist/esm/parser/binary-operation-parser.js +36 -47
- package/dist/esm/parser/expression-parser.d.ts +9 -4
- package/dist/esm/parser/join-parser.d.ts +2 -2
- package/dist/esm/parser/join-parser.js +3 -4
- package/dist/esm/parser/order-by-parser.d.ts +6 -2
- package/dist/esm/parser/order-by-parser.js +40 -7
- package/dist/esm/parser/parse-utils.js +3 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/select-parser.d.ts +5 -5
- package/dist/esm/parser/set-operation-parser.d.ts +3 -1
- package/dist/esm/parser/set-operation-parser.js +11 -2
- package/dist/esm/parser/tuple-parser.d.ts +47 -0
- package/dist/esm/parser/tuple-parser.js +2 -0
- package/dist/esm/parser/value-parser.d.ts +4 -2
- package/dist/esm/parser/value-parser.js +10 -1
- package/dist/esm/parser/with-parser.d.ts +3 -2
- package/dist/esm/parser/with-parser.js +16 -4
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +3 -3
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +5 -9
- package/dist/esm/plugin/parse-json-results/parse-json-results-plugin.d.ts +13 -0
- package/dist/esm/plugin/parse-json-results/parse-json-results-plugin.js +51 -15
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +5 -5
- package/dist/esm/query-builder/aggregate-function-builder.js +3 -3
- package/dist/esm/query-builder/case-builder.js +10 -6
- package/dist/esm/query-builder/cte-builder.d.ts +20 -0
- package/dist/esm/query-builder/cte-builder.js +36 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +34 -7
- package/dist/esm/query-builder/delete-query-builder.js +4 -4
- package/dist/esm/query-builder/function-module.d.ts +41 -6
- package/dist/esm/query-builder/function-module.js +3 -0
- package/dist/esm/query-builder/having-interface.d.ts +2 -5
- package/dist/esm/query-builder/join-builder.d.ts +2 -6
- package/dist/esm/query-builder/join-builder.js +3 -3
- package/dist/esm/query-builder/json-path-builder.d.ts +59 -3
- package/dist/esm/query-builder/on-conflict-builder.d.ts +65 -12
- package/dist/esm/query-builder/on-conflict-builder.js +5 -5
- package/dist/esm/query-builder/over-builder.js +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +201 -65
- package/dist/esm/query-builder/select-query-builder.js +72 -923
- package/dist/esm/query-builder/update-query-builder.d.ts +34 -7
- package/dist/esm/query-builder/update-query-builder.js +3 -3
- package/dist/esm/query-builder/where-interface.d.ts +32 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/esm/query-compiler/default-query-compiler.js +39 -7
- package/dist/esm/query-creator.d.ts +74 -2
- package/dist/esm/query-creator.js +84 -7
- package/dist/esm/raw-builder/raw-builder.d.ts +88 -49
- package/dist/esm/raw-builder/raw-builder.js +17 -42
- package/dist/esm/raw-builder/sql.js +9 -9
- package/dist/esm/schema/alter-table-builder.d.ts +4 -0
- package/dist/esm/schema/alter-table-builder.js +12 -0
- package/dist/esm/schema/create-index-builder.d.ts +1 -1
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +7 -6
- package/dist/esm/util/json-object-args.d.ts +3 -0
- package/dist/esm/util/json-object-args.js +32 -0
- package/dist/esm/util/object-utils.d.ts +1 -0
- package/dist/esm/util/object-utils.js +7 -0
- package/dist/esm/util/type-utils.d.ts +10 -10
- package/helpers/sqlite.d.ts +1 -0
- package/helpers/sqlite.js +1 -0
- package/package.json +7 -4
|
@@ -1,38 +1,21 @@
|
|
|
1
1
|
import { QueryResult } from '../driver/database-connection.js';
|
|
2
|
-
import { AliasNode } from '../operation-node/alias-node.js';
|
|
3
2
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
4
3
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
5
4
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
5
|
import { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
|
|
7
6
|
import { QueryId } from '../util/query-id.js';
|
|
8
|
-
import { AliasedExpression, Expression } from '../expression/expression.js';
|
|
7
|
+
import { AliasableExpression, AliasedExpression, Expression } from '../expression/expression.js';
|
|
9
8
|
/**
|
|
10
9
|
* An instance of this class can be used to create raw SQL snippets or queries.
|
|
11
10
|
*
|
|
12
11
|
* You shouldn't need to create `RawBuilder` instances directly. Instead you should
|
|
13
12
|
* use the {@link sql} template tag.
|
|
14
13
|
*/
|
|
15
|
-
export
|
|
16
|
-
#private;
|
|
17
|
-
constructor(props: RawBuilderProps);
|
|
18
|
-
/** @private */
|
|
14
|
+
export interface RawBuilder<O> extends AliasableExpression<O> {
|
|
19
15
|
/**
|
|
20
|
-
*
|
|
21
|
-
* Simply add this getter for your expression and always return `undefined` from it:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* class SomeExpression<T> implements Expression<T> {
|
|
25
|
-
* get expressionType(): T | undefined {
|
|
26
|
-
* return undefined
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* The getter is needed to make the expression assignable to another expression only
|
|
32
|
-
* if the types `T` are assignable. Without this property (or some other property
|
|
33
|
-
* that references `T`), you could assing `Expression<string>` to `Expression<number>`.
|
|
16
|
+
* @private Without this SelectQueryBuilder extends RawBuilder and things break.
|
|
34
17
|
*/
|
|
35
|
-
get
|
|
18
|
+
get isRawBuilder(): true;
|
|
36
19
|
/**
|
|
37
20
|
* Returns an aliased version of the SQL expression.
|
|
38
21
|
*
|
|
@@ -87,6 +70,62 @@ export declare class RawBuilder<O> implements Expression<O> {
|
|
|
87
70
|
* ```
|
|
88
71
|
*/
|
|
89
72
|
as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns an aliased version of the expression.
|
|
75
|
+
*
|
|
76
|
+
* In addition to slapping `as "the_alias"` at the end of the expression,
|
|
77
|
+
* this method also provides strict typing:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const result = await db
|
|
81
|
+
* .selectFrom('person')
|
|
82
|
+
* .select((eb) =>
|
|
83
|
+
* // `eb.fn<string>` returns an AliasableExpression<string>
|
|
84
|
+
* eb.fn<string>('concat', ['first_name' eb.val(' '), 'last_name']).as('full_name')
|
|
85
|
+
* )
|
|
86
|
+
* .executeTakeFirstOrThrow()
|
|
87
|
+
*
|
|
88
|
+
* // `full_name: string` field exists in the result type.
|
|
89
|
+
* console.log(result.full_name)
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* The generated SQL (PostgreSQL):
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* select
|
|
96
|
+
* concat("first_name", $1, "last_name") as "full_name"
|
|
97
|
+
* from
|
|
98
|
+
* "person"
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
|
102
|
+
* provide the alias as the only type argument:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
106
|
+
*
|
|
107
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
108
|
+
* // in addition to the table name. We must tell kysely that
|
|
109
|
+
* // columns of the table can be referenced through `t`
|
|
110
|
+
* // by providing an explicit type argument.
|
|
111
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
112
|
+
*
|
|
113
|
+
* await db
|
|
114
|
+
* .insertInto('person')
|
|
115
|
+
* .columns(['first_name', 'last_name'])
|
|
116
|
+
* .expression(
|
|
117
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
118
|
+
* )
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* The generated SQL (PostgreSQL):
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* insert into "person" ("first_name", "last_name")
|
|
125
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
126
|
+
* select "t"."a", "t"."b"
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
90
129
|
as<A extends string>(alias: Expression<any>): AliasedRawBuilder<O, A>;
|
|
91
130
|
/**
|
|
92
131
|
* Change the output type of the raw expression.
|
|
@@ -95,14 +134,31 @@ export declare class RawBuilder<O> implements Expression<O> {
|
|
|
95
134
|
* returns a copy of this `RawBuilder` with a new output type.
|
|
96
135
|
*/
|
|
97
136
|
$castTo<T>(): RawBuilder<T>;
|
|
98
|
-
/**
|
|
99
|
-
* @deprecated Use `$castTo` instead.
|
|
100
|
-
*/
|
|
101
|
-
castTo<T>(): RawBuilder<T>;
|
|
102
137
|
/**
|
|
103
138
|
* Adds a plugin for this SQL snippet.
|
|
104
139
|
*/
|
|
105
140
|
withPlugin(plugin: KyselyPlugin): RawBuilder<O>;
|
|
141
|
+
/**
|
|
142
|
+
* Compiles the builder to a `CompiledQuery`.
|
|
143
|
+
*
|
|
144
|
+
* ### Examples
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* const { sql } = sql`select * from ${sql.table('person')}`.compile(db)
|
|
148
|
+
* console.log(sql)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
compile(executorProvider: QueryExecutorProvider): CompiledQuery<O>;
|
|
152
|
+
/**
|
|
153
|
+
* Executes the raw query.
|
|
154
|
+
*
|
|
155
|
+
* ### Examples
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* const result = await sql`select * from ${sql.table('person')}`.execute(db)
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
execute(executorProvider: QueryExecutorProvider): Promise<QueryResult<O>>;
|
|
106
162
|
/**
|
|
107
163
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
108
164
|
*
|
|
@@ -118,33 +174,16 @@ export declare class RawBuilder<O> implements Expression<O> {
|
|
|
118
174
|
* ```
|
|
119
175
|
*/
|
|
120
176
|
toOperationNode(): RawNode;
|
|
121
|
-
compile(executorProvider: QueryExecutorProvider): CompiledQuery<O>;
|
|
122
|
-
execute(executorProvider: QueryExecutorProvider): Promise<QueryResult<O>>;
|
|
123
|
-
}
|
|
124
|
-
export declare function isRawBuilder(obj: unknown): obj is RawBuilder<unknown>;
|
|
125
|
-
/**
|
|
126
|
-
* {@link RawBuilder} with an alias. The result of calling {@link RawBuilder.as}.
|
|
127
|
-
*/
|
|
128
|
-
export declare class AliasedRawBuilder<O = unknown, A extends string = never> implements AliasedExpression<O, A> {
|
|
129
|
-
#private;
|
|
130
|
-
constructor(rawBuilder: RawBuilder<O>, alias: A | Expression<unknown>);
|
|
131
|
-
/** @private */
|
|
132
|
-
/**
|
|
133
|
-
* Returns the aliased expression.
|
|
134
|
-
*/
|
|
135
|
-
get expression(): Expression<O>;
|
|
136
|
-
/** @private */
|
|
137
|
-
/**
|
|
138
|
-
* Returns the alias.
|
|
139
|
-
*/
|
|
140
|
-
get alias(): A | Expression<unknown>;
|
|
141
|
-
/**
|
|
142
|
-
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
143
|
-
*/
|
|
144
|
-
toOperationNode(): AliasNode;
|
|
145
177
|
}
|
|
146
178
|
export interface RawBuilderProps {
|
|
147
179
|
readonly queryId: QueryId;
|
|
148
180
|
readonly rawNode: RawNode;
|
|
149
181
|
readonly plugins?: ReadonlyArray<KyselyPlugin>;
|
|
150
182
|
}
|
|
183
|
+
export declare function createRawBuilder<O>(props: RawBuilderProps): RawBuilder<O>;
|
|
184
|
+
/**
|
|
185
|
+
* {@link RawBuilder} with an alias. The result of calling {@link RawBuilder.as}.
|
|
186
|
+
*/
|
|
187
|
+
export interface AliasedRawBuilder<O = unknown, A extends string = never> extends AliasedExpression<O, A> {
|
|
188
|
+
get rawBuilder(): RawBuilder<O>;
|
|
189
|
+
}
|
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createRawBuilder = void 0;
|
|
4
4
|
const alias_node_js_1 = require("../operation-node/alias-node.js");
|
|
5
5
|
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
6
6
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
7
7
|
const noop_query_executor_js_1 = require("../query-executor/noop-query-executor.js");
|
|
8
8
|
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
9
9
|
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
10
|
-
|
|
11
|
-
* An instance of this class can be used to create raw SQL snippets or queries.
|
|
12
|
-
*
|
|
13
|
-
* You shouldn't need to create `RawBuilder` instances directly. Instead you should
|
|
14
|
-
* use the {@link sql} template tag.
|
|
15
|
-
*/
|
|
16
|
-
class RawBuilder {
|
|
10
|
+
class RawBuilderImpl {
|
|
17
11
|
#props;
|
|
18
12
|
constructor(props) {
|
|
19
13
|
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
20
14
|
}
|
|
21
|
-
/** @private */
|
|
22
15
|
get expressionType() {
|
|
23
16
|
return undefined;
|
|
24
17
|
}
|
|
18
|
+
get isRawBuilder() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
25
21
|
as(alias) {
|
|
26
|
-
return new
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Change the output type of the raw expression.
|
|
30
|
-
*
|
|
31
|
-
* This method call doesn't change the SQL in any way. This methods simply
|
|
32
|
-
* returns a copy of this `RawBuilder` with a new output type.
|
|
33
|
-
*/
|
|
34
|
-
$castTo() {
|
|
35
|
-
return new RawBuilder({ ...this.#props });
|
|
22
|
+
return new AliasedRawBuilderImpl(this, alias);
|
|
36
23
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
castTo() {
|
|
41
|
-
return this.$castTo();
|
|
24
|
+
$castTo() {
|
|
25
|
+
return new RawBuilderImpl({ ...this.#props });
|
|
42
26
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Adds a plugin for this SQL snippet.
|
|
45
|
-
*/
|
|
46
27
|
withPlugin(plugin) {
|
|
47
|
-
return new
|
|
28
|
+
return new RawBuilderImpl({
|
|
48
29
|
...this.#props,
|
|
49
30
|
plugins: this.#props.plugins !== undefined
|
|
50
31
|
? (0, object_utils_js_1.freeze)([...this.#props.plugins, plugin])
|
|
@@ -76,39 +57,31 @@ class RawBuilder {
|
|
|
76
57
|
return executor.compileQuery(this.#toOperationNode(executor), this.#props.queryId);
|
|
77
58
|
}
|
|
78
59
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return ((0, object_utils_js_1.isObject)(obj) &&
|
|
82
|
-
(0, object_utils_js_1.isFunction)(obj.as) &&
|
|
83
|
-
(0, object_utils_js_1.isFunction)(obj.$castTo) &&
|
|
84
|
-
(0, object_utils_js_1.isFunction)(obj.withPlugin) &&
|
|
85
|
-
(0, object_utils_js_1.isFunction)(obj.toOperationNode) &&
|
|
86
|
-
(0, object_utils_js_1.isFunction)(obj.execute));
|
|
60
|
+
function createRawBuilder(props) {
|
|
61
|
+
return new RawBuilderImpl(props);
|
|
87
62
|
}
|
|
88
|
-
exports.
|
|
89
|
-
(0, prevent_await_js_1.preventAwait)(
|
|
90
|
-
|
|
91
|
-
* {@link RawBuilder} with an alias. The result of calling {@link RawBuilder.as}.
|
|
92
|
-
*/
|
|
93
|
-
class AliasedRawBuilder {
|
|
63
|
+
exports.createRawBuilder = createRawBuilder;
|
|
64
|
+
(0, prevent_await_js_1.preventAwait)(RawBuilderImpl, "don't await RawBuilder instances directly. To execute the query you need to call `execute`");
|
|
65
|
+
class AliasedRawBuilderImpl {
|
|
94
66
|
#rawBuilder;
|
|
95
67
|
#alias;
|
|
96
68
|
constructor(rawBuilder, alias) {
|
|
97
69
|
this.#rawBuilder = rawBuilder;
|
|
98
70
|
this.#alias = alias;
|
|
99
71
|
}
|
|
100
|
-
/** @private */
|
|
101
72
|
get expression() {
|
|
102
73
|
return this.#rawBuilder;
|
|
103
74
|
}
|
|
104
|
-
/** @private */
|
|
105
75
|
get alias() {
|
|
106
76
|
return this.#alias;
|
|
107
77
|
}
|
|
78
|
+
get rawBuilder() {
|
|
79
|
+
return this.#rawBuilder;
|
|
80
|
+
}
|
|
108
81
|
toOperationNode() {
|
|
109
82
|
return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), (0, operation_node_source_js_1.isOperationNodeSource)(this.#alias)
|
|
110
83
|
? this.#alias.toOperationNode()
|
|
111
84
|
: identifier_node_js_1.IdentifierNode.create(this.#alias));
|
|
112
85
|
}
|
|
113
86
|
}
|
|
114
|
-
|
|
87
|
+
(0, prevent_await_js_1.preventAwait)(AliasedRawBuilderImpl, "don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");
|
|
@@ -10,19 +10,19 @@ const value_parser_js_1 = require("../parser/value-parser.js");
|
|
|
10
10
|
const query_id_js_1 = require("../util/query-id.js");
|
|
11
11
|
const raw_builder_js_1 = require("./raw-builder.js");
|
|
12
12
|
exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
|
13
|
-
return
|
|
13
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
14
14
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
15
15
|
rawNode: raw_node_js_1.RawNode.create(sqlFragments, parameters?.map(value_parser_js_1.parseValueExpression) ?? []),
|
|
16
16
|
});
|
|
17
17
|
}, {
|
|
18
18
|
ref(columnReference) {
|
|
19
|
-
return
|
|
19
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
20
20
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
21
21
|
rawNode: raw_node_js_1.RawNode.createWithChild((0, reference_parser_js_1.parseStringReference)(columnReference)),
|
|
22
22
|
});
|
|
23
23
|
},
|
|
24
24
|
val(value) {
|
|
25
|
-
return
|
|
25
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
26
26
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
27
27
|
rawNode: raw_node_js_1.RawNode.createWithChild((0, value_parser_js_1.parseValueExpression)(value)),
|
|
28
28
|
});
|
|
@@ -31,7 +31,7 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
|
|
31
31
|
return this.val(value);
|
|
32
32
|
},
|
|
33
33
|
table(tableReference) {
|
|
34
|
-
return
|
|
34
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
35
35
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
36
36
|
rawNode: raw_node_js_1.RawNode.createWithChild((0, table_parser_js_1.parseTable)(tableReference)),
|
|
37
37
|
});
|
|
@@ -40,13 +40,13 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
|
|
40
40
|
const fragments = new Array(ids.length + 1).fill('.');
|
|
41
41
|
fragments[0] = '';
|
|
42
42
|
fragments[fragments.length - 1] = '';
|
|
43
|
-
return
|
|
43
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
44
44
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
45
45
|
rawNode: raw_node_js_1.RawNode.create(fragments, ids.map(identifier_node_js_1.IdentifierNode.create)),
|
|
46
46
|
});
|
|
47
47
|
},
|
|
48
48
|
lit(value) {
|
|
49
|
-
return
|
|
49
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
50
50
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
51
51
|
rawNode: raw_node_js_1.RawNode.createWithChild(value_node_js_1.ValueNode.createImmediate(value)),
|
|
52
52
|
});
|
|
@@ -55,7 +55,7 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
|
|
55
55
|
return this.lit(value);
|
|
56
56
|
},
|
|
57
57
|
raw(sql) {
|
|
58
|
-
return
|
|
58
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
59
59
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
60
60
|
rawNode: raw_node_js_1.RawNode.createWithSql(sql),
|
|
61
61
|
});
|
|
@@ -69,7 +69,7 @@ exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
|
|
69
69
|
nodes[2 * i + 1] = sep;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return (0, raw_builder_js_1.createRawBuilder)({
|
|
73
73
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
74
74
|
rawNode: raw_node_js_1.RawNode.createWithChildren(nodes),
|
|
75
75
|
});
|
|
@@ -48,6 +48,10 @@ export declare class AlterTableBuilder implements ColumnAlteringInterface {
|
|
|
48
48
|
* is because you can only add one column per `ALTER TABLE` query.
|
|
49
49
|
*/
|
|
50
50
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
51
|
+
/**
|
|
52
|
+
* See {@link CreateTableBuilder.addPrimaryKeyConstraint}
|
|
53
|
+
*/
|
|
54
|
+
addPrimaryKeyConstraint(constraintName: string, columns: string[]): AlterTableExecutor;
|
|
51
55
|
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
|
52
56
|
/**
|
|
53
57
|
* Calls the given function passing `this` as the only argument.
|
|
@@ -24,6 +24,7 @@ const alter_column_builder_js_1 = require("./alter-column-builder.js");
|
|
|
24
24
|
const alter_table_executor_js_1 = require("./alter-table-executor.js");
|
|
25
25
|
const alter_table_add_foreign_key_constraint_builder_js_1 = require("./alter-table-add-foreign-key-constraint-builder.js");
|
|
26
26
|
const alter_table_drop_constraint_builder_js_1 = require("./alter-table-drop-constraint-builder.js");
|
|
27
|
+
const primary_constraint_node_js_1 = require("../operation-node/primary-constraint-node.js");
|
|
27
28
|
/**
|
|
28
29
|
* This builder can be used to create a `alter table` query.
|
|
29
30
|
*/
|
|
@@ -116,6 +117,17 @@ class AlterTableBuilder {
|
|
|
116
117
|
constraintBuilder: new foreign_key_constraint_builder_js_1.ForeignKeyConstraintBuilder(foreign_key_constraint_node_js_1.ForeignKeyConstraintNode.create(columns.map(column_node_js_1.ColumnNode.create), (0, table_parser_js_1.parseTable)(targetTable), targetColumns.map(column_node_js_1.ColumnNode.create), constraintName)),
|
|
117
118
|
});
|
|
118
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* See {@link CreateTableBuilder.addPrimaryKeyConstraint}
|
|
122
|
+
*/
|
|
123
|
+
addPrimaryKeyConstraint(constraintName, columns) {
|
|
124
|
+
return new alter_table_executor_js_1.AlterTableExecutor({
|
|
125
|
+
...this.#props,
|
|
126
|
+
node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
|
|
127
|
+
addConstraint: add_constraint_node_js_1.AddConstraintNode.create(primary_constraint_node_js_1.PrimaryConstraintNode.create(columns, constraintName)),
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
119
131
|
dropConstraint(constraintName) {
|
|
120
132
|
return new alter_table_drop_constraint_builder_js_1.AlterTableDropConstraintBuilder({
|
|
121
133
|
...this.#props,
|
|
@@ -133,7 +133,7 @@ export declare class CreateIndexBuilder<C = never> implements OperationNodeSourc
|
|
|
133
133
|
*/
|
|
134
134
|
where(lhs: C | Expression<any>, op: ComparisonOperatorExpression, rhs: unknown): CreateIndexBuilder<C>;
|
|
135
135
|
where(factory: (qb: ExpressionBuilder<ShallowRecord<string, ShallowRecord<C & string, any>>, string>) => Expression<SqlBool>): CreateIndexBuilder<C>;
|
|
136
|
-
where(expression: Expression<
|
|
136
|
+
where(expression: Expression<SqlBool>): CreateIndexBuilder<C>;
|
|
137
137
|
/**
|
|
138
138
|
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
139
139
|
* what the provided function returns.
|
|
@@ -150,7 +150,7 @@ class CreateIndexBuilder {
|
|
|
150
150
|
const transformer = new immediate_value_transformer_js_1.ImmediateValueTransformer();
|
|
151
151
|
return new CreateIndexBuilder({
|
|
152
152
|
...this.#props,
|
|
153
|
-
node: query_node_js_1.QueryNode.cloneWithWhere(this.#props.node, transformer.transformNode((0, binary_operation_parser_js_1.
|
|
153
|
+
node: query_node_js_1.QueryNode.cloneWithWhere(this.#props.node, transformer.transformNode((0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args))),
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DrainOuterGeneric } from './type-utils.js';
|
|
1
2
|
/**
|
|
2
3
|
* This type can be used to specify a different type for
|
|
3
4
|
* select, insert and update operations.
|
|
@@ -123,9 +124,9 @@ export type UpdateKeys<R> = {
|
|
|
123
124
|
* // }
|
|
124
125
|
* ```
|
|
125
126
|
*/
|
|
126
|
-
export type Selectable<R> = {
|
|
127
|
+
export type Selectable<R> = DrainOuterGeneric<{
|
|
127
128
|
[K in NonNeverSelectKeys<R>]: SelectType<R[K]>;
|
|
128
|
-
}
|
|
129
|
+
}>;
|
|
129
130
|
/**
|
|
130
131
|
* Given a table interface, extracts the insert type from all
|
|
131
132
|
* {@link ColumnType} types.
|
|
@@ -147,11 +148,11 @@ export type Selectable<R> = {
|
|
|
147
148
|
* // }
|
|
148
149
|
* ```
|
|
149
150
|
*/
|
|
150
|
-
export type Insertable<R> = {
|
|
151
|
+
export type Insertable<R> = DrainOuterGeneric<{
|
|
151
152
|
[K in NonNullableInsertKeys<R>]: InsertType<R[K]>;
|
|
152
153
|
} & {
|
|
153
154
|
[K in NullableInsertKeys<R>]?: InsertType<R[K]>;
|
|
154
|
-
}
|
|
155
|
+
}>;
|
|
155
156
|
/**
|
|
156
157
|
* Given a table interface, extracts the update type from all
|
|
157
158
|
* {@link ColumnType} types.
|
|
@@ -172,7 +173,7 @@ export type Insertable<R> = {
|
|
|
172
173
|
* // }
|
|
173
174
|
* ```
|
|
174
175
|
*/
|
|
175
|
-
export type Updateable<R> = {
|
|
176
|
+
export type Updateable<R> = DrainOuterGeneric<{
|
|
176
177
|
[K in UpdateKeys<R>]?: UpdateType<R[K]>;
|
|
177
|
-
}
|
|
178
|
+
}>;
|
|
178
179
|
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonObjectArgs = void 0;
|
|
4
|
+
const expression_wrapper_js_1 = require("../expression/expression-wrapper.js");
|
|
5
|
+
const alias_node_js_1 = require("../operation-node/alias-node.js");
|
|
6
|
+
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
7
|
+
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
8
|
+
const reference_node_js_1 = require("../operation-node/reference-node.js");
|
|
9
|
+
const table_node_js_1 = require("../operation-node/table-node.js");
|
|
10
|
+
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
11
|
+
function getJsonObjectArgs(node, table) {
|
|
12
|
+
const args = [];
|
|
13
|
+
for (const { selection: s } of node.selections ?? []) {
|
|
14
|
+
if (reference_node_js_1.ReferenceNode.is(s) && column_node_js_1.ColumnNode.is(s.column)) {
|
|
15
|
+
args.push(colName(s.column.column.name), colRef(table, s.column.column.name));
|
|
16
|
+
}
|
|
17
|
+
else if (column_node_js_1.ColumnNode.is(s)) {
|
|
18
|
+
args.push(colName(s.column.name), colRef(table, s.column.name));
|
|
19
|
+
}
|
|
20
|
+
else if (alias_node_js_1.AliasNode.is(s) && identifier_node_js_1.IdentifierNode.is(s.alias)) {
|
|
21
|
+
args.push(colName(s.alias.name), colRef(table, s.alias.name));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`can't extract column names from the select query node`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return args;
|
|
28
|
+
}
|
|
29
|
+
exports.getJsonObjectArgs = getJsonObjectArgs;
|
|
30
|
+
function colName(col) {
|
|
31
|
+
return new expression_wrapper_js_1.ExpressionWrapper(value_node_js_1.ValueNode.createImmediate(col));
|
|
32
|
+
}
|
|
33
|
+
function colRef(table, col) {
|
|
34
|
+
return new expression_wrapper_js_1.ExpressionWrapper(reference_node_js_1.ReferenceNode.create(column_node_js_1.ColumnNode.create(col), table_node_js_1.TableNode.create(table)));
|
|
35
|
+
}
|
|
@@ -13,6 +13,7 @@ export declare function isBuffer(obj: unknown): obj is {
|
|
|
13
13
|
export declare function isFunction(obj: unknown): obj is Function;
|
|
14
14
|
export declare function isObject(obj: unknown): obj is ShallowRecord<string, unknown>;
|
|
15
15
|
export declare function isArrayBufferOrView(obj: unknown): obj is ArrayBuffer | ArrayBufferView;
|
|
16
|
+
export declare function isPlainObject(obj: unknown): obj is Record<string, unknown>;
|
|
16
17
|
export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
|
|
17
18
|
export declare function freeze<T>(obj: T): Readonly<T>;
|
|
18
19
|
export declare function asArray<T>(arg: T | T[]): T[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compare = exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isArrayBufferOrView = exports.isObject = exports.isFunction = exports.isBuffer = exports.isBigInt = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isUndefined = exports.isEmpty = void 0;
|
|
3
|
+
exports.compare = exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isPlainObject = exports.isArrayBufferOrView = exports.isObject = exports.isFunction = exports.isBuffer = exports.isBigInt = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isUndefined = exports.isEmpty = void 0;
|
|
4
4
|
function isEmpty(obj) {
|
|
5
5
|
if (Array.isArray(obj) || isString(obj) || isBuffer(obj)) {
|
|
6
6
|
return obj.length === 0;
|
|
@@ -57,6 +57,14 @@ function isArrayBufferOrView(obj) {
|
|
|
57
57
|
return obj instanceof ArrayBuffer || ArrayBuffer.isView(obj);
|
|
58
58
|
}
|
|
59
59
|
exports.isArrayBufferOrView = isArrayBufferOrView;
|
|
60
|
+
function isPlainObject(obj) {
|
|
61
|
+
return (isObject(obj) &&
|
|
62
|
+
!Array.isArray(obj) &&
|
|
63
|
+
!isDate(obj) &&
|
|
64
|
+
!isBuffer(obj) &&
|
|
65
|
+
!isArrayBufferOrView(obj));
|
|
66
|
+
}
|
|
67
|
+
exports.isPlainObject = isPlainObject;
|
|
60
68
|
function getLast(arr) {
|
|
61
69
|
return arr[arr.length - 1];
|
|
62
70
|
}
|
|
@@ -40,9 +40,9 @@ export type AnyColumn<DB, TB extends keyof DB> = DrainOuterGeneric<{
|
|
|
40
40
|
/**
|
|
41
41
|
* Extracts a column type.
|
|
42
42
|
*/
|
|
43
|
-
export type ExtractColumnType<DB, TB extends keyof DB, C> = {
|
|
43
|
+
export type ExtractColumnType<DB, TB extends keyof DB, C> = DrainOuterGeneric<{
|
|
44
44
|
[T in TB]: C extends keyof DB[T] ? DB[T][C] : never;
|
|
45
|
-
}[TB]
|
|
45
|
+
}[TB]>;
|
|
46
46
|
/**
|
|
47
47
|
* Given a database type and a union of table names in that db, returns
|
|
48
48
|
* a union type with all possible `table`.`column` combinations.
|
|
@@ -74,21 +74,21 @@ export type ExtractColumnType<DB, TB extends keyof DB, C> = {
|
|
|
74
74
|
* // Columns == 'person.id' | 'pet.name' | 'pet.species'
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
export type AnyColumnWithTable<DB, TB extends keyof DB> = {
|
|
77
|
+
export type AnyColumnWithTable<DB, TB extends keyof DB> = DrainOuterGeneric<{
|
|
78
78
|
[T in TB]: T extends string ? keyof DB[T] extends string ? `${T}.${keyof DB[T]}` : never : never;
|
|
79
|
-
}[TB]
|
|
79
|
+
}[TB]>;
|
|
80
80
|
/**
|
|
81
81
|
* Just like {@link AnyColumn} but with a ` as <string>` suffix.
|
|
82
82
|
*/
|
|
83
|
-
export type AnyAliasedColumn<DB, TB extends keyof DB> = {
|
|
83
|
+
export type AnyAliasedColumn<DB, TB extends keyof DB> = DrainOuterGeneric<{
|
|
84
84
|
[T in TB]: T extends string ? keyof DB[T] extends string ? `${keyof DB[T]} as ${string}` : never : never;
|
|
85
|
-
}[TB]
|
|
85
|
+
}[TB]>;
|
|
86
86
|
/**
|
|
87
87
|
* Just like {@link AnyColumnWithTable} but with a ` as <string>` suffix.
|
|
88
88
|
*/
|
|
89
|
-
export type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = {
|
|
89
|
+
export type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = DrainOuterGeneric<{
|
|
90
90
|
[T in TB]: T extends string ? keyof DB[T] extends string ? `${T}.${keyof DB[T]} as ${string}` : never : never;
|
|
91
|
-
}[TB]
|
|
91
|
+
}[TB]>;
|
|
92
92
|
/**
|
|
93
93
|
* Extracts the item type of an array.
|
|
94
94
|
*/
|
|
@@ -124,9 +124,9 @@ export type IsAny<T> = 0 extends T & 1 ? true : false;
|
|
|
124
124
|
* Evaluates to `true` if the types `T` and `U` are equal.
|
|
125
125
|
*/
|
|
126
126
|
export type Equals<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
|
127
|
-
export type NarrowPartial<S, T> = DrainOuterGeneric<{
|
|
127
|
+
export type NarrowPartial<S, T> = DrainOuterGeneric<T extends object ? {
|
|
128
128
|
[K in keyof S & string]: K extends keyof T ? T[K] extends S[K] ? T[K] : KyselyTypeError<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : S[K];
|
|
129
|
-
}>;
|
|
129
|
+
} : never>;
|
|
130
130
|
export type SqlBool = boolean | 0 | 1;
|
|
131
131
|
/**
|
|
132
132
|
* Utility to reduce depth of TypeScript's internal type instantiation stack.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Kysely } from '../kysely.js';
|
|
2
|
-
import { DialectAdapter } from './dialect-adapter.js';
|
|
2
|
+
import { DialectAdapter, MigrationLockOptions } from './dialect-adapter.js';
|
|
3
3
|
/**
|
|
4
4
|
* A basic implementation of `DialectAdapter` with sensible default values.
|
|
5
5
|
* 3rd party dialects can extend this instead of implementing the `DialectAdapter`
|
|
@@ -63,7 +63,7 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
|
63
63
|
* `db` is a single connection (session) that will be used to execute the
|
|
64
64
|
* migrations.
|
|
65
65
|
*/
|
|
66
|
-
abstract acquireMigrationLock(db: Kysely<any
|
|
66
|
+
abstract acquireMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
|
|
67
67
|
/**
|
|
68
68
|
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
69
69
|
*
|
|
@@ -72,5 +72,5 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
|
72
72
|
* is a single connection (session) that was used to execute the migrations
|
|
73
73
|
* and the `acquireMigrationLock` call.
|
|
74
74
|
*/
|
|
75
|
-
abstract releaseMigrationLock(db: Kysely<any
|
|
75
|
+
abstract releaseMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
|
|
76
76
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Kysely } from '../../kysely.js';
|
|
2
2
|
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
3
|
+
import { MigrationLockOptions } from '../dialect-adapter.js';
|
|
3
4
|
export declare class MysqlAdapter extends DialectAdapterBase {
|
|
4
5
|
/**
|
|
5
6
|
* Whether or not this dialect supports transactional DDL.
|
|
@@ -57,7 +58,7 @@ export declare class MysqlAdapter extends DialectAdapterBase {
|
|
|
57
58
|
* `db` is a single connection (session) that will be used to execute the
|
|
58
59
|
* migrations.
|
|
59
60
|
*/
|
|
60
|
-
acquireMigrationLock(db: Kysely<any
|
|
61
|
+
acquireMigrationLock(db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
|
|
61
62
|
/**
|
|
62
63
|
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
63
64
|
*
|
|
@@ -66,5 +67,5 @@ export declare class MysqlAdapter extends DialectAdapterBase {
|
|
|
66
67
|
* is a single connection (session) that was used to execute the migrations
|
|
67
68
|
* and the `acquireMigrationLock` call.
|
|
68
69
|
*/
|
|
69
|
-
releaseMigrationLock(db: Kysely<any
|
|
70
|
+
releaseMigrationLock(db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
|
|
70
71
|
}
|
|
@@ -10,7 +10,7 @@ export class MysqlAdapter extends DialectAdapterBase {
|
|
|
10
10
|
get supportsReturning() {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
async acquireMigrationLock(db) {
|
|
13
|
+
async acquireMigrationLock(db, _opt) {
|
|
14
14
|
// Kysely uses a single connection to run the migrations. Because of that, we
|
|
15
15
|
// can take a lock using `get_lock`. Locks acquired using `get_lock` get
|
|
16
16
|
// released when the connection is destroyed (session ends) or when the lock
|
|
@@ -19,7 +19,7 @@ export class MysqlAdapter extends DialectAdapterBase {
|
|
|
19
19
|
// MySQL if the process gets killed for some reason.
|
|
20
20
|
await sql `select get_lock(${sql.lit(LOCK_ID)}, ${sql.lit(LOCK_TIMEOUT_SECONDS)})`.execute(db);
|
|
21
21
|
}
|
|
22
|
-
async releaseMigrationLock(db) {
|
|
22
|
+
async releaseMigrationLock(db, _opt) {
|
|
23
23
|
await sql `select release_lock(${sql.lit(LOCK_ID)})`.execute(db);
|
|
24
24
|
}
|
|
25
25
|
}
|