kysely 0.13.0 → 0.15.1
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 +92 -32
- package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/cjs/dialect/dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/kysely.d.ts +8 -40
- package/dist/cjs/kysely.js +8 -40
- package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
- package/dist/cjs/migration/file-migration-provider.js +52 -0
- package/dist/{esm/migration/migration.d.ts → cjs/migration/migrator.d.ts} +159 -134
- package/dist/cjs/migration/{migration.js → migrator.js} +166 -57
- package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/cjs/operation-node/check-constraint-node.js +2 -3
- package/dist/cjs/operation-node/column-definition-node.d.ts +2 -2
- package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
- package/dist/cjs/operation-node/generated-node.d.ts +20 -0
- package/dist/cjs/operation-node/generated-node.js +31 -0
- package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/cjs/operation-node/on-conflict-node.js +39 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -5
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
- package/dist/cjs/parser/insert-values-parser.js +2 -3
- package/dist/cjs/parser/reference-parser.d.ts +4 -3
- package/dist/cjs/parser/select-parser.d.ts +10 -4
- package/dist/cjs/parser/update-set-parser.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/cjs/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/cjs/query-builder/insert-query-builder.js +145 -15
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -4
- package/dist/cjs/query-builder/select-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/update-query-builder.d.ts +2 -4
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +33 -7
- package/dist/cjs/query-creator.d.ts +0 -2
- package/dist/cjs/query-creator.js +0 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +29 -9
- package/dist/cjs/schema/alter-table-builder.js +33 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +28 -8
- package/dist/cjs/schema/column-definition-builder.js +17 -7
- package/dist/cjs/schema/create-index-builder.d.ts +3 -2
- package/dist/cjs/schema/create-index-builder.js +2 -2
- package/dist/cjs/schema/create-table-builder.d.ts +3 -2
- package/dist/cjs/schema/create-table-builder.js +2 -2
- package/dist/cjs/util/column-type.d.ts +165 -0
- package/dist/cjs/util/column-type.js +2 -0
- package/dist/cjs/util/private-symbols.d.ts +5 -0
- package/dist/cjs/util/private-symbols.js +8 -0
- package/dist/cjs/util/type-utils.d.ts +6 -42
- package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +6 -3
- package/dist/esm/kysely.d.ts +8 -40
- package/dist/esm/kysely.js +8 -40
- package/dist/esm/migration/file-migration-provider.d.ts +52 -0
- package/dist/esm/migration/file-migration-provider.js +48 -0
- package/dist/{cjs/migration/migration.d.ts → esm/migration/migrator.d.ts} +159 -134
- package/dist/esm/migration/{migration.js → migrator.js} +165 -56
- package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/esm/operation-node/check-constraint-node.js +2 -3
- package/dist/esm/operation-node/column-definition-node.d.ts +2 -2
- package/dist/esm/operation-node/data-type-node.d.ts +1 -1
- package/dist/esm/operation-node/generated-node.d.ts +20 -0
- package/dist/esm/operation-node/generated-node.js +28 -0
- package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/esm/operation-node/on-conflict-node.js +39 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +11 -5
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-visitor.js +1 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/parser/insert-values-parser.d.ts +4 -4
- package/dist/esm/parser/insert-values-parser.js +2 -3
- package/dist/esm/parser/reference-parser.d.ts +4 -3
- package/dist/esm/parser/select-parser.d.ts +10 -4
- package/dist/esm/parser/update-set-parser.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/esm/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/esm/query-builder/insert-query-builder.js +145 -15
- package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-builder/returning-interface.d.ts +2 -4
- package/dist/esm/query-builder/select-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/update-query-builder.d.ts +2 -4
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +33 -7
- package/dist/esm/query-creator.d.ts +0 -2
- package/dist/esm/query-creator.js +0 -2
- package/dist/esm/schema/alter-table-builder.d.ts +29 -9
- package/dist/esm/schema/alter-table-builder.js +33 -9
- package/dist/esm/schema/column-definition-builder.d.ts +28 -8
- package/dist/esm/schema/column-definition-builder.js +17 -7
- package/dist/esm/schema/create-index-builder.d.ts +3 -2
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/schema/create-table-builder.d.ts +3 -2
- package/dist/esm/schema/create-table-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +165 -0
- package/dist/esm/util/column-type.js +1 -0
- package/dist/esm/util/private-symbols.d.ts +5 -0
- package/dist/esm/util/private-symbols.js +5 -0
- package/dist/esm/util/type-utils.d.ts +6 -42
- package/package.json +1 -1
- package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
- package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
- package/dist/cjs/parser/on-conflict-parser.js +0 -35
- package/dist/cjs/util/generated-placeholder.d.ts +0 -3
- package/dist/cjs/util/generated-placeholder.js +0 -11
- package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/esm/operation-node/generated-always-as-node.js +0 -22
- package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
- package/dist/esm/parser/on-conflict-parser.js +0 -30
- package/dist/esm/util/generated-placeholder.d.ts +0 -3
- package/dist/esm/util/generated-placeholder.js +0 -7
|
@@ -1,25 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const fs_1 = require("fs");
|
|
3
|
+
exports.Migrator = exports.NO_MIGRATIONS = exports.MIGRATION_LOCK_ID = exports.MIGRATION_LOCK_TABLE = exports.MIGRATION_TABLE = void 0;
|
|
6
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
+
const private_symbols_js_1 = require("../util/private-symbols.js");
|
|
7
6
|
exports.MIGRATION_TABLE = 'kysely_migration';
|
|
8
7
|
exports.MIGRATION_LOCK_TABLE = 'kysely_migration_lock';
|
|
9
8
|
exports.MIGRATION_LOCK_ID = 'migration_lock';
|
|
10
9
|
exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A class for running migrations.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
*
|
|
15
|
+
* This example uses the {@link FileMigrationProvider} that reads migrations
|
|
16
|
+
* files from a single folder. You can easily implement your own
|
|
17
|
+
* {@link MigrationProvider} if you want to provide migrations some
|
|
18
|
+
* other way.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const migrator = new Migrator({
|
|
22
|
+
* db,
|
|
23
|
+
* // The constructor signature of FileMigrationProvider is a
|
|
24
|
+
* // bit weird to keep Kysely independent of node.js or any
|
|
25
|
+
* // other environment.
|
|
26
|
+
* provider: new FileMigrationProvider(
|
|
27
|
+
* fs.readdir,
|
|
28
|
+
* path.join,
|
|
29
|
+
* // Path to the folder that contains all your migrations.
|
|
30
|
+
* 'migrations'
|
|
31
|
+
* )
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
class Migrator {
|
|
36
|
+
#props;
|
|
37
|
+
constructor(props) {
|
|
38
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
17
39
|
}
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Runs all migrations that have not yet been run.
|
|
42
|
+
*
|
|
43
|
+
* This method returns a {@link MigrationResultSet} instance and _never_ throws.
|
|
44
|
+
* {@link MigrationResultSet.error} holds the error if something went wrong.
|
|
45
|
+
* {@link MigrationResultSet.results} contains information about which migrations
|
|
46
|
+
* were executed and which failed. See the examples below.
|
|
47
|
+
*
|
|
48
|
+
* This method goes through all possible migrations provided by the provider and runs the
|
|
49
|
+
* ones whose names come alphabetically after the last migration that has been run. If the
|
|
50
|
+
* list of executed migrations doesn't match the beginning of the list of possible migrations
|
|
51
|
+
* an error is thrown.
|
|
52
|
+
*
|
|
53
|
+
* ### Examples
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import * as path from 'path'
|
|
57
|
+
* import * as fs from 'fs/promises'
|
|
58
|
+
*
|
|
59
|
+
* const db = new Kysely<Database>({
|
|
60
|
+
* dialect: new PostgresDialect({
|
|
61
|
+
* host: 'localhost',
|
|
62
|
+
* database: 'kysely_test',
|
|
63
|
+
* }),
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* const migrator = new Migrator({
|
|
67
|
+
* db,
|
|
68
|
+
* // The constructor signature of FileMigrationProvider is a
|
|
69
|
+
* // bit weird to keep Kysely independent of node.js or any
|
|
70
|
+
* // other environment.
|
|
71
|
+
* provider: new FileMigrationProvider(
|
|
72
|
+
* fs.readdir,
|
|
73
|
+
* path.join,
|
|
74
|
+
* // Path to the folder that contains all your migrations.
|
|
75
|
+
* 'migrations'
|
|
76
|
+
* )
|
|
77
|
+
* })
|
|
78
|
+
*
|
|
79
|
+
* const { error, results } = await migrator.migrateToLatest()
|
|
80
|
+
*
|
|
81
|
+
* results?.forEach((it) => {
|
|
82
|
+
* if (it.status === 'Success') {
|
|
83
|
+
* console.log(`migration "${it.migrationName}" was executed successfully`)
|
|
84
|
+
* } else if (it.status === 'Error') {
|
|
85
|
+
* console.error(`failed to execute migration "${it.migrationName}"`)
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* if (error) {
|
|
90
|
+
* console.error('failed to run `migrateToLatest`')
|
|
91
|
+
* console.error(error)
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
async migrateToLatest() {
|
|
96
|
+
return this.#migrate(({ migrations }) => migrations.length - 1);
|
|
20
97
|
}
|
|
21
|
-
|
|
22
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Migrate up/down to a specific migration.
|
|
100
|
+
*
|
|
101
|
+
* This method returns a {@link MigrationResultSet} instance and _never_ throws.
|
|
102
|
+
* {@link MigrationResultSet.error} holds the error if something went wrong.
|
|
103
|
+
* {@link MigrationResultSet.results} contains information about which migrations
|
|
104
|
+
* were executed and which failed.
|
|
105
|
+
*
|
|
106
|
+
* ### Examples
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* await migrator.migrateTo('some_migration')
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* If you specify the name of the first migration, this method migrates
|
|
113
|
+
* down to the first migration, but doesn't run the `down` method of
|
|
114
|
+
* the first migration. In case you want to migrate all the way down,
|
|
115
|
+
* you can use a special constant `NO_MIGRATIONS`:
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* await migrator.migrateTo(NO_MIGRATIONS)
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async migrateTo(targetMigrationName) {
|
|
122
|
+
return this.#migrate(({ migrations }) => {
|
|
23
123
|
if (targetMigrationName === exports.NO_MIGRATIONS) {
|
|
24
124
|
return -1;
|
|
25
125
|
}
|
|
@@ -30,16 +130,44 @@ class MigrationModule {
|
|
|
30
130
|
return index;
|
|
31
131
|
});
|
|
32
132
|
}
|
|
33
|
-
|
|
34
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Migrate one step up.
|
|
135
|
+
*
|
|
136
|
+
* This method returns a {@link MigrationResultSet} instance and _never_ throws.
|
|
137
|
+
* {@link MigrationResultSet.error} holds the error if something went wrong.
|
|
138
|
+
* {@link MigrationResultSet.results} contains information about which migrations
|
|
139
|
+
* were executed and which failed.
|
|
140
|
+
*
|
|
141
|
+
* ### Examples
|
|
142
|
+
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* await migrator.migrateUp()
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
async migrateUp() {
|
|
148
|
+
return this.#migrate(({ currentIndex, migrations }) => Math.min(currentIndex + 1, migrations.length - 1));
|
|
35
149
|
}
|
|
36
|
-
|
|
37
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Migrate one step down.
|
|
152
|
+
*
|
|
153
|
+
* This method returns a {@link MigrationResultSet} instance and _never_ throws.
|
|
154
|
+
* {@link MigrationResultSet.error} holds the error if something went wrong.
|
|
155
|
+
* {@link MigrationResultSet.results} contains information about which migrations
|
|
156
|
+
* were executed and which failed.
|
|
157
|
+
*
|
|
158
|
+
* ### Examples
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* await migrator.migrateDown()
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
async migrateDown() {
|
|
165
|
+
return this.#migrate(({ currentIndex }) => Math.max(currentIndex - 1, -1));
|
|
38
166
|
}
|
|
39
|
-
async #migrate(
|
|
167
|
+
async #migrate(getTargetMigrationIndex) {
|
|
40
168
|
try {
|
|
41
169
|
await this.#ensureMigrationTablesExists();
|
|
42
|
-
return await this.#runMigrations(
|
|
170
|
+
return await this.#runMigrations(getTargetMigrationIndex);
|
|
43
171
|
}
|
|
44
172
|
catch (error) {
|
|
45
173
|
if (error instanceof MigrationResultSetError) {
|
|
@@ -56,7 +184,7 @@ class MigrationModule {
|
|
|
56
184
|
async #ensureMigrationTableExists() {
|
|
57
185
|
if (!(await this.#doesTableExists(exports.MIGRATION_TABLE))) {
|
|
58
186
|
try {
|
|
59
|
-
await this.#db.schema
|
|
187
|
+
await this.#props.db.schema
|
|
60
188
|
.createTable(exports.MIGRATION_TABLE)
|
|
61
189
|
.ifNotExists()
|
|
62
190
|
.addColumn('name', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
@@ -78,7 +206,7 @@ class MigrationModule {
|
|
|
78
206
|
async #ensureMigrationLockTableExists() {
|
|
79
207
|
if (!(await this.#doesTableExists(exports.MIGRATION_LOCK_TABLE))) {
|
|
80
208
|
try {
|
|
81
|
-
await this.#db.schema
|
|
209
|
+
await this.#props.db.schema
|
|
82
210
|
.createTable(exports.MIGRATION_LOCK_TABLE)
|
|
83
211
|
.ifNotExists()
|
|
84
212
|
.addColumn('id', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
@@ -98,7 +226,7 @@ class MigrationModule {
|
|
|
98
226
|
async #ensureLockRowExists() {
|
|
99
227
|
if (!(await this.#doesLockRowExists())) {
|
|
100
228
|
try {
|
|
101
|
-
await this.#db
|
|
229
|
+
await this.#props.db
|
|
102
230
|
.insertInto(exports.MIGRATION_LOCK_TABLE)
|
|
103
231
|
.values({ id: exports.MIGRATION_LOCK_ID })
|
|
104
232
|
.execute();
|
|
@@ -111,28 +239,28 @@ class MigrationModule {
|
|
|
111
239
|
}
|
|
112
240
|
}
|
|
113
241
|
async #doesTableExists(tableName) {
|
|
114
|
-
const metadata = await this.#db.introspection.getMetadata({
|
|
242
|
+
const metadata = await this.#props.db.introspection.getMetadata({
|
|
115
243
|
withInternalKyselyTables: true,
|
|
116
244
|
});
|
|
117
245
|
return !!metadata.tables.find((it) => it.name === tableName);
|
|
118
246
|
}
|
|
119
247
|
async #doesLockRowExists() {
|
|
120
|
-
const lockRow = await this.#db
|
|
248
|
+
const lockRow = await this.#props.db
|
|
121
249
|
.selectFrom(exports.MIGRATION_LOCK_TABLE)
|
|
122
250
|
.where('id', '=', exports.MIGRATION_LOCK_ID)
|
|
123
251
|
.select('id')
|
|
124
252
|
.executeTakeFirst();
|
|
125
253
|
return !!lockRow;
|
|
126
254
|
}
|
|
127
|
-
async #runMigrations(
|
|
255
|
+
async #runMigrations(getTargetMigrationIndex) {
|
|
128
256
|
const run = async (db) => {
|
|
129
257
|
try {
|
|
130
|
-
await this.#
|
|
131
|
-
const state = await this.#getState(db
|
|
258
|
+
await this.#props.db[private_symbols_js_1.PRIVATE_ADAPTER].acquireMigrationLock(db);
|
|
259
|
+
const state = await this.#getState(db);
|
|
132
260
|
if (state.migrations.length === 0) {
|
|
133
261
|
return { results: [] };
|
|
134
262
|
}
|
|
135
|
-
const targetIndex =
|
|
263
|
+
const targetIndex = getTargetMigrationIndex(state);
|
|
136
264
|
if (targetIndex === undefined) {
|
|
137
265
|
return { results: [] };
|
|
138
266
|
}
|
|
@@ -145,18 +273,18 @@ class MigrationModule {
|
|
|
145
273
|
return { results: [] };
|
|
146
274
|
}
|
|
147
275
|
finally {
|
|
148
|
-
await this.#
|
|
276
|
+
await this.#props.db[private_symbols_js_1.PRIVATE_ADAPTER].releaseMigrationLock(db);
|
|
149
277
|
}
|
|
150
278
|
};
|
|
151
|
-
if (this.#
|
|
152
|
-
return this.#db.transaction().execute(run);
|
|
279
|
+
if (this.#props.db[private_symbols_js_1.PRIVATE_ADAPTER].supportsTransactionalDdl) {
|
|
280
|
+
return this.#props.db.transaction().execute(run);
|
|
153
281
|
}
|
|
154
282
|
else {
|
|
155
|
-
return this.#db.connection().execute(run);
|
|
283
|
+
return this.#props.db.connection().execute(run);
|
|
156
284
|
}
|
|
157
285
|
}
|
|
158
|
-
async #getState(db
|
|
159
|
-
const migrations = await this.#resolveMigrations(
|
|
286
|
+
async #getState(db) {
|
|
287
|
+
const migrations = await this.#resolveMigrations();
|
|
160
288
|
const executedMigrations = await this.#getExecutedMigrations(db);
|
|
161
289
|
this.#ensureMigrationsNotCorrupted(migrations, executedMigrations);
|
|
162
290
|
return (0, object_utils_js_1.freeze)({
|
|
@@ -164,10 +292,8 @@ class MigrationModule {
|
|
|
164
292
|
currentIndex: migrations.findIndex((it) => it.name === (0, object_utils_js_1.getLast)(executedMigrations)),
|
|
165
293
|
});
|
|
166
294
|
}
|
|
167
|
-
async #resolveMigrations(
|
|
168
|
-
const allMigrations =
|
|
169
|
-
? await this.#readMigrationsFromFolder(migrationsOrFolderPath)
|
|
170
|
-
: migrationsOrFolderPath;
|
|
295
|
+
async #resolveMigrations() {
|
|
296
|
+
const allMigrations = await this.#props.provider.getMigrations();
|
|
171
297
|
return Object.keys(allMigrations)
|
|
172
298
|
.sort()
|
|
173
299
|
.map((name) => ({
|
|
@@ -175,20 +301,6 @@ class MigrationModule {
|
|
|
175
301
|
name,
|
|
176
302
|
}));
|
|
177
303
|
}
|
|
178
|
-
async #readMigrationsFromFolder(migrationsFolderPath) {
|
|
179
|
-
const files = await fs_1.promises.readdir(migrationsFolderPath);
|
|
180
|
-
const migrations = {};
|
|
181
|
-
for (const file of files) {
|
|
182
|
-
if ((file.endsWith('.js') || file.endsWith('.ts')) &&
|
|
183
|
-
!file.endsWith('.d.ts')) {
|
|
184
|
-
const migration = await Promise.resolve().then(() => require(path.join(migrationsFolderPath, file)));
|
|
185
|
-
if (isMigration(migration)) {
|
|
186
|
-
migrations[file.substring(0, file.length - 3)] = migration;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return migrations;
|
|
191
|
-
}
|
|
192
304
|
async #getExecutedMigrations(db) {
|
|
193
305
|
const executedMigrations = await db
|
|
194
306
|
.selectFrom(exports.MIGRATION_TABLE)
|
|
@@ -204,7 +316,7 @@ class MigrationModule {
|
|
|
204
316
|
}
|
|
205
317
|
}
|
|
206
318
|
// Now we know all executed migrations exist in the `migrations` list.
|
|
207
|
-
// Next we need to make sure that the executed
|
|
319
|
+
// Next we need to make sure that the executed migratiosns are the first
|
|
208
320
|
// ones in the migration list.
|
|
209
321
|
for (let i = 0; i < executedMigrations.length; ++i) {
|
|
210
322
|
if (migrations[i].name !== executedMigrations[i]) {
|
|
@@ -292,7 +404,7 @@ class MigrationModule {
|
|
|
292
404
|
return { results };
|
|
293
405
|
}
|
|
294
406
|
}
|
|
295
|
-
exports.
|
|
407
|
+
exports.Migrator = Migrator;
|
|
296
408
|
class MigrationResultSetError extends Error {
|
|
297
409
|
#resultSet;
|
|
298
410
|
constructor(result) {
|
|
@@ -303,6 +415,3 @@ class MigrationResultSetError extends Error {
|
|
|
303
415
|
return this.#resultSet;
|
|
304
416
|
}
|
|
305
417
|
}
|
|
306
|
-
function isMigration(obj) {
|
|
307
|
-
return (0, object_utils_js_1.isObject)(obj) && (0, object_utils_js_1.isFunction)(obj.up);
|
|
308
|
-
}
|
|
@@ -11,5 +11,5 @@ export interface CheckConstraintNode extends OperationNode {
|
|
|
11
11
|
*/
|
|
12
12
|
export declare const CheckConstraintNode: Readonly<{
|
|
13
13
|
is(node: OperationNode): node is CheckConstraintNode;
|
|
14
|
-
create(
|
|
14
|
+
create(expression: RawNode, constraintName?: string | undefined): CheckConstraintNode;
|
|
15
15
|
}>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CheckConstraintNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const raw_node_js_1 = require("./raw-node.js");
|
|
6
5
|
const identifier_node_js_1 = require("./identifier-node.js");
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
@@ -11,10 +10,10 @@ exports.CheckConstraintNode = (0, object_utils_js_1.freeze)({
|
|
|
11
10
|
is(node) {
|
|
12
11
|
return node.kind === 'CheckConstraintNode';
|
|
13
12
|
},
|
|
14
|
-
create(
|
|
13
|
+
create(expression, constraintName) {
|
|
15
14
|
return (0, object_utils_js_1.freeze)({
|
|
16
15
|
kind: 'CheckConstraintNode',
|
|
17
|
-
expression
|
|
16
|
+
expression,
|
|
18
17
|
name: constraintName ? identifier_node_js_1.IdentifierNode.create(constraintName) : undefined,
|
|
19
18
|
});
|
|
20
19
|
},
|
|
@@ -2,7 +2,7 @@ import { CheckConstraintNode } from './check-constraint-node.js';
|
|
|
2
2
|
import { ColumnNode } from './column-node.js';
|
|
3
3
|
import { DataTypeNode } from './data-type-node.js';
|
|
4
4
|
import { DefaultValueNode } from './default-value-node.js';
|
|
5
|
-
import {
|
|
5
|
+
import { GeneratedNode } from './generated-node.js';
|
|
6
6
|
import { OperationNode } from './operation-node.js';
|
|
7
7
|
import { RawNode } from './raw-node.js';
|
|
8
8
|
import { ReferencesNode } from './references-node.js';
|
|
@@ -19,7 +19,7 @@ export interface ColumnDefinitionNode extends OperationNode {
|
|
|
19
19
|
readonly notNull?: boolean;
|
|
20
20
|
readonly defaultTo?: DefaultValueNode;
|
|
21
21
|
readonly check?: CheckConstraintNode;
|
|
22
|
-
readonly
|
|
22
|
+
readonly generated?: GeneratedNode;
|
|
23
23
|
readonly unsigned?: boolean;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
export declare type ColumnDataType = 'varchar' | `varchar(${number})` | 'text' | 'integer' | 'int2' | 'int4' | 'int8' | 'bigint' | 'boolean' | 'real' | 'double precision' | 'float4' | 'float8' | 'decimal' | `decimal(${number}, ${number})` | 'numeric' | `numeric(${number}, ${number})` | 'binary' | 'date' | 'datetime' | 'time' | 'timetz' | 'timestamp' | 'timestamptz' | 'serial' | 'bigserial' | 'uuid' | 'json' | 'jsonb';
|
|
2
|
+
export declare type ColumnDataType = 'varchar' | `varchar(${number})` | 'text' | 'integer' | 'int2' | 'int4' | 'int8' | 'bigint' | 'boolean' | 'real' | 'double precision' | 'float4' | 'float8' | 'decimal' | `decimal(${number}, ${number})` | 'numeric' | `numeric(${number}, ${number})` | 'binary' | 'date' | 'datetime' | 'time' | 'timetz' | 'timestamp' | 'timestamptz' | 'serial' | 'bigserial' | 'uuid' | 'json' | 'jsonb' | 'blob';
|
|
3
3
|
export declare type DataTypeParams = Omit<DataTypeNode, 'kind' | 'dataType'>;
|
|
4
4
|
export interface DataTypeNode extends OperationNode {
|
|
5
5
|
readonly kind: 'DataTypeNode';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { RawNode } from './raw-node.js';
|
|
3
|
+
export declare type GeneratedNodeParams = Omit<GeneratedNode, 'kind' | 'expression'>;
|
|
4
|
+
export interface GeneratedNode extends OperationNode {
|
|
5
|
+
readonly kind: 'GeneratedNode';
|
|
6
|
+
readonly byDefault?: boolean;
|
|
7
|
+
readonly always?: boolean;
|
|
8
|
+
readonly identity?: boolean;
|
|
9
|
+
readonly stored?: boolean;
|
|
10
|
+
readonly expression?: RawNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare const GeneratedNode: Readonly<{
|
|
16
|
+
is(node: OperationNode): node is GeneratedNode;
|
|
17
|
+
create(params: GeneratedNodeParams): GeneratedNode;
|
|
18
|
+
createWithExpression(expression: RawNode): GeneratedNode;
|
|
19
|
+
cloneWith(node: GeneratedNode, params: GeneratedNodeParams): GeneratedNode;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratedNode = void 0;
|
|
4
|
+
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
exports.GeneratedNode = (0, object_utils_js_1.freeze)({
|
|
9
|
+
is(node) {
|
|
10
|
+
return node.kind === 'GeneratedNode';
|
|
11
|
+
},
|
|
12
|
+
create(params) {
|
|
13
|
+
return (0, object_utils_js_1.freeze)({
|
|
14
|
+
kind: 'GeneratedNode',
|
|
15
|
+
...params,
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
createWithExpression(expression) {
|
|
19
|
+
return (0, object_utils_js_1.freeze)({
|
|
20
|
+
kind: 'GeneratedNode',
|
|
21
|
+
always: true,
|
|
22
|
+
expression,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
cloneWith(node, params) {
|
|
26
|
+
return (0, object_utils_js_1.freeze)({
|
|
27
|
+
...node,
|
|
28
|
+
...params,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { ColumnNode } from './column-node.js';
|
|
2
2
|
import { ColumnUpdateNode } from './column-update-node.js';
|
|
3
3
|
import { IdentifierNode } from './identifier-node.js';
|
|
4
|
+
import { FilterExpressionNode } from './operation-node-utils.js';
|
|
4
5
|
import { OperationNode } from './operation-node.js';
|
|
5
|
-
|
|
6
|
+
import { RawNode } from './raw-node.js';
|
|
7
|
+
import { WhereNode } from './where-node.js';
|
|
8
|
+
export declare type OnConflictNodeProps = Omit<OnConflictNode, 'kind' | 'indexWhere' | 'updateWhere'>;
|
|
6
9
|
export interface OnConflictNode extends OperationNode {
|
|
7
10
|
readonly kind: 'OnConflictNode';
|
|
8
11
|
readonly columns?: ReadonlyArray<ColumnNode>;
|
|
9
12
|
readonly constraint?: IdentifierNode;
|
|
13
|
+
readonly indexExpression?: RawNode;
|
|
14
|
+
readonly indexWhere?: WhereNode;
|
|
10
15
|
readonly updates?: ReadonlyArray<ColumnUpdateNode>;
|
|
16
|
+
readonly updateWhere?: WhereNode;
|
|
11
17
|
readonly doNothing?: boolean;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
@@ -15,5 +21,10 @@ export interface OnConflictNode extends OperationNode {
|
|
|
15
21
|
*/
|
|
16
22
|
export declare const OnConflictNode: Readonly<{
|
|
17
23
|
is(node: OperationNode): node is OnConflictNode;
|
|
18
|
-
create(
|
|
24
|
+
create(): OnConflictNode;
|
|
25
|
+
cloneWith(node: OnConflictNode, props: OnConflictNodeProps): OnConflictNode;
|
|
26
|
+
cloneWithIndexWhere(node: OnConflictNode, filter: FilterExpressionNode): OnConflictNode;
|
|
27
|
+
cloneWithIndexOrWhere(node: OnConflictNode, filter: FilterExpressionNode): OnConflictNode;
|
|
28
|
+
cloneWithUpdateWhere(node: OnConflictNode, filter: FilterExpressionNode): OnConflictNode;
|
|
29
|
+
cloneWithUpdateOrWhere(node: OnConflictNode, filter: FilterExpressionNode): OnConflictNode;
|
|
19
30
|
}>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OnConflictNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
+
const where_node_js_1 = require("./where-node.js");
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
7
8
|
*/
|
|
@@ -9,10 +10,47 @@ exports.OnConflictNode = (0, object_utils_js_1.freeze)({
|
|
|
9
10
|
is(node) {
|
|
10
11
|
return node.kind === 'OnConflictNode';
|
|
11
12
|
},
|
|
12
|
-
create(
|
|
13
|
+
create() {
|
|
13
14
|
return (0, object_utils_js_1.freeze)({
|
|
14
15
|
kind: 'OnConflictNode',
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
cloneWith(node, props) {
|
|
19
|
+
return (0, object_utils_js_1.freeze)({
|
|
20
|
+
...node,
|
|
15
21
|
...props,
|
|
16
22
|
});
|
|
17
23
|
},
|
|
24
|
+
cloneWithIndexWhere(node, filter) {
|
|
25
|
+
return (0, object_utils_js_1.freeze)({
|
|
26
|
+
...node,
|
|
27
|
+
indexWhere: node.indexWhere
|
|
28
|
+
? where_node_js_1.WhereNode.cloneWithFilter(node.indexWhere, 'And', filter)
|
|
29
|
+
: where_node_js_1.WhereNode.create(filter),
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
cloneWithIndexOrWhere(node, filter) {
|
|
33
|
+
return (0, object_utils_js_1.freeze)({
|
|
34
|
+
...node,
|
|
35
|
+
indexWhere: node.indexWhere
|
|
36
|
+
? where_node_js_1.WhereNode.cloneWithFilter(node.indexWhere, 'Or', filter)
|
|
37
|
+
: where_node_js_1.WhereNode.create(filter),
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
cloneWithUpdateWhere(node, filter) {
|
|
41
|
+
return (0, object_utils_js_1.freeze)({
|
|
42
|
+
...node,
|
|
43
|
+
updateWhere: node.updateWhere
|
|
44
|
+
? where_node_js_1.WhereNode.cloneWithFilter(node.updateWhere, 'And', filter)
|
|
45
|
+
: where_node_js_1.WhereNode.create(filter),
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
cloneWithUpdateOrWhere(node, filter) {
|
|
49
|
+
return (0, object_utils_js_1.freeze)({
|
|
50
|
+
...node,
|
|
51
|
+
updateWhere: node.updateWhere
|
|
52
|
+
? where_node_js_1.WhereNode.cloneWithFilter(node.updateWhere, 'Or', filter)
|
|
53
|
+
: where_node_js_1.WhereNode.create(filter),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
18
56
|
});
|
|
@@ -61,7 +61,7 @@ import { OnDuplicateKeyNode } from './on-duplicate-key-node.js';
|
|
|
61
61
|
import { UnionNode } from './union-node.js';
|
|
62
62
|
import { CreateViewNode } from './create-view-node.js';
|
|
63
63
|
import { DropViewNode } from './drop-view-node.js';
|
|
64
|
-
import {
|
|
64
|
+
import { GeneratedNode } from './generated-node.js';
|
|
65
65
|
import { DefaultValueNode } from './default-value-node.js';
|
|
66
66
|
import { OnNode } from './on-node.js';
|
|
67
67
|
import { ValuesNode } from './values-node.js';
|
|
@@ -156,7 +156,7 @@ export declare class OperationNodeTransformer {
|
|
|
156
156
|
protected transformDropConstraint(node: DropConstraintNode): DropConstraintNode;
|
|
157
157
|
protected transformCreateView(node: CreateViewNode): CreateViewNode;
|
|
158
158
|
protected transformDropView(node: DropViewNode): DropViewNode;
|
|
159
|
-
protected
|
|
159
|
+
protected transformGenerated(node: GeneratedNode): GeneratedNode;
|
|
160
160
|
protected transformDefaultValue(node: DefaultValueNode): DefaultValueNode;
|
|
161
161
|
protected transformOn(node: OnNode): OnNode;
|
|
162
162
|
protected transformDataType(node: DataTypeNode): DataTypeNode;
|
|
@@ -96,7 +96,7 @@ class OperationNodeTransformer {
|
|
|
96
96
|
UnionNode: this.transformUnion.bind(this),
|
|
97
97
|
CreateViewNode: this.transformCreateView.bind(this),
|
|
98
98
|
DropViewNode: this.transformDropView.bind(this),
|
|
99
|
-
|
|
99
|
+
GeneratedNode: this.transformGenerated.bind(this),
|
|
100
100
|
DefaultValueNode: this.transformDefaultValue.bind(this),
|
|
101
101
|
OnNode: this.transformOn.bind(this),
|
|
102
102
|
ValuesNode: this.transformValues.bind(this),
|
|
@@ -288,7 +288,7 @@ class OperationNodeTransformer {
|
|
|
288
288
|
unsigned: node.unsigned,
|
|
289
289
|
defaultTo: this.transformNode(node.defaultTo),
|
|
290
290
|
check: this.transformNode(node.check),
|
|
291
|
-
|
|
291
|
+
generated: this.transformNode(node.generated),
|
|
292
292
|
};
|
|
293
293
|
}
|
|
294
294
|
transformAddColumn(node) {
|
|
@@ -364,7 +364,10 @@ class OperationNodeTransformer {
|
|
|
364
364
|
kind: 'OnConflictNode',
|
|
365
365
|
columns: this.transformNodeList(node.columns),
|
|
366
366
|
constraint: this.transformNode(node.constraint),
|
|
367
|
+
indexExpression: this.transformNode(node.indexExpression),
|
|
368
|
+
indexWhere: this.transformNode(node.indexWhere),
|
|
367
369
|
updates: this.transformNodeList(node.updates),
|
|
370
|
+
updateWhere: this.transformNode(node.updateWhere),
|
|
368
371
|
doNothing: node.doNothing,
|
|
369
372
|
};
|
|
370
373
|
}
|
|
@@ -563,11 +566,14 @@ class OperationNodeTransformer {
|
|
|
563
566
|
materialized: node.materialized,
|
|
564
567
|
};
|
|
565
568
|
}
|
|
566
|
-
|
|
569
|
+
transformGenerated(node) {
|
|
567
570
|
return {
|
|
568
|
-
kind: '
|
|
569
|
-
|
|
571
|
+
kind: 'GeneratedNode',
|
|
572
|
+
byDefault: node.byDefault,
|
|
573
|
+
always: node.always,
|
|
574
|
+
identity: node.identity,
|
|
570
575
|
stored: node.stored,
|
|
576
|
+
expression: this.transformNode(node.expression),
|
|
571
577
|
};
|
|
572
578
|
}
|
|
573
579
|
transformDefaultValue(node) {
|
|
@@ -61,7 +61,7 @@ import { OnDuplicateKeyNode } from './on-duplicate-key-node.js';
|
|
|
61
61
|
import { UnionNode } from './union-node.js';
|
|
62
62
|
import { CreateViewNode } from './create-view-node.js';
|
|
63
63
|
import { DropViewNode } from './drop-view-node.js';
|
|
64
|
-
import {
|
|
64
|
+
import { GeneratedNode } from './generated-node.js';
|
|
65
65
|
import { DefaultValueNode } from './default-value-node.js';
|
|
66
66
|
import { OnNode } from './on-node.js';
|
|
67
67
|
import { ValuesNode } from './values-node.js';
|
|
@@ -132,7 +132,7 @@ export declare abstract class OperationNodeVisitor {
|
|
|
132
132
|
protected abstract visitOperator(node: OperatorNode): void;
|
|
133
133
|
protected abstract visitCreateView(node: CreateViewNode): void;
|
|
134
134
|
protected abstract visitDropView(node: DropViewNode): void;
|
|
135
|
-
protected abstract
|
|
135
|
+
protected abstract visitGenerated(node: GeneratedNode): void;
|
|
136
136
|
protected abstract visitDefaultValue(node: DefaultValueNode): void;
|
|
137
137
|
protected abstract visitOn(node: OnNode): void;
|
|
138
138
|
protected abstract visitValues(node: ValuesNode): void;
|
|
@@ -70,7 +70,7 @@ class OperationNodeVisitor {
|
|
|
70
70
|
UnionNode: this.visitUnion.bind(this),
|
|
71
71
|
CreateViewNode: this.visitCreateView.bind(this),
|
|
72
72
|
DropViewNode: this.visitDropView.bind(this),
|
|
73
|
-
|
|
73
|
+
GeneratedNode: this.visitGenerated.bind(this),
|
|
74
74
|
DefaultValueNode: this.visitDefaultValue.bind(this),
|
|
75
75
|
OnNode: this.visitOn.bind(this),
|
|
76
76
|
ValuesNode: this.visitValues.bind(this),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type OperationNodeKind = 'IdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'FilterNode' | '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' | 'UnionNode' | 'CreateViewNode' | 'DropViewNode' | '
|
|
1
|
+
export declare type OperationNodeKind = 'IdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'FilterNode' | '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' | 'UnionNode' | 'CreateViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode';
|
|
2
2
|
export interface OperationNode {
|
|
3
3
|
readonly kind: OperationNodeKind;
|
|
4
4
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
2
|
-
import { GeneratedPlaceholder } from '../util/type-utils.js';
|
|
3
2
|
import { ParseContext } from './parse-context.js';
|
|
4
3
|
import { ValueExpression } from './value-parser.js';
|
|
5
4
|
import { ValuesNode } from '../operation-node/values-node.js';
|
|
5
|
+
import { NonNullableInsertKeys, NullableInsertKeys, InsertType } from '../util/column-type.js';
|
|
6
6
|
export declare type InsertObject<DB, TB extends keyof DB> = {
|
|
7
|
-
[C in
|
|
7
|
+
[C in NonNullableInsertKeys<DB[TB]>]: ValueExpression<DB, TB, InsertType<DB[TB][C]>>;
|
|
8
|
+
} & {
|
|
9
|
+
[C in NullableInsertKeys<DB[TB]>]?: ValueExpression<DB, TB, InsertType<DB[TB][C]>>;
|
|
8
10
|
};
|
|
9
11
|
export declare type InsertObjectOrList<DB, TB extends keyof DB> = InsertObject<DB, TB> | ReadonlyArray<InsertObject<DB, TB>>;
|
|
10
|
-
declare type InsertValueExpression<DB, TB extends keyof DB, T> = ValueExpression<DB, TB, T> | GeneratedPlaceholder;
|
|
11
12
|
export declare function parseInsertObjectOrList(ctx: ParseContext, args: InsertObjectOrList<any, any>): [ReadonlyArray<ColumnNode>, ValuesNode];
|
|
12
|
-
export {};
|