kysely 0.23.3 → 0.23.4
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 +22 -24
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/migration/migrator.d.ts +8 -3
- package/dist/cjs/migration/migrator.js +15 -5
- package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/delete-query-node.js +9 -0
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +9 -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 +1 -1
- package/dist/cjs/operation-node/operator-node.js +1 -0
- package/dist/cjs/operation-node/using-node.d.ts +13 -0
- package/dist/cjs/operation-node/using-node.js +24 -0
- package/dist/cjs/parser/update-set-parser.d.ts +1 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +98 -6
- package/dist/cjs/query-builder/delete-query-builder.js +39 -8
- package/dist/cjs/query-builder/insert-query-builder.d.ts +21 -5
- package/dist/cjs/query-builder/insert-query-builder.js +32 -8
- package/dist/cjs/query-builder/select-query-builder.d.ts +43 -27
- package/dist/cjs/query-builder/select-query-builder.js +53 -29
- package/dist/cjs/query-builder/update-query-builder.d.ts +21 -5
- package/dist/cjs/query-builder/update-query-builder.js +32 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +11 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
- package/dist/cjs/raw-builder/raw-builder.js +8 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
- package/dist/cjs/schema/alter-table-builder.js +8 -2
- package/dist/cjs/schema/create-index-builder.d.ts +6 -0
- package/dist/cjs/schema/create-index-builder.js +13 -0
- package/dist/cjs/schema/create-table-builder.d.ts +6 -2
- package/dist/cjs/schema/create-table-builder.js +9 -3
- package/dist/cjs/util/type-utils.d.ts +18 -0
- package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/esm/dialect/postgres/postgres-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/migration/migrator.d.ts +8 -3
- package/dist/esm/migration/migrator.js +15 -5
- package/dist/esm/operation-node/create-index-node.d.ts +1 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
- package/dist/esm/operation-node/delete-query-node.js +9 -0
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +9 -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 +1 -1
- package/dist/esm/operation-node/operator-node.js +1 -0
- package/dist/esm/operation-node/using-node.d.ts +13 -0
- package/dist/esm/operation-node/using-node.js +22 -0
- package/dist/esm/parser/update-set-parser.d.ts +1 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +98 -6
- package/dist/esm/query-builder/delete-query-builder.js +39 -8
- package/dist/esm/query-builder/insert-query-builder.d.ts +21 -5
- package/dist/esm/query-builder/insert-query-builder.js +33 -9
- package/dist/esm/query-builder/select-query-builder.d.ts +43 -27
- package/dist/esm/query-builder/select-query-builder.js +53 -29
- package/dist/esm/query-builder/update-query-builder.d.ts +21 -5
- package/dist/esm/query-builder/update-query-builder.js +32 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +11 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
- package/dist/esm/raw-builder/raw-builder.js +8 -2
- package/dist/esm/schema/alter-table-builder.d.ts +5 -1
- package/dist/esm/schema/alter-table-builder.js +8 -2
- package/dist/esm/schema/create-index-builder.d.ts +6 -0
- package/dist/esm/schema/create-index-builder.js +13 -0
- package/dist/esm/schema/create-table-builder.d.ts +6 -2
- package/dist/esm/schema/create-table-builder.js +9 -3
- package/dist/esm/util/type-utils.d.ts +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -207,37 +207,34 @@ among other places.
|
|
|
207
207
|
import { Pool } from 'pg'
|
|
208
208
|
// or `import * as Cursor from 'pg-cursor'` depending on your tsconfig
|
|
209
209
|
import Cursor from 'pg-cursor'
|
|
210
|
-
import {
|
|
211
|
-
Kysely,
|
|
212
|
-
PostgresDialect,
|
|
213
|
-
} from 'kysely'
|
|
210
|
+
import { Kysely, PostgresDialect } from 'kysely'
|
|
214
211
|
|
|
215
212
|
const db = new Kysely<Database>({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}),
|
|
222
|
-
cursor: Cursor
|
|
213
|
+
// PostgresDialect requires the Cursor dependency
|
|
214
|
+
dialect: new PostgresDialect({
|
|
215
|
+
pool: new Pool({
|
|
216
|
+
host: 'localhost',
|
|
217
|
+
database: 'kysely_test'
|
|
223
218
|
}),
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
cursor: Cursor
|
|
220
|
+
}),
|
|
221
|
+
// MysqlDialect doesn't require any special configuration
|
|
226
222
|
})
|
|
227
223
|
|
|
228
224
|
async function demo() {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
225
|
+
for await (const adult of db.selectFrom('person')
|
|
226
|
+
.selectAll()
|
|
227
|
+
.where('age', '>', 18)
|
|
228
|
+
.stream()
|
|
229
|
+
) {
|
|
230
|
+
console.log(`Hello ${adult.first_name}!`)
|
|
231
|
+
|
|
232
|
+
if (adult.first_name === 'John') {
|
|
233
|
+
// After this line the db connection is released and no more
|
|
234
|
+
// rows are streamed from the database to the client
|
|
235
|
+
break;
|
|
240
236
|
}
|
|
237
|
+
}
|
|
241
238
|
}
|
|
242
239
|
```
|
|
243
240
|
|
|
@@ -268,6 +265,7 @@ or "recipes" for common use cases.
|
|
|
268
265
|
* [Extending kysely](https://github.com/koskimas/kysely/tree/master/recipes/extending-kysely.md)
|
|
269
266
|
* [Raw SQL](https://github.com/koskimas/kysely/tree/master/recipes/raw-sql.md)
|
|
270
267
|
* [Schemas](https://github.com/koskimas/kysely/tree/master/recipes/schemas.md)
|
|
268
|
+
* [Dealing with the `Type instantiation is excessively deep and possibly infinite` error](https://github.com/koskimas/kysely/tree/master/recipes/excessively-deep-types.md)
|
|
271
269
|
|
|
272
270
|
# Migrations
|
|
273
271
|
|
|
@@ -25,12 +25,38 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
|
25
25
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
26
26
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
27
27
|
*
|
|
28
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
29
|
-
* created by Kysely can be used instead.
|
|
30
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
29
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
30
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
31
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
32
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
33
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
34
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
35
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
36
|
+
*
|
|
37
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
38
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* {
|
|
42
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
43
|
+
* const queryDb = options.lockTableSchema
|
|
44
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
45
|
+
* : db
|
|
46
|
+
*
|
|
47
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
48
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
49
|
+
* // all subsequent calls to this method from other transactions will
|
|
50
|
+
* // wait until this transaction finishes.
|
|
51
|
+
* await queryDb
|
|
52
|
+
* .selectFrom(options.lockTable)
|
|
53
|
+
* .selectAll()
|
|
54
|
+
* .where('id', '=', options.lockRowId)
|
|
55
|
+
* .forUpdate()
|
|
56
|
+
* .execute()
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
34
60
|
*
|
|
35
61
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
36
62
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
@@ -26,19 +26,45 @@ export interface DialectAdapter {
|
|
|
26
26
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
27
27
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
28
28
|
*
|
|
29
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
30
|
-
* created by Kysely can be used instead.
|
|
31
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
30
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
31
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
32
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
33
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
34
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
35
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
36
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
37
|
+
*
|
|
38
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
39
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* {
|
|
43
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
44
|
+
* const queryDb = options.lockTableSchema
|
|
45
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
46
|
+
* : db
|
|
47
|
+
*
|
|
48
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
49
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
50
|
+
* // all subsequent calls to this method from other transactions will
|
|
51
|
+
* // wait until this transaction finishes.
|
|
52
|
+
* await queryDb
|
|
53
|
+
* .selectFrom(options.lockTable)
|
|
54
|
+
* .selectAll()
|
|
55
|
+
* .where('id', '=', options.lockRowId)
|
|
56
|
+
* .forUpdate()
|
|
57
|
+
* .execute()
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
35
61
|
*
|
|
36
62
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
37
63
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
38
64
|
* `db` is a single connection (session) that will be used to execute the
|
|
39
65
|
* migrations.
|
|
40
66
|
*/
|
|
41
|
-
acquireMigrationLock(db: Kysely<any
|
|
67
|
+
acquireMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
|
|
42
68
|
/**
|
|
43
69
|
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
44
70
|
*
|
|
@@ -47,5 +73,21 @@ export interface DialectAdapter {
|
|
|
47
73
|
* is a single connection (session) that was used to execute the migrations
|
|
48
74
|
* and the `acquireMigrationLock` call.
|
|
49
75
|
*/
|
|
50
|
-
releaseMigrationLock(db: Kysely<any
|
|
76
|
+
releaseMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface MigrationLockOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The name of the migration lock table.
|
|
81
|
+
*/
|
|
82
|
+
readonly lockTable: string;
|
|
83
|
+
/**
|
|
84
|
+
* The id of the only row in the migration lock table.
|
|
85
|
+
*/
|
|
86
|
+
readonly lockRowId: string;
|
|
87
|
+
/**
|
|
88
|
+
* The schema in which the migration lock table lives. This is only
|
|
89
|
+
* defined if the user has specified a custom schema in the migration
|
|
90
|
+
* settings.
|
|
91
|
+
*/
|
|
92
|
+
readonly lockTableSchema?: string;
|
|
51
93
|
}
|
|
@@ -19,12 +19,38 @@ export declare class MysqlAdapter extends DialectAdapterBase {
|
|
|
19
19
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
20
20
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
21
21
|
*
|
|
22
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
23
|
-
* created by Kysely can be used instead.
|
|
24
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
23
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
24
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
25
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
26
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
27
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
28
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
29
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
30
|
+
*
|
|
31
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
32
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* {
|
|
36
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
37
|
+
* const queryDb = options.lockTableSchema
|
|
38
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
39
|
+
* : db
|
|
40
|
+
*
|
|
41
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
42
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
43
|
+
* // all subsequent calls to this method from other transactions will
|
|
44
|
+
* // wait until this transaction finishes.
|
|
45
|
+
* await queryDb
|
|
46
|
+
* .selectFrom(options.lockTable)
|
|
47
|
+
* .selectAll()
|
|
48
|
+
* .where('id', '=', options.lockRowId)
|
|
49
|
+
* .forUpdate()
|
|
50
|
+
* .execute()
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
28
54
|
*
|
|
29
55
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
30
56
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
@@ -13,7 +13,7 @@ class MysqlIntrospector {
|
|
|
13
13
|
let rawSchemas = await this.#db
|
|
14
14
|
.selectFrom('information_schema.schemata')
|
|
15
15
|
.select('schema_name')
|
|
16
|
-
|
|
16
|
+
.$castTo()
|
|
17
17
|
.execute();
|
|
18
18
|
return rawSchemas.map((it) => ({ name: it.SCHEMA_NAME }));
|
|
19
19
|
}
|
|
@@ -32,7 +32,7 @@ class MysqlIntrospector {
|
|
|
32
32
|
.where('table_schema', '=', (0, sql_js_1.sql) `database()`)
|
|
33
33
|
.orderBy('table_name')
|
|
34
34
|
.orderBy('ordinal_position')
|
|
35
|
-
|
|
35
|
+
.$castTo();
|
|
36
36
|
if (!options.withInternalKyselyTables) {
|
|
37
37
|
query = query
|
|
38
38
|
.where('table_name', '!=', migrator_js_1.DEFAULT_MIGRATION_TABLE)
|
|
@@ -19,12 +19,38 @@ export declare class PostgresAdapter extends DialectAdapterBase {
|
|
|
19
19
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
20
20
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
21
21
|
*
|
|
22
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
23
|
-
* created by Kysely can be used instead.
|
|
24
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
23
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
24
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
25
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
26
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
27
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
28
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
29
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
30
|
+
*
|
|
31
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
32
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* {
|
|
36
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
37
|
+
* const queryDb = options.lockTableSchema
|
|
38
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
39
|
+
* : db
|
|
40
|
+
*
|
|
41
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
42
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
43
|
+
* // all subsequent calls to this method from other transactions will
|
|
44
|
+
* // wait until this transaction finishes.
|
|
45
|
+
* await queryDb
|
|
46
|
+
* .selectFrom(options.lockTable)
|
|
47
|
+
* .selectAll()
|
|
48
|
+
* .where('id', '=', options.lockRowId)
|
|
49
|
+
* .forUpdate()
|
|
50
|
+
* .execute()
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
28
54
|
*
|
|
29
55
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
30
56
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
@@ -13,7 +13,7 @@ class PostgresIntrospector {
|
|
|
13
13
|
let rawSchemas = await this.#db
|
|
14
14
|
.selectFrom('pg_catalog.pg_namespace')
|
|
15
15
|
.select('nspname')
|
|
16
|
-
|
|
16
|
+
.$castTo()
|
|
17
17
|
.execute();
|
|
18
18
|
return rawSchemas.map((it) => ({ name: it.nspname }));
|
|
19
19
|
}
|
|
@@ -58,7 +58,7 @@ class PostgresIntrospector {
|
|
|
58
58
|
.orderBy('ns.nspname')
|
|
59
59
|
.orderBy('c.relname')
|
|
60
60
|
.orderBy('a.attnum')
|
|
61
|
-
|
|
61
|
+
.$castTo();
|
|
62
62
|
if (!options.withInternalKyselyTables) {
|
|
63
63
|
query = query
|
|
64
64
|
.where('c.relname', '!=', migrator_js_1.DEFAULT_MIGRATION_TABLE)
|
|
@@ -18,12 +18,38 @@ export declare class SqliteAdapter implements DialectAdapterBase {
|
|
|
18
18
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
19
19
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
20
20
|
*
|
|
21
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
22
|
-
* created by Kysely can be used instead.
|
|
23
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
21
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
22
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
23
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
24
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
25
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
26
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
27
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
28
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
29
|
+
*
|
|
30
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
31
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* {
|
|
35
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
36
|
+
* const queryDb = options.lockTableSchema
|
|
37
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
38
|
+
* : db
|
|
39
|
+
*
|
|
40
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
41
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
42
|
+
* // all subsequent calls to this method from other transactions will
|
|
43
|
+
* // wait until this transaction finishes.
|
|
44
|
+
* await queryDb
|
|
45
|
+
* .selectFrom(options.lockTable)
|
|
46
|
+
* .selectAll()
|
|
47
|
+
* .where('id', '=', options.lockRowId)
|
|
48
|
+
* .forUpdate()
|
|
49
|
+
* .execute()
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
27
53
|
*
|
|
28
54
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
29
55
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
@@ -19,7 +19,7 @@ class SqliteIntrospector {
|
|
|
19
19
|
.where('name', 'not like', 'sqlite_%')
|
|
20
20
|
.select('name')
|
|
21
21
|
.orderBy('name')
|
|
22
|
-
|
|
22
|
+
.$castTo();
|
|
23
23
|
if (!options.withInternalKyselyTables) {
|
|
24
24
|
query = query
|
|
25
25
|
.where('name', '!=', migrator_js_1.DEFAULT_MIGRATION_TABLE)
|
|
@@ -40,7 +40,7 @@ class SqliteIntrospector {
|
|
|
40
40
|
.selectFrom('sqlite_master')
|
|
41
41
|
.where('name', '=', table)
|
|
42
42
|
.select('sql')
|
|
43
|
-
|
|
43
|
+
.$castTo()
|
|
44
44
|
.execute();
|
|
45
45
|
// Try to find the name of the column that has `autoincrement` 🤦
|
|
46
46
|
const autoIncrementCol = createSql[0]?.sql
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -159,6 +159,7 @@ export * from './operation-node/partition-by-item-node.js';
|
|
|
159
159
|
export * from './operation-node/set-operation-node.js';
|
|
160
160
|
export * from './operation-node/binary-operation-node.js';
|
|
161
161
|
export * from './operation-node/unary-operation-node.js';
|
|
162
|
+
export * from './operation-node/using-node.js';
|
|
162
163
|
export * from './util/column-type.js';
|
|
163
164
|
export * from './util/compilable.js';
|
|
164
165
|
export * from './util/explainable.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -176,6 +176,7 @@ __exportStar(require("./operation-node/partition-by-item-node.js"), exports);
|
|
|
176
176
|
__exportStar(require("./operation-node/set-operation-node.js"), exports);
|
|
177
177
|
__exportStar(require("./operation-node/binary-operation-node.js"), exports);
|
|
178
178
|
__exportStar(require("./operation-node/unary-operation-node.js"), exports);
|
|
179
|
+
__exportStar(require("./operation-node/using-node.js"), exports);
|
|
179
180
|
__exportStar(require("./util/column-type.js"), exports);
|
|
180
181
|
__exportStar(require("./util/compilable.js"), exports);
|
|
181
182
|
__exportStar(require("./util/explainable.js"), exports);
|
|
@@ -24,12 +24,17 @@ export interface Migration {
|
|
|
24
24
|
* other way.
|
|
25
25
|
*
|
|
26
26
|
* ```ts
|
|
27
|
+
* import { promises as fs } from 'fs'
|
|
28
|
+
* import path from 'path'
|
|
29
|
+
*
|
|
27
30
|
* const migrator = new Migrator({
|
|
28
31
|
* db,
|
|
29
|
-
* provider: new FileMigrationProvider(
|
|
32
|
+
* provider: new FileMigrationProvider({
|
|
33
|
+
* fs,
|
|
34
|
+
* path,
|
|
30
35
|
* // Path to the folder that contains all your migrations.
|
|
31
|
-
* 'some/path/to/migrations'
|
|
32
|
-
* )
|
|
36
|
+
* migrationFolder: 'some/path/to/migrations'
|
|
37
|
+
* })
|
|
33
38
|
* })
|
|
34
39
|
* ```
|
|
35
40
|
*/
|
|
@@ -19,12 +19,17 @@ exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true }
|
|
|
19
19
|
* other way.
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
|
+
* import { promises as fs } from 'fs'
|
|
23
|
+
* import path from 'path'
|
|
24
|
+
*
|
|
22
25
|
* const migrator = new Migrator({
|
|
23
26
|
* db,
|
|
24
|
-
* provider: new FileMigrationProvider(
|
|
27
|
+
* provider: new FileMigrationProvider({
|
|
28
|
+
* fs,
|
|
29
|
+
* path,
|
|
25
30
|
* // Path to the folder that contains all your migrations.
|
|
26
|
-
* 'some/path/to/migrations'
|
|
27
|
-
* )
|
|
31
|
+
* migrationFolder: 'some/path/to/migrations'
|
|
32
|
+
* })
|
|
28
33
|
* })
|
|
29
34
|
* ```
|
|
30
35
|
*/
|
|
@@ -318,9 +323,14 @@ class Migrator {
|
|
|
318
323
|
}
|
|
319
324
|
async #runMigrations(getTargetMigrationIndex) {
|
|
320
325
|
const adapter = this.#props.db.getExecutor().adapter;
|
|
326
|
+
const lockOptions = (0, object_utils_js_1.freeze)({
|
|
327
|
+
lockTable: this.#props.migrationLockTableName ?? exports.DEFAULT_MIGRATION_LOCK_TABLE,
|
|
328
|
+
lockRowId: exports.MIGRATION_LOCK_ID,
|
|
329
|
+
lockTableSchema: this.#props.migrationTableSchema,
|
|
330
|
+
});
|
|
321
331
|
const run = async (db) => {
|
|
322
332
|
try {
|
|
323
|
-
await adapter.acquireMigrationLock(db);
|
|
333
|
+
await adapter.acquireMigrationLock(db, lockOptions);
|
|
324
334
|
const state = await this.#getState(db);
|
|
325
335
|
if (state.migrations.length === 0) {
|
|
326
336
|
return { results: [] };
|
|
@@ -338,7 +348,7 @@ class Migrator {
|
|
|
338
348
|
return { results: [] };
|
|
339
349
|
}
|
|
340
350
|
finally {
|
|
341
|
-
await adapter.releaseMigrationLock(db);
|
|
351
|
+
await adapter.releaseMigrationLock(db, lockOptions);
|
|
342
352
|
}
|
|
343
353
|
};
|
|
344
354
|
if (adapter.supportsTransactionalDdl) {
|
|
@@ -8,9 +8,11 @@ import { LimitNode } from './limit-node.js';
|
|
|
8
8
|
import { OrderByNode } from './order-by-node.js';
|
|
9
9
|
import { OrderByItemNode } from './order-by-item-node.js';
|
|
10
10
|
import { ExplainNode } from './explain-node.js';
|
|
11
|
+
import { UsingNode } from './using-node.js';
|
|
11
12
|
export interface DeleteQueryNode extends OperationNode {
|
|
12
13
|
readonly kind: 'DeleteQueryNode';
|
|
13
14
|
readonly from: FromNode;
|
|
15
|
+
readonly using?: UsingNode;
|
|
14
16
|
readonly joins?: ReadonlyArray<JoinNode>;
|
|
15
17
|
readonly where?: WhereNode;
|
|
16
18
|
readonly returning?: ReturningNode;
|
|
@@ -28,4 +30,5 @@ export declare const DeleteQueryNode: Readonly<{
|
|
|
28
30
|
cloneWithOrderByItem(deleteNode: DeleteQueryNode, item: OrderByItemNode): DeleteQueryNode;
|
|
29
31
|
cloneWithLimit(deleteNode: DeleteQueryNode, limit: LimitNode): DeleteQueryNode;
|
|
30
32
|
cloneWithExplain(deleteNode: DeleteQueryNode, explain: ExplainNode): DeleteQueryNode;
|
|
33
|
+
cloneWithUsing(deleteNode: DeleteQueryNode, tables: OperationNode[]): DeleteQueryNode;
|
|
31
34
|
}>;
|
|
@@ -4,6 +4,7 @@ exports.DeleteQueryNode = void 0;
|
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
5
|
const from_node_js_1 = require("./from-node.js");
|
|
6
6
|
const order_by_node_js_1 = require("./order-by-node.js");
|
|
7
|
+
const using_node_js_1 = require("./using-node.js");
|
|
7
8
|
/**
|
|
8
9
|
* @internal
|
|
9
10
|
*/
|
|
@@ -38,4 +39,12 @@ exports.DeleteQueryNode = (0, object_utils_js_1.freeze)({
|
|
|
38
39
|
explain,
|
|
39
40
|
});
|
|
40
41
|
},
|
|
42
|
+
cloneWithUsing(deleteNode, tables) {
|
|
43
|
+
return (0, object_utils_js_1.freeze)({
|
|
44
|
+
...deleteNode,
|
|
45
|
+
using: deleteNode.using !== undefined
|
|
46
|
+
? using_node_js_1.UsingNode.cloneWithTables(deleteNode.using, tables)
|
|
47
|
+
: using_node_js_1.UsingNode.create(tables),
|
|
48
|
+
});
|
|
49
|
+
},
|
|
41
50
|
});
|
|
@@ -76,6 +76,7 @@ import { PartitionByItemNode } from './partition-by-item-node.js';
|
|
|
76
76
|
import { SetOperationNode } from './set-operation-node.js';
|
|
77
77
|
import { BinaryOperationNode } from './binary-operation-node.js';
|
|
78
78
|
import { UnaryOperationNode } from './unary-operation-node.js';
|
|
79
|
+
import { UsingNode } from './using-node.js';
|
|
79
80
|
/**
|
|
80
81
|
* Transforms an operation node tree into another one.
|
|
81
82
|
*
|
|
@@ -181,6 +182,7 @@ export declare class OperationNodeTransformer {
|
|
|
181
182
|
protected transformPartitionByItem(node: PartitionByItemNode): PartitionByItemNode;
|
|
182
183
|
protected transformBinaryOperation(node: BinaryOperationNode): BinaryOperationNode;
|
|
183
184
|
protected transformUnaryOperation(node: UnaryOperationNode): UnaryOperationNode;
|
|
185
|
+
protected transformUsing(node: UsingNode): UsingNode;
|
|
184
186
|
protected transformDataType(node: DataTypeNode): DataTypeNode;
|
|
185
187
|
protected transformSelectAll(node: SelectAllNode): SelectAllNode;
|
|
186
188
|
protected transformIdentifier(node: IdentifierNode): IdentifierNode;
|
|
@@ -112,6 +112,7 @@ class OperationNodeTransformer {
|
|
|
112
112
|
SetOperationNode: this.transformSetOperation.bind(this),
|
|
113
113
|
BinaryOperationNode: this.transformBinaryOperation.bind(this),
|
|
114
114
|
UnaryOperationNode: this.transformUnaryOperation.bind(this),
|
|
115
|
+
UsingNode: this.transformUsing.bind(this),
|
|
115
116
|
});
|
|
116
117
|
transformNode(node) {
|
|
117
118
|
if (!node) {
|
|
@@ -261,6 +262,7 @@ class OperationNodeTransformer {
|
|
|
261
262
|
return (0, require_all_props_js_1.requireAllProps)({
|
|
262
263
|
kind: 'DeleteQueryNode',
|
|
263
264
|
from: this.transformNode(node.from),
|
|
265
|
+
using: this.transformNode(node.using),
|
|
264
266
|
joins: this.transformNodeList(node.joins),
|
|
265
267
|
where: this.transformNode(node.where),
|
|
266
268
|
returning: this.transformNode(node.returning),
|
|
@@ -404,6 +406,7 @@ class OperationNodeTransformer {
|
|
|
404
406
|
expression: this.transformNode(node.expression),
|
|
405
407
|
unique: node.unique,
|
|
406
408
|
using: this.transformNode(node.using),
|
|
409
|
+
ifNotExists: node.ifNotExists,
|
|
407
410
|
});
|
|
408
411
|
}
|
|
409
412
|
transformList(node) {
|
|
@@ -689,6 +692,12 @@ class OperationNodeTransformer {
|
|
|
689
692
|
operand: this.transformNode(node.operand),
|
|
690
693
|
});
|
|
691
694
|
}
|
|
695
|
+
transformUsing(node) {
|
|
696
|
+
return (0, require_all_props_js_1.requireAllProps)({
|
|
697
|
+
kind: 'UsingNode',
|
|
698
|
+
tables: node.tables,
|
|
699
|
+
});
|
|
700
|
+
}
|
|
692
701
|
transformDataType(node) {
|
|
693
702
|
// An Object.freezed leaf node. No need to clone.
|
|
694
703
|
return node;
|
|
@@ -76,6 +76,7 @@ import { PartitionByItemNode } from './partition-by-item-node.js';
|
|
|
76
76
|
import { SetOperationNode } from './set-operation-node.js';
|
|
77
77
|
import { BinaryOperationNode } from './binary-operation-node.js';
|
|
78
78
|
import { UnaryOperationNode } from './unary-operation-node.js';
|
|
79
|
+
import { UsingNode } from './using-node.js';
|
|
79
80
|
export declare abstract class OperationNodeVisitor {
|
|
80
81
|
#private;
|
|
81
82
|
protected readonly nodeStack: OperationNode[];
|
|
@@ -158,4 +159,5 @@ export declare abstract class OperationNodeVisitor {
|
|
|
158
159
|
protected abstract visitSetOperation(node: SetOperationNode): void;
|
|
159
160
|
protected abstract visitBinaryOperation(node: BinaryOperationNode): void;
|
|
160
161
|
protected abstract visitUnaryOperation(node: UnaryOperationNode): void;
|
|
162
|
+
protected abstract visitUsing(node: UsingNode): void;
|
|
161
163
|
}
|
|
@@ -85,6 +85,7 @@ class OperationNodeVisitor {
|
|
|
85
85
|
SetOperationNode: this.visitSetOperation.bind(this),
|
|
86
86
|
BinaryOperationNode: this.visitBinaryOperation.bind(this),
|
|
87
87
|
UnaryOperationNode: this.visitUnaryOperation.bind(this),
|
|
88
|
+
UsingNode: this.visitUsing.bind(this),
|
|
88
89
|
});
|
|
89
90
|
visitNode = (node) => {
|
|
90
91
|
this.nodeStack.push(node);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode';
|
|
1
|
+
export declare type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode' | 'UsingNode';
|
|
2
2
|
export interface OperationNode {
|
|
3
3
|
readonly kind: OperationNodeKind;
|
|
4
4
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
export declare const COMPARISON_OPERATORS: readonly ["=", "==", "!=", "<>", ">", ">=", "<", "<=", "in", "not in", "is", "is not", "like", "not like", "ilike", "not ilike", "@>", "<@", "?", "?&", "!<", "!>", "<=>", "!~", "~", "~*", "!~*", "&&", "||", "@@", "@@@", "!!", "<->"];
|
|
2
|
+
export declare const COMPARISON_OPERATORS: readonly ["=", "==", "!=", "<>", ">", ">=", "<", "<=", "in", "not in", "is", "is not", "like", "not like", "match", "ilike", "not ilike", "@>", "<@", "?", "?&", "!<", "!>", "<=>", "!~", "~", "~*", "!~*", "&&", "||", "@@", "@@@", "!!", "<->"];
|
|
3
3
|
export declare const UNARY_FILTER_OPERATORS: readonly ["exists", "not exists"];
|
|
4
4
|
export declare type ComparisonOperator = typeof COMPARISON_OPERATORS[number];
|
|
5
5
|
export declare type UnaryFilterOperator = typeof UNARY_FILTER_OPERATORS[number];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OperationNode } from './operation-node.js';
|
|
2
|
+
export interface UsingNode extends OperationNode {
|
|
3
|
+
readonly kind: 'UsingNode';
|
|
4
|
+
readonly tables: ReadonlyArray<OperationNode>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const UsingNode: Readonly<{
|
|
10
|
+
is(node: OperationNode): node is UsingNode;
|
|
11
|
+
create(tables: ReadonlyArray<OperationNode>): UsingNode;
|
|
12
|
+
cloneWithTables(using: UsingNode, tables: ReadonlyArray<OperationNode>): UsingNode;
|
|
13
|
+
}>;
|