kysely 0.18.0 → 0.19.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 +22 -17
- package/dist/cjs/dialect/database-introspector.d.ts +13 -0
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +24 -207
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +26 -3
- package/dist/cjs/dialect/mysql/mysql-dialect.js +27 -5
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +13 -4
- package/dist/cjs/dialect/mysql/mysql-driver.js +33 -51
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +29 -7
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +25 -89
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +25 -5
- package/dist/cjs/dialect/postgres/postgres-dialect.js +26 -7
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +12 -3
- package/dist/cjs/dialect/postgres/postgres-driver.js +21 -39
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +15 -4
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +19 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +19 -3
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +3 -37
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +11 -4
- package/dist/cjs/index.d.ts +153 -2
- package/dist/cjs/index.js +147 -3
- package/dist/cjs/migration/file-migration-provider.d.ts +21 -5
- package/dist/cjs/migration/file-migration-provider.js +14 -13
- package/dist/cjs/migration/migrator.d.ts +44 -2
- package/dist/cjs/migration/migrator.js +77 -18
- package/dist/cjs/plugin/noop-plugin.d.ts +42 -0
- package/dist/cjs/plugin/noop-plugin.js +12 -0
- package/dist/cjs/query-creator.d.ts +9 -0
- package/dist/cjs/query-creator.js +18 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +2 -5
- package/dist/cjs/schema/alter-table-builder.js +3 -7
- package/dist/cjs/schema/schema.d.ts +9 -0
- package/dist/cjs/schema/schema.js +12 -0
- package/dist/cjs/util/column-type.d.ts +9 -1
- package/dist/cjs/util/stack-trace-utils.d.ts +1 -0
- package/dist/cjs/util/stack-trace-utils.js +17 -0
- package/dist/esm/dialect/database-introspector.d.ts +13 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +24 -207
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +26 -3
- package/dist/esm/dialect/mysql/mysql-dialect.js +27 -5
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +13 -4
- package/dist/esm/dialect/mysql/mysql-driver.js +33 -51
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +30 -8
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +25 -89
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +25 -5
- package/dist/esm/dialect/postgres/postgres-dialect.js +26 -7
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +12 -3
- package/dist/esm/dialect/postgres/postgres-driver.js +21 -39
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +16 -5
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +19 -3
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +19 -3
- package/dist/esm/dialect/sqlite/sqlite-driver.js +4 -38
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +12 -5
- package/dist/esm/index.d.ts +153 -2
- package/dist/esm/index.js +142 -2
- package/dist/esm/migration/file-migration-provider.d.ts +21 -5
- package/dist/esm/migration/file-migration-provider.js +14 -13
- package/dist/esm/migration/migrator.d.ts +44 -2
- package/dist/esm/migration/migrator.js +76 -17
- package/dist/esm/plugin/noop-plugin.d.ts +42 -0
- package/dist/esm/plugin/noop-plugin.js +9 -0
- package/dist/esm/query-creator.d.ts +9 -0
- package/dist/esm/query-creator.js +18 -0
- package/dist/esm/schema/alter-table-builder.d.ts +2 -5
- package/dist/esm/schema/alter-table-builder.js +4 -8
- package/dist/esm/schema/schema.d.ts +9 -0
- package/dist/esm/schema/schema.js +12 -0
- package/dist/esm/util/column-type.d.ts +9 -1
- package/dist/esm/util/stack-trace-utils.d.ts +1 -0
- package/dist/esm/util/stack-trace-utils.js +14 -0
- package/package.json +10 -15
- package/dist/cjs/index-nodeless.d.ts +0 -152
- package/dist/cjs/index-nodeless.js +0 -153
- package/dist/esm/index-nodeless.d.ts +0 -152
- package/dist/esm/index-nodeless.js +0 -142
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Migrator = exports.NO_MIGRATIONS = exports.MIGRATION_LOCK_ID = exports.
|
|
3
|
+
exports.Migrator = exports.NO_MIGRATIONS = exports.MIGRATION_LOCK_ID = exports.DEFAULT_MIGRATION_LOCK_TABLE = exports.DEFAULT_MIGRATION_TABLE = void 0;
|
|
4
|
+
const noop_plugin_js_1 = require("../plugin/noop-plugin.js");
|
|
5
|
+
const with_schema_plugin_js_1 = require("../plugin/with-schema/with-schema-plugin.js");
|
|
4
6
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
+
exports.DEFAULT_MIGRATION_TABLE = 'kysely_migration';
|
|
8
|
+
exports.DEFAULT_MIGRATION_LOCK_TABLE = 'kysely_migration_lock';
|
|
7
9
|
exports.MIGRATION_LOCK_ID = 'migration_lock';
|
|
8
10
|
exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true });
|
|
9
11
|
/**
|
|
@@ -37,9 +39,10 @@ class Migrator {
|
|
|
37
39
|
* The returned array is sorted by migration name.
|
|
38
40
|
*/
|
|
39
41
|
async getMigrations() {
|
|
40
|
-
const executedMigrations = (await this.#doesTableExists(
|
|
42
|
+
const executedMigrations = (await this.#doesTableExists(this.#migrationTable))
|
|
41
43
|
? await this.#props.db
|
|
42
|
-
.
|
|
44
|
+
.withPlugin(this.#schemaPlugin)
|
|
45
|
+
.selectFrom(this.#migrationTable)
|
|
43
46
|
.select(['name', 'timestamp'])
|
|
44
47
|
.execute()
|
|
45
48
|
: [];
|
|
@@ -184,16 +187,61 @@ class Migrator {
|
|
|
184
187
|
return { error };
|
|
185
188
|
}
|
|
186
189
|
}
|
|
190
|
+
get #migrationTableSchema() {
|
|
191
|
+
return this.#props.migrationTableSchema;
|
|
192
|
+
}
|
|
193
|
+
get #migrationTable() {
|
|
194
|
+
return this.#props.migrationTableName ?? exports.DEFAULT_MIGRATION_TABLE;
|
|
195
|
+
}
|
|
196
|
+
get #migrationLockTable() {
|
|
197
|
+
return this.#props.migrationLockTableName ?? exports.DEFAULT_MIGRATION_LOCK_TABLE;
|
|
198
|
+
}
|
|
199
|
+
get #schemaPlugin() {
|
|
200
|
+
if (this.#migrationTableSchema) {
|
|
201
|
+
return new with_schema_plugin_js_1.WithSchemaPlugin(this.#migrationTableSchema);
|
|
202
|
+
}
|
|
203
|
+
return new noop_plugin_js_1.NoopPlugin();
|
|
204
|
+
}
|
|
187
205
|
async #ensureMigrationTablesExists() {
|
|
206
|
+
await this.#ensureMigrationTableSchemaExists();
|
|
188
207
|
await this.#ensureMigrationTableExists();
|
|
189
208
|
await this.#ensureMigrationLockTableExists();
|
|
190
209
|
await this.#ensureLockRowExists();
|
|
191
210
|
}
|
|
211
|
+
async #ensureMigrationTableSchemaExists() {
|
|
212
|
+
if (!this.#migrationTableSchema) {
|
|
213
|
+
// Use default schema. Nothing to do.
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!(await this.#doesSchemaExists())) {
|
|
217
|
+
try {
|
|
218
|
+
await this.#props.db.schema
|
|
219
|
+
.createSchema(this.#migrationTableSchema)
|
|
220
|
+
.ifNotExists()
|
|
221
|
+
.execute();
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create schema`
|
|
225
|
+
// query doesn't throw if the schema already exits. That's why we check if
|
|
226
|
+
// the schema exist here and ignore the error if it does.
|
|
227
|
+
if (!(await this.#doesSchemaExists())) {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
192
233
|
async #ensureMigrationTableExists() {
|
|
193
|
-
if (!(await this.#doesTableExists(
|
|
234
|
+
if (!(await this.#doesTableExists(this.#migrationTable))) {
|
|
194
235
|
try {
|
|
236
|
+
if (this.#migrationTableSchema) {
|
|
237
|
+
await this.#props.db.schema
|
|
238
|
+
.createSchema(this.#migrationTableSchema)
|
|
239
|
+
.ifNotExists()
|
|
240
|
+
.execute();
|
|
241
|
+
}
|
|
195
242
|
await this.#props.db.schema
|
|
196
|
-
.
|
|
243
|
+
.withPlugin(this.#schemaPlugin)
|
|
244
|
+
.createTable(this.#migrationTable)
|
|
197
245
|
.ifNotExists()
|
|
198
246
|
.addColumn('name', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
199
247
|
// The migration run time as ISO string. This is not a real date type as we
|
|
@@ -205,17 +253,18 @@ class Migrator {
|
|
|
205
253
|
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
206
254
|
// query doesn't throw if the table already exits. That's why we check if
|
|
207
255
|
// the table exist here and ignore the error if it does.
|
|
208
|
-
if (!(await this.#doesTableExists(
|
|
256
|
+
if (!(await this.#doesTableExists(this.#migrationTable))) {
|
|
209
257
|
throw error;
|
|
210
258
|
}
|
|
211
259
|
}
|
|
212
260
|
}
|
|
213
261
|
}
|
|
214
262
|
async #ensureMigrationLockTableExists() {
|
|
215
|
-
if (!(await this.#doesTableExists(
|
|
263
|
+
if (!(await this.#doesTableExists(this.#migrationLockTable))) {
|
|
216
264
|
try {
|
|
217
265
|
await this.#props.db.schema
|
|
218
|
-
.
|
|
266
|
+
.withPlugin(this.#schemaPlugin)
|
|
267
|
+
.createTable(this.#migrationLockTable)
|
|
219
268
|
.ifNotExists()
|
|
220
269
|
.addColumn('id', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
221
270
|
.addColumn('is_locked', 'integer', (col) => col.notNull().defaultTo(0))
|
|
@@ -225,7 +274,7 @@ class Migrator {
|
|
|
225
274
|
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
226
275
|
// query doesn't throw if the table already exits. That's why we check if
|
|
227
276
|
// the table exist here and ignore the error if it does.
|
|
228
|
-
if (!(await this.#doesTableExists(
|
|
277
|
+
if (!(await this.#doesTableExists(this.#migrationLockTable))) {
|
|
229
278
|
throw error;
|
|
230
279
|
}
|
|
231
280
|
}
|
|
@@ -235,7 +284,8 @@ class Migrator {
|
|
|
235
284
|
if (!(await this.#doesLockRowExists())) {
|
|
236
285
|
try {
|
|
237
286
|
await this.#props.db
|
|
238
|
-
.
|
|
287
|
+
.withPlugin(this.#schemaPlugin)
|
|
288
|
+
.insertInto(this.#migrationLockTable)
|
|
239
289
|
.values({ id: exports.MIGRATION_LOCK_ID, is_locked: 0 })
|
|
240
290
|
.execute();
|
|
241
291
|
}
|
|
@@ -246,15 +296,21 @@ class Migrator {
|
|
|
246
296
|
}
|
|
247
297
|
}
|
|
248
298
|
}
|
|
299
|
+
async #doesSchemaExists() {
|
|
300
|
+
const schemas = await this.#props.db.introspection.getSchemas();
|
|
301
|
+
return schemas.some((it) => it.name === this.#migrationTableSchema);
|
|
302
|
+
}
|
|
249
303
|
async #doesTableExists(tableName) {
|
|
250
|
-
const
|
|
304
|
+
const schema = this.#migrationTableSchema;
|
|
305
|
+
const tables = await this.#props.db.introspection.getTables({
|
|
251
306
|
withInternalKyselyTables: true,
|
|
252
307
|
});
|
|
253
|
-
return
|
|
308
|
+
return tables.some((it) => it.name === tableName && (!schema || it.schema === schema));
|
|
254
309
|
}
|
|
255
310
|
async #doesLockRowExists() {
|
|
256
311
|
const lockRow = await this.#props.db
|
|
257
|
-
.
|
|
312
|
+
.withPlugin(this.#schemaPlugin)
|
|
313
|
+
.selectFrom(this.#migrationLockTable)
|
|
258
314
|
.where('id', '=', exports.MIGRATION_LOCK_ID)
|
|
259
315
|
.select('id')
|
|
260
316
|
.executeTakeFirst();
|
|
@@ -312,7 +368,8 @@ class Migrator {
|
|
|
312
368
|
}
|
|
313
369
|
async #getExecutedMigrations(db) {
|
|
314
370
|
const executedMigrations = await db
|
|
315
|
-
.
|
|
371
|
+
.withPlugin(this.#schemaPlugin)
|
|
372
|
+
.selectFrom(this.#migrationTable)
|
|
316
373
|
.select('name')
|
|
317
374
|
.orderBy('name')
|
|
318
375
|
.execute();
|
|
@@ -348,7 +405,8 @@ class Migrator {
|
|
|
348
405
|
if (migration.down) {
|
|
349
406
|
await migration.down(db);
|
|
350
407
|
await db
|
|
351
|
-
.
|
|
408
|
+
.withPlugin(this.#schemaPlugin)
|
|
409
|
+
.deleteFrom(this.#migrationTable)
|
|
352
410
|
.where('name', '=', migration.name)
|
|
353
411
|
.execute();
|
|
354
412
|
results[i] = {
|
|
@@ -386,7 +444,8 @@ class Migrator {
|
|
|
386
444
|
try {
|
|
387
445
|
await migration.up(db);
|
|
388
446
|
await db
|
|
389
|
-
.
|
|
447
|
+
.withPlugin(this.#schemaPlugin)
|
|
448
|
+
.insertInto(this.#migrationTable)
|
|
390
449
|
.values({
|
|
391
450
|
name: migration.name,
|
|
392
451
|
timestamp: new Date().toISOString(),
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { QueryResult } from '../driver/database-connection.js';
|
|
2
|
+
import { RootOperationNode } from '../query-compiler/query-compiler.js';
|
|
3
|
+
import { UnknownRow } from '../util/type-utils.js';
|
|
4
|
+
import { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs } from './kysely-plugin.js';
|
|
5
|
+
export declare class NoopPlugin implements KyselyPlugin {
|
|
6
|
+
/**
|
|
7
|
+
* This is called for each query before it is executed. You can modify the query by
|
|
8
|
+
* transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
|
|
9
|
+
* and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
|
|
10
|
+
* for this.
|
|
11
|
+
*
|
|
12
|
+
* If you need to pass some query-related data between this method and `transformResult` you
|
|
13
|
+
* can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const plugin = {
|
|
17
|
+
* data: new WeakMap<QueryId, SomeData>(),
|
|
18
|
+
*
|
|
19
|
+
* transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
|
|
20
|
+
* this.data.set(args.queryId, something)
|
|
21
|
+
* return args.node
|
|
22
|
+
* },
|
|
23
|
+
*
|
|
24
|
+
* transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
|
|
25
|
+
* const data = this.data.get(args.queryId)
|
|
26
|
+
* return args.result
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
|
|
32
|
+
* is not always matched by a call to `transformResult` which would leave orphaned items in the map
|
|
33
|
+
* and cause a memory leak.
|
|
34
|
+
*/
|
|
35
|
+
transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
|
|
36
|
+
/**
|
|
37
|
+
* This method is called for each query after it has been executed. The result
|
|
38
|
+
* of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
|
|
39
|
+
* You can modify the result and return the modifier result.
|
|
40
|
+
*/
|
|
41
|
+
transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoopPlugin = void 0;
|
|
4
|
+
class NoopPlugin {
|
|
5
|
+
transformQuery(args) {
|
|
6
|
+
return args.node;
|
|
7
|
+
}
|
|
8
|
+
async transformResult(args) {
|
|
9
|
+
return args.result;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.NoopPlugin = NoopPlugin;
|
|
@@ -9,6 +9,7 @@ import { WithNode } from './operation-node/with-node.js';
|
|
|
9
9
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
10
10
|
import { DeleteResult } from './query-builder/delete-result.js';
|
|
11
11
|
import { UpdateResult } from './query-builder/update-result.js';
|
|
12
|
+
import { KyselyPlugin } from './plugin/kysely-plugin.js';
|
|
12
13
|
export declare class QueryCreator<DB> {
|
|
13
14
|
#private;
|
|
14
15
|
constructor(props: QueryCreatorProps);
|
|
@@ -252,6 +253,14 @@ export declare class QueryCreator<DB> {
|
|
|
252
253
|
* See the {@link with} method for examples and more documentation.
|
|
253
254
|
*/
|
|
254
255
|
withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
256
|
+
/**
|
|
257
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
258
|
+
*/
|
|
259
|
+
withPlugin(plugin: KyselyPlugin): QueryCreator<DB>;
|
|
260
|
+
/**
|
|
261
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
262
|
+
*/
|
|
263
|
+
withoutPlugins(): QueryCreator<DB>;
|
|
255
264
|
/**
|
|
256
265
|
* Sets the schema to be used for all table references that don't explicitly
|
|
257
266
|
* specify a schema.
|
|
@@ -192,6 +192,24 @@ class QueryCreator {
|
|
|
192
192
|
: with_node_js_1.WithNode.create(cte, { recursive: true }),
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
197
|
+
*/
|
|
198
|
+
withPlugin(plugin) {
|
|
199
|
+
return new QueryCreator({
|
|
200
|
+
...this.#props,
|
|
201
|
+
executor: this.#props.executor.withPlugin(plugin),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
206
|
+
*/
|
|
207
|
+
withoutPlugins() {
|
|
208
|
+
return new QueryCreator({
|
|
209
|
+
...this.#props,
|
|
210
|
+
executor: this.#props.executor.withoutPlugins(),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
195
213
|
/**
|
|
196
214
|
* Sets the schema to be used for all table references that don't explicitly
|
|
197
215
|
* specify a schema.
|
|
@@ -25,12 +25,8 @@ export declare class AlterTableBuilder {
|
|
|
25
25
|
renameColumn(column: string, newColumn: string): AlterTableExecutor;
|
|
26
26
|
/**
|
|
27
27
|
* See {@link CreateTableBuilder.addColumn}
|
|
28
|
-
*
|
|
29
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
30
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
31
|
-
* add one column per `ALTER TABLE` query.
|
|
32
28
|
*/
|
|
33
|
-
addColumn(columnName: string, dataType: DataTypeExpression): AlterTableAddColumnBuilder;
|
|
29
|
+
addColumn(columnName: string, dataType: DataTypeExpression, build?: AlterTableAddColumnBuilderCallback): AlterTableAddColumnBuilder;
|
|
34
30
|
/**
|
|
35
31
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
36
32
|
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
|
@@ -245,6 +241,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
245
241
|
export interface AlterTableAddColumnBuilderProps extends AlterTableBuilderProps {
|
|
246
242
|
readonly columnBuilder: ColumnDefinitionBuilder;
|
|
247
243
|
}
|
|
244
|
+
export declare type AlterTableAddColumnBuilderCallback = (builder: AlterTableAddColumnBuilder) => AlterTableAddColumnBuilder;
|
|
248
245
|
export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBuilderInterface, OperationNodeSource, Compilable {
|
|
249
246
|
#private;
|
|
250
247
|
constructor(props: AlterTableModifyColumnBuilderProps);
|
|
@@ -70,16 +70,12 @@ class AlterTableBuilder {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* See {@link CreateTableBuilder.addColumn}
|
|
73
|
-
*
|
|
74
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
75
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
76
|
-
* add one column per `ALTER TABLE` query.
|
|
77
73
|
*/
|
|
78
|
-
addColumn(columnName, dataType) {
|
|
79
|
-
return new AlterTableAddColumnBuilder({
|
|
74
|
+
addColumn(columnName, dataType, build = object_utils_js_1.noop) {
|
|
75
|
+
return build(new AlterTableAddColumnBuilder({
|
|
80
76
|
...this.#props,
|
|
81
77
|
columnBuilder: new column_definition_builder_js_1.ColumnDefinitionBuilder(column_definition_node_js_1.ColumnDefinitionNode.create(columnName, (0, data_type_parser_js_1.parseDataTypeExpression)(dataType))),
|
|
82
|
-
});
|
|
78
|
+
}));
|
|
83
79
|
}
|
|
84
80
|
/**
|
|
85
81
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
@@ -8,6 +8,7 @@ import { DropSchemaBuilder } from './drop-schema-builder.js';
|
|
|
8
8
|
import { DropTableBuilder } from './drop-table-builder.js';
|
|
9
9
|
import { CreateViewBuilder } from './create-view-builder.js';
|
|
10
10
|
import { DropViewBuilder } from './drop-view-builder.js';
|
|
11
|
+
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
11
12
|
/**
|
|
12
13
|
* Provides methods for building database schema.
|
|
13
14
|
*/
|
|
@@ -169,6 +170,14 @@ export declare class SchemaModule {
|
|
|
169
170
|
* ```
|
|
170
171
|
*/
|
|
171
172
|
dropView(viewName: string): DropViewBuilder;
|
|
173
|
+
/**
|
|
174
|
+
* Returns a copy of this schema module with the given plugin installed.
|
|
175
|
+
*/
|
|
176
|
+
withPlugin(plugin: KyselyPlugin): SchemaModule;
|
|
177
|
+
/**
|
|
178
|
+
* Returns a copy of this schema module without any plugins.
|
|
179
|
+
*/
|
|
180
|
+
withoutPlugins(): SchemaModule;
|
|
172
181
|
/**
|
|
173
182
|
* See {@link QueryCreator.withSchema}
|
|
174
183
|
*/
|
|
@@ -239,6 +239,18 @@ class SchemaModule {
|
|
|
239
239
|
dropViewNode: drop_view_node_js_1.DropViewNode.create(viewName),
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns a copy of this schema module with the given plugin installed.
|
|
244
|
+
*/
|
|
245
|
+
withPlugin(plugin) {
|
|
246
|
+
return new SchemaModule(this.#executor.withPlugin(plugin));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Returns a copy of this schema module without any plugins.
|
|
250
|
+
*/
|
|
251
|
+
withoutPlugins() {
|
|
252
|
+
return new SchemaModule(this.#executor.withoutPlugins());
|
|
253
|
+
}
|
|
242
254
|
/**
|
|
243
255
|
* See {@link QueryCreator.withSchema}
|
|
244
256
|
*/
|
|
@@ -43,13 +43,21 @@ export declare type ColumnType<SelectType, InsertType = SelectType, UpdateType =
|
|
|
43
43
|
* is the same for all selects, inserts and updates but the
|
|
44
44
|
* column is optional for inserts and updates.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* The implementation:
|
|
47
47
|
*
|
|
48
48
|
* ```ts
|
|
49
|
+
* // The update type is `S` instead of `S | undefined` because
|
|
50
|
+
* // updates are always optional --> no need to specify optionality.
|
|
49
51
|
* type Generated<S> = ColumnType<S, S | undefined, S>
|
|
50
52
|
* ```
|
|
51
53
|
*/
|
|
52
54
|
export declare type Generated<S> = ColumnType<S, S | undefined, S>;
|
|
55
|
+
/**
|
|
56
|
+
* A shortcut for defining columns that are only database-generated
|
|
57
|
+
* (like postgres GENERATED ALWAYS AS IDENTITY). No insert/update
|
|
58
|
+
* is allowed.
|
|
59
|
+
*/
|
|
60
|
+
export declare type GeneratedAlways<S> = ColumnType<S, never, never>;
|
|
53
61
|
/**
|
|
54
62
|
* Evaluates to `K` if `T` can be `null` or `undefined`.
|
|
55
63
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extendStackTrace(err: unknown, stackError: Error): unknown;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendStackTrace = void 0;
|
|
4
|
+
const object_utils_js_1 = require("./object-utils.js");
|
|
5
|
+
function extendStackTrace(err, stackError) {
|
|
6
|
+
if (isStackHolder(err) && stackError.stack) {
|
|
7
|
+
// Remove the first line that just says `Error`.
|
|
8
|
+
const stackExtension = stackError.stack.split('\n').slice(1).join('\n');
|
|
9
|
+
err.stack += `\n${stackExtension}`;
|
|
10
|
+
return err;
|
|
11
|
+
}
|
|
12
|
+
return err;
|
|
13
|
+
}
|
|
14
|
+
exports.extendStackTrace = extendStackTrace;
|
|
15
|
+
function isStackHolder(obj) {
|
|
16
|
+
return (0, object_utils_js_1.isObject)(obj) && (0, object_utils_js_1.isString)(obj.stack);
|
|
17
|
+
}
|
|
@@ -3,8 +3,18 @@ import { ColumnDataType } from '../operation-node/data-type-node.js';
|
|
|
3
3
|
* An interface for getting the database metadata (names of the tables and columns etc.)
|
|
4
4
|
*/
|
|
5
5
|
export interface DatabaseIntrospector {
|
|
6
|
+
/**
|
|
7
|
+
* Get schema metadata.
|
|
8
|
+
*/
|
|
9
|
+
getSchemas(): Promise<SchemaMetadata[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Get table metadata.
|
|
12
|
+
*/
|
|
13
|
+
getTables(options?: DatabaseMetadataOptions): Promise<TableMetadata[]>;
|
|
6
14
|
/**
|
|
7
15
|
* Get the database metadata such as table and column names.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Use getTables() instead.
|
|
8
18
|
*/
|
|
9
19
|
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
|
|
10
20
|
}
|
|
@@ -15,6 +25,9 @@ export interface DatabaseMetadataOptions {
|
|
|
15
25
|
*/
|
|
16
26
|
withInternalKyselyTables: boolean;
|
|
17
27
|
}
|
|
28
|
+
export interface SchemaMetadata {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
}
|
|
18
31
|
export interface DatabaseMetadata {
|
|
19
32
|
/**
|
|
20
33
|
* The tables found in the database.
|