kysely 0.12.0 → 0.14.0
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 +34 -10
- 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-adapter-base.d.ts +36 -0
- package/dist/cjs/dialect/dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +38 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +17 -1
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +4 -1
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +38 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +17 -1
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +4 -1
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +38 -2
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +17 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +4 -1
- package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
- package/dist/cjs/driver/runtime-driver.d.ts +29 -0
- package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/kysely.d.ts +152 -1
- package/dist/cjs/kysely.js +37 -0
- package/dist/cjs/migration/migration.d.ts +154 -11
- package/dist/cjs/migration/migration.js +256 -135
- 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 +8 -7
- package/dist/cjs/operation-node/column-definition-node.js +0 -4
- package/dist/cjs/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/cjs/operation-node/common-table-expression-name-node.js +23 -0
- package/dist/cjs/operation-node/common-table-expression-node.d.ts +3 -3
- 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 +4 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +22 -6
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +4 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +2 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/with-node.d.ts +3 -1
- package/dist/cjs/operation-node/with-node.js +2 -1
- package/dist/cjs/package.json +1 -3
- package/dist/cjs/parser/parse-context.d.ts +14 -0
- package/dist/cjs/parser/with-parser.d.ts +32 -5
- package/dist/cjs/parser/with-parser.js +13 -2
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +36 -2
- package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
- package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -0
- package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +545 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +142 -76
- package/dist/cjs/query-builder/insert-query-builder.js +150 -15
- package/dist/cjs/query-builder/join-interface.d.ts +3 -6
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +684 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +513 -2
- package/dist/cjs/query-builder/select-query-builder.js +2 -2
- package/dist/cjs/query-builder/update-query-builder.d.ts +547 -2
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-builder/where-interface.d.ts +7 -10
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +48 -8
- package/dist/cjs/query-creator.d.ts +27 -3
- package/dist/cjs/query-creator.js +33 -1
- package/dist/cjs/query-executor/default-query-executor.d.ts +19 -0
- package/dist/cjs/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/cjs/raw-builder/raw-builder.js +1 -1
- package/dist/cjs/schema/alter-table-builder.d.ts +253 -5
- package/dist/cjs/schema/alter-table-builder.js +45 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +146 -6
- package/dist/cjs/schema/column-definition-builder.js +21 -8
- 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/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +38 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +17 -1
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +4 -1
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +38 -2
- package/dist/esm/dialect/postgres/postgres-adapter.js +2 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +17 -1
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +4 -1
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +38 -2
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +17 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +4 -1
- package/dist/esm/driver/default-connection-provider.d.ts +4 -0
- package/dist/esm/driver/runtime-driver.d.ts +29 -0
- package/dist/esm/driver/single-connection-provider.d.ts +4 -0
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +3 -2
- package/dist/esm/kysely.d.ts +152 -1
- package/dist/esm/kysely.js +37 -0
- package/dist/esm/migration/migration.d.ts +154 -11
- package/dist/esm/migration/migration.js +255 -134
- 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 +8 -7
- package/dist/esm/operation-node/column-definition-node.js +0 -4
- package/dist/esm/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/esm/operation-node/common-table-expression-name-node.js +20 -0
- package/dist/esm/operation-node/common-table-expression-node.d.ts +3 -3
- 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 +4 -2
- package/dist/esm/operation-node/operation-node-transformer.js +22 -6
- package/dist/esm/operation-node/operation-node-visitor.d.ts +4 -2
- package/dist/esm/operation-node/operation-node-visitor.js +2 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/with-node.d.ts +3 -1
- package/dist/esm/operation-node/with-node.js +2 -1
- package/dist/esm/package.json +1 -3
- package/dist/esm/parser/parse-context.d.ts +14 -0
- package/dist/esm/parser/with-parser.d.ts +32 -5
- package/dist/esm/parser/with-parser.js +13 -2
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +36 -2
- package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
- package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
- package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +545 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +142 -76
- package/dist/esm/query-builder/insert-query-builder.js +150 -15
- package/dist/esm/query-builder/join-interface.d.ts +3 -6
- package/dist/esm/query-builder/on-conflict-builder.d.ts +684 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-builder/returning-interface.d.ts +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +513 -2
- package/dist/esm/query-builder/select-query-builder.js +2 -2
- package/dist/esm/query-builder/update-query-builder.d.ts +547 -2
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-builder/where-interface.d.ts +7 -10
- package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -2
- package/dist/esm/query-compiler/default-query-compiler.js +48 -8
- package/dist/esm/query-creator.d.ts +27 -3
- package/dist/esm/query-creator.js +33 -1
- package/dist/esm/query-executor/default-query-executor.d.ts +19 -0
- package/dist/esm/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/esm/raw-builder/raw-builder.js +1 -1
- package/dist/esm/schema/alter-table-builder.d.ts +253 -5
- package/dist/esm/schema/alter-table-builder.js +45 -9
- package/dist/esm/schema/column-definition-builder.d.ts +146 -6
- package/dist/esm/schema/column-definition-builder.js +21 -8
- 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/package.json +8 -6
- 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/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/cjs/index.js
CHANGED
|
@@ -85,6 +85,7 @@ __exportStar(require("./operation-node/column-definition-node.js"), exports);
|
|
|
85
85
|
__exportStar(require("./operation-node/column-node.js"), exports);
|
|
86
86
|
__exportStar(require("./operation-node/column-update-node.js"), exports);
|
|
87
87
|
__exportStar(require("./operation-node/common-table-expression-node.js"), exports);
|
|
88
|
+
__exportStar(require("./operation-node/common-table-expression-name-node.js"), exports);
|
|
88
89
|
__exportStar(require("./operation-node/constraint-node.js"), exports);
|
|
89
90
|
__exportStar(require("./operation-node/create-index-node.js"), exports);
|
|
90
91
|
__exportStar(require("./operation-node/create-schema-node.js"), exports);
|
|
@@ -102,7 +103,7 @@ __exportStar(require("./operation-node/drop-view-node.js"), exports);
|
|
|
102
103
|
__exportStar(require("./operation-node/filter-node.js"), exports);
|
|
103
104
|
__exportStar(require("./operation-node/foreign-key-constraint-node.js"), exports);
|
|
104
105
|
__exportStar(require("./operation-node/from-node.js"), exports);
|
|
105
|
-
__exportStar(require("./operation-node/generated-
|
|
106
|
+
__exportStar(require("./operation-node/generated-node.js"), exports);
|
|
106
107
|
__exportStar(require("./operation-node/group-by-item-node.js"), exports);
|
|
107
108
|
__exportStar(require("./operation-node/group-by-node.js"), exports);
|
|
108
109
|
__exportStar(require("./operation-node/having-node.js"), exports);
|
|
@@ -147,6 +148,6 @@ __exportStar(require("./operation-node/value-node.js"), exports);
|
|
|
147
148
|
__exportStar(require("./operation-node/values-node.js"), exports);
|
|
148
149
|
__exportStar(require("./operation-node/where-node.js"), exports);
|
|
149
150
|
__exportStar(require("./operation-node/with-node.js"), exports);
|
|
150
|
-
__exportStar(require("./
|
|
151
|
+
__exportStar(require("./dialect/database-introspector.js"), exports);
|
|
151
152
|
__exportStar(require("./util/compilable.js"), exports);
|
|
152
153
|
__exportStar(require("./util/log.js"), exports);
|
package/dist/cjs/kysely.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { QueryExecutor } from './query-executor/query-executor.js';
|
|
|
6
6
|
import { QueryCreator } from './query-creator.js';
|
|
7
7
|
import { KyselyPlugin } from './plugin/kysely-plugin.js';
|
|
8
8
|
import { GeneratedPlaceholder } from './util/type-utils.js';
|
|
9
|
-
import { DatabaseIntrospector } from './
|
|
9
|
+
import { DatabaseIntrospector } from './dialect/database-introspector.js';
|
|
10
10
|
import { Driver, IsolationLevel } from './driver/driver.js';
|
|
11
11
|
import { ParseContext } from './parser/parse-context.js';
|
|
12
12
|
import { FunctionBuilder } from './query-builder/function-builder.js';
|
|
@@ -207,6 +207,38 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
207
207
|
* Returns a copy of this Kysely instance without any plugins.
|
|
208
208
|
*/
|
|
209
209
|
withoutPlugins(): Kysely<DB>;
|
|
210
|
+
/**
|
|
211
|
+
* Returns a copy of this Kysely instance with tables added to its
|
|
212
|
+
* database type.
|
|
213
|
+
*
|
|
214
|
+
* This method only modifies the types and doesn't affect any of the
|
|
215
|
+
* executed queries in any way.
|
|
216
|
+
*
|
|
217
|
+
* ### Examples
|
|
218
|
+
*
|
|
219
|
+
* The following example adds and uses a temporary table:
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* await db.schema
|
|
224
|
+
* .createTable('temp_table')
|
|
225
|
+
* .temporary()
|
|
226
|
+
* .addColumn('some_column', 'integer')
|
|
227
|
+
* .execute()
|
|
228
|
+
*
|
|
229
|
+
* const tempDb = db.withTables<{
|
|
230
|
+
* temp_table: {
|
|
231
|
+
* some_column: number
|
|
232
|
+
* }
|
|
233
|
+
* }>()
|
|
234
|
+
*
|
|
235
|
+
* await tempDb
|
|
236
|
+
* .insertInto('temp_table')
|
|
237
|
+
* .values({ some_column: 100 })
|
|
238
|
+
* .execute()
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
withTables<T extends Record<string, Record<string, any>>>(): Kysely<DB & T>;
|
|
210
242
|
/**
|
|
211
243
|
* Releases all resources and disconnects from the database.
|
|
212
244
|
*
|
|
@@ -223,13 +255,132 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
223
255
|
export declare class Transaction<DB> extends Kysely<DB> {
|
|
224
256
|
#private;
|
|
225
257
|
constructor(props: KyselyProps);
|
|
258
|
+
/**
|
|
259
|
+
* Returns true if this `Kysely` instance is a transaction.
|
|
260
|
+
*
|
|
261
|
+
* You can also use `db instanceof Transaction`.
|
|
262
|
+
*/
|
|
226
263
|
get isTransaction(): true;
|
|
264
|
+
/**
|
|
265
|
+
* Returns the {@link MigrationModule} module for managing and running migrations.
|
|
266
|
+
*/
|
|
227
267
|
get migration(): MigrationModule;
|
|
268
|
+
/**
|
|
269
|
+
* Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
|
|
270
|
+
*
|
|
271
|
+
* The returned {@link TransactionBuilder} can be used to configure the transaction. The
|
|
272
|
+
* {@link TransactionBuilder.execute} method can then be called to run the transaction.
|
|
273
|
+
* {@link TransactionBuilder.execute} takes a function that is run inside the
|
|
274
|
+
* transaction. If the function throws, the transaction is rolled back. Otherwise
|
|
275
|
+
* the transaction is committed.
|
|
276
|
+
*
|
|
277
|
+
* The callback function passed to the {@link TransactionBuilder.execute | execute}
|
|
278
|
+
* method gets the transaction object as its only argument. The transaction is
|
|
279
|
+
* of type {@link Transaction} which inherits {@link Kysely}. Any query
|
|
280
|
+
* started through the transaction object is executed inside the transaction.
|
|
281
|
+
*
|
|
282
|
+
* ### Examples
|
|
283
|
+
*
|
|
284
|
+
* ```ts
|
|
285
|
+
* const catto = await db.transaction().execute(async (trx) => {
|
|
286
|
+
* const jennifer = await trx.insertInto('person')
|
|
287
|
+
* .values({
|
|
288
|
+
* id: db.generated,
|
|
289
|
+
* first_name: 'Jennifer',
|
|
290
|
+
* last_name: 'Aniston',
|
|
291
|
+
* })
|
|
292
|
+
* .returning('id')
|
|
293
|
+
* .executeTakeFirstOrThrow()
|
|
294
|
+
*
|
|
295
|
+
* await someFunction(trx, jennifer)
|
|
296
|
+
*
|
|
297
|
+
* return await trx.insertInto('pet')
|
|
298
|
+
* .values({
|
|
299
|
+
* id: db.generated,
|
|
300
|
+
* user_id: jennifer.id,
|
|
301
|
+
* name: 'Catto',
|
|
302
|
+
* species: 'cat'
|
|
303
|
+
* })
|
|
304
|
+
* .returning('*')
|
|
305
|
+
* .executeTakeFirst()
|
|
306
|
+
* })
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* Setting the isolation level:
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* await db
|
|
313
|
+
* .transaction()
|
|
314
|
+
* .setIsolationLevel('serializable')
|
|
315
|
+
* .execute(async (trx) => {
|
|
316
|
+
* await doStuff(trx)
|
|
317
|
+
* })
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
228
320
|
transaction(): TransactionBuilder<DB>;
|
|
321
|
+
/**
|
|
322
|
+
* Provides a kysely instance bound to a single database connection.
|
|
323
|
+
*
|
|
324
|
+
* ### Examples
|
|
325
|
+
*
|
|
326
|
+
* ```ts
|
|
327
|
+
* await db
|
|
328
|
+
* .connection()
|
|
329
|
+
* .execute(async (db) => {
|
|
330
|
+
* // `db` is an instance of `Kysely` that's bound to a single
|
|
331
|
+
* // database connection. All queries executed through `db` use
|
|
332
|
+
* // the same connection.
|
|
333
|
+
* await doStuff(db)
|
|
334
|
+
* })
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
229
337
|
connection(): ConnectionBuilder<DB>;
|
|
338
|
+
/**
|
|
339
|
+
* Releases all resources and disconnects from the database.
|
|
340
|
+
*
|
|
341
|
+
* You need to call this when you are done using the `Kysely` instance.
|
|
342
|
+
*/
|
|
230
343
|
destroy(): Promise<void>;
|
|
344
|
+
/**
|
|
345
|
+
* Returns a copy of this Kysely instance with the given plugin installed.
|
|
346
|
+
*/
|
|
231
347
|
withPlugin(plugin: KyselyPlugin): Transaction<DB>;
|
|
348
|
+
/**
|
|
349
|
+
* Returns a copy of this Kysely instance without any plugins.
|
|
350
|
+
*/
|
|
232
351
|
withoutPlugins(): Transaction<DB>;
|
|
352
|
+
/**
|
|
353
|
+
* Returns a copy of this Kysely instance with tables added to its
|
|
354
|
+
* database type.
|
|
355
|
+
*
|
|
356
|
+
* This method only modifies the types and doesn't affect any of the
|
|
357
|
+
* executed queries in any way.
|
|
358
|
+
*
|
|
359
|
+
* ### Examples
|
|
360
|
+
*
|
|
361
|
+
* The following example adds and uses a temporary table:
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* await db.schema
|
|
366
|
+
* .createTable('temp_table')
|
|
367
|
+
* .temporary()
|
|
368
|
+
* .addColumn('some_column', 'integer')
|
|
369
|
+
* .execute()
|
|
370
|
+
*
|
|
371
|
+
* const tempDb = db.withTables<{
|
|
372
|
+
* temp_table: {
|
|
373
|
+
* some_column: number
|
|
374
|
+
* }
|
|
375
|
+
* }>()
|
|
376
|
+
*
|
|
377
|
+
* await tempDb
|
|
378
|
+
* .insertInto('temp_table')
|
|
379
|
+
* .values({ some_column: 100 })
|
|
380
|
+
* .execute()
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
withTables<T extends Record<string, Record<string, any>>>(): Transaction<DB & T>;
|
|
233
384
|
}
|
|
234
385
|
export interface KyselyProps {
|
|
235
386
|
readonly config: KyselyConfig;
|
package/dist/cjs/kysely.js
CHANGED
|
@@ -261,6 +261,40 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
261
261
|
executor: this.#props.executor.withoutPlugins(),
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns a copy of this Kysely instance with tables added to its
|
|
266
|
+
* database type.
|
|
267
|
+
*
|
|
268
|
+
* This method only modifies the types and doesn't affect any of the
|
|
269
|
+
* executed queries in any way.
|
|
270
|
+
*
|
|
271
|
+
* ### Examples
|
|
272
|
+
*
|
|
273
|
+
* The following example adds and uses a temporary table:
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* await db.schema
|
|
278
|
+
* .createTable('temp_table')
|
|
279
|
+
* .temporary()
|
|
280
|
+
* .addColumn('some_column', 'integer')
|
|
281
|
+
* .execute()
|
|
282
|
+
*
|
|
283
|
+
* const tempDb = db.withTables<{
|
|
284
|
+
* temp_table: {
|
|
285
|
+
* some_column: number
|
|
286
|
+
* }
|
|
287
|
+
* }>()
|
|
288
|
+
*
|
|
289
|
+
* await tempDb
|
|
290
|
+
* .insertInto('temp_table')
|
|
291
|
+
* .values({ some_column: 100 })
|
|
292
|
+
* .execute()
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
withTables() {
|
|
296
|
+
return new Kysely({ ...this.#props });
|
|
297
|
+
}
|
|
264
298
|
/**
|
|
265
299
|
* Releases all resources and disconnects from the database.
|
|
266
300
|
*
|
|
@@ -315,6 +349,9 @@ class Transaction extends Kysely {
|
|
|
315
349
|
executor: this.#props.executor.withoutPlugins(),
|
|
316
350
|
});
|
|
317
351
|
}
|
|
352
|
+
withTables() {
|
|
353
|
+
return new Transaction({ ...this.#props });
|
|
354
|
+
}
|
|
318
355
|
}
|
|
319
356
|
exports.Transaction = Transaction;
|
|
320
357
|
function isKyselyProps(obj) {
|
|
@@ -3,6 +3,73 @@ import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
|
3
3
|
export declare const MIGRATION_TABLE = "kysely_migration";
|
|
4
4
|
export declare const MIGRATION_LOCK_TABLE = "kysely_migration_lock";
|
|
5
5
|
export declare const MIGRATION_LOCK_ID = "migration_lock";
|
|
6
|
+
export declare const NO_MIGRATIONS: NoMigrations;
|
|
7
|
+
export declare type MigrationsOrFolderPath = Record<string, Migration> | string;
|
|
8
|
+
export interface Migration {
|
|
9
|
+
up(db: Kysely<any>): Promise<void>;
|
|
10
|
+
down?(db: Kysely<any>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type for the NO_MIGRATIONS constant. Never create one of these.
|
|
14
|
+
*/
|
|
15
|
+
export interface NoMigrations {
|
|
16
|
+
readonly __noMigrations__: true;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* All migration methods ({@link MigrationModule.migrateTo | migrateTo},
|
|
20
|
+
* {@link MigrationModule.migrateToLatest | migrateToLatest} etc.) never
|
|
21
|
+
* throw but return this object instead.
|
|
22
|
+
*/
|
|
23
|
+
export interface MigrationResultSet {
|
|
24
|
+
/**
|
|
25
|
+
* This is defined if something went wrong.
|
|
26
|
+
*
|
|
27
|
+
* An error may have occurred in one of the migrations in which case the
|
|
28
|
+
* {@link results} list contains an item with `status === 'Error'` to
|
|
29
|
+
* indicate which migration failed.
|
|
30
|
+
*
|
|
31
|
+
* An error may also have occurred before Kysely was able to figure out
|
|
32
|
+
* which migrations should be executed, in which case the {@link results}
|
|
33
|
+
* list is undefined.
|
|
34
|
+
*/
|
|
35
|
+
readonly error?: unknown;
|
|
36
|
+
/**
|
|
37
|
+
* {@link MigrationResult} for each individual migration that was supposed
|
|
38
|
+
* to be executed by the operation.
|
|
39
|
+
*
|
|
40
|
+
* If all went well, each result's `status` is `Success`. If some migration
|
|
41
|
+
* failed, the failed migration's result's `status` is `Error` and all
|
|
42
|
+
* results after that one have `status` ´NotExecuted`.
|
|
43
|
+
*
|
|
44
|
+
* This property can be undefined if an error occurred before Kysely was
|
|
45
|
+
* able to figure out which migrations should be executed.
|
|
46
|
+
*
|
|
47
|
+
* If this list is empty, there were no migrations to execute.
|
|
48
|
+
*/
|
|
49
|
+
readonly results?: MigrationResult[];
|
|
50
|
+
}
|
|
51
|
+
export interface MigrationResult {
|
|
52
|
+
readonly migrationName: string;
|
|
53
|
+
/**
|
|
54
|
+
* The direction in which this migration was executed.
|
|
55
|
+
*/
|
|
56
|
+
readonly direction: 'Up' | 'Down';
|
|
57
|
+
/**
|
|
58
|
+
* The execution status.
|
|
59
|
+
*
|
|
60
|
+
* - `Success` means the migration was successfully executed. Note that
|
|
61
|
+
* if any of the later migrations in the {@link MigrationResult.results}
|
|
62
|
+
* list failed (have status `Error`) AND the dialect supports transactional
|
|
63
|
+
* DDL, even the successfull migrations were rolled back.
|
|
64
|
+
*
|
|
65
|
+
* - `Error` means the migration failed. In this case the
|
|
66
|
+
* {@link MigrationResult.error} contains the error.
|
|
67
|
+
*
|
|
68
|
+
* - `NotExecuted` means that the migration was supposed to be executed
|
|
69
|
+
* but wasn't because an earlier migration failed.
|
|
70
|
+
*/
|
|
71
|
+
readonly status: 'Success' | 'Error' | 'NotExecuted';
|
|
72
|
+
}
|
|
6
73
|
export declare class MigrationModule {
|
|
7
74
|
#private;
|
|
8
75
|
constructor(db: Kysely<any>, adapter: DialectAdapter);
|
|
@@ -10,26 +77,45 @@ export declare class MigrationModule {
|
|
|
10
77
|
* Runs all migrations that have not yet been run.
|
|
11
78
|
*
|
|
12
79
|
* The only argument must either be a file path to the folder that contains all migrations
|
|
13
|
-
* OR an object that contains all migrations (not just the ones that need to be
|
|
80
|
+
* OR an object that contains all migrations (not just the ones that need to be executed).
|
|
14
81
|
* The keys in the object must be the unique migration names.
|
|
15
82
|
*
|
|
83
|
+
* This method returns a {@link MigrationResultSet} instance and _never_ throws.
|
|
84
|
+
* {@link MigrationResultSet.error} holds the error if something went wrong.
|
|
85
|
+
* {@link MigrationResultSet.results} contains information about which migrations
|
|
86
|
+
* were executed and which failed. See the examples below.
|
|
87
|
+
*
|
|
16
88
|
* This method goes through all possible migrations (passed as the argument) and runs the
|
|
17
89
|
* ones whose names are alphabetically after the last migration that has been run. If the
|
|
18
|
-
* list of executed migrations doesn't match the list of possible migrations
|
|
19
|
-
* is thrown.
|
|
90
|
+
* list of executed migrations doesn't match the beginning of the list of possible migrations
|
|
91
|
+
* an error is thrown.
|
|
20
92
|
*
|
|
21
93
|
* ### Examples
|
|
22
94
|
*
|
|
23
95
|
* ```ts
|
|
24
|
-
* await db.migration.migrateToLatest(
|
|
96
|
+
* const { error, results } = await db.migration.migrateToLatest(
|
|
25
97
|
* path.join(__dirname, 'migrations')
|
|
26
98
|
* )
|
|
99
|
+
*
|
|
100
|
+
* results?.forEach((it) => {
|
|
101
|
+
* if (it.status === 'Success') {
|
|
102
|
+
* console.log(`migration "${it.migrationName}" was executed successfully`)
|
|
103
|
+
* } else if (it.status === 'Error') {
|
|
104
|
+
* console.error(`failed to execute migration "${it.migrationName}"`)
|
|
105
|
+
* }
|
|
106
|
+
* })
|
|
107
|
+
*
|
|
108
|
+
* if (error) {
|
|
109
|
+
* console.error('failed to run `migrateToLatest`')
|
|
110
|
+
* console.error(error)
|
|
111
|
+
* }
|
|
27
112
|
* ```
|
|
28
113
|
*
|
|
29
114
|
* In the next example, we use a record of migration objects instead of file folder path.
|
|
30
115
|
* The keys in the object are migration names that can be anything you want. The order of
|
|
31
116
|
* the migrations is determined based on the alphabetical order of the keys in the record.
|
|
32
|
-
* This can be useful if you are using a bundler
|
|
117
|
+
* This version of the `migrateToLatest` method can be useful if you are using a bundler
|
|
118
|
+
* like webpack or esbuild.
|
|
33
119
|
*
|
|
34
120
|
* ```ts
|
|
35
121
|
* await db.migration.migrateToLatest({
|
|
@@ -57,10 +143,67 @@ export declare class MigrationModule {
|
|
|
57
143
|
* })
|
|
58
144
|
* ```
|
|
59
145
|
*/
|
|
60
|
-
migrateToLatest(migrationsFolderPath: string): Promise<
|
|
61
|
-
migrateToLatest(allMigrations: Record<string, Migration>): Promise<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
146
|
+
migrateToLatest(migrationsFolderPath: string): Promise<MigrationResultSet>;
|
|
147
|
+
migrateToLatest(allMigrations: Record<string, Migration>): Promise<MigrationResultSet>;
|
|
148
|
+
/**
|
|
149
|
+
* Migrate up/down to a specific migration.
|
|
150
|
+
*
|
|
151
|
+
* Otherwise works just like {@link migrateToLatest}. The first argument
|
|
152
|
+
* behaves the same, the output is the same etc.
|
|
153
|
+
*
|
|
154
|
+
* ### Examples
|
|
155
|
+
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* await db.migration.migrateTo(
|
|
158
|
+
* path.join(__dirname, 'migrations'),
|
|
159
|
+
* 'some_migration'
|
|
160
|
+
* )
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* If you specify the name of the first migration, this method migrates
|
|
164
|
+
* down to the first migration, but doesn't run the `down` migration for
|
|
165
|
+
* the first migration. In case you want to migrate down ALL migrations
|
|
166
|
+
* you can use a special constant `NO_MIGRATIONS`:
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* await db.migration.migrateTo(
|
|
170
|
+
* path.join(__dirname, 'migrations'),
|
|
171
|
+
* NO_MIGRATIONS,
|
|
172
|
+
* )
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
migrateTo(migrationsFolderPath: string, targetMigrationName: string | NoMigrations): Promise<MigrationResultSet>;
|
|
176
|
+
migrateTo(allMigrations: Record<string, Migration>, targetMigrationName: string | NoMigrations): Promise<MigrationResultSet>;
|
|
177
|
+
/**
|
|
178
|
+
* Migrate one step up.
|
|
179
|
+
*
|
|
180
|
+
* Otherwise works just like {@link migrateToLatest}. The only argument
|
|
181
|
+
* behaves the same, the output is the same etc.
|
|
182
|
+
*
|
|
183
|
+
* ### Examples
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* await db.migration.migrateUp(
|
|
187
|
+
* path.join(__dirname, 'migrations'),
|
|
188
|
+
* )
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
migrateUp(migrationsFolderPath: string): Promise<MigrationResultSet>;
|
|
192
|
+
migrateUp(allMigrations: Record<string, Migration>): Promise<MigrationResultSet>;
|
|
193
|
+
/**
|
|
194
|
+
* Migrate one step down.
|
|
195
|
+
*
|
|
196
|
+
* Otherwise works just like {@link migrateToLatest}. The only argument
|
|
197
|
+
* behaves the same, the output is the same etc.
|
|
198
|
+
*
|
|
199
|
+
* ### Examples
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* await db.migration.migrateDown(
|
|
203
|
+
* path.join(__dirname, 'migrations'),
|
|
204
|
+
* )
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
migrateDown(migrationsFolderPath: string): Promise<MigrationResultSet>;
|
|
208
|
+
migrateDown(allMigrations: Record<string, Migration>): Promise<MigrationResultSet>;
|
|
66
209
|
}
|