kysely 0.11.4 → 0.13.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 +35 -11
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +36 -0
- 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 +16 -0
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +3 -0
- 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 +16 -0
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +3 -0
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +38 -2
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
- 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/dynamic/dynamic-reference-builder.d.ts +1 -0
- package/dist/cjs/dynamic/dynamic-reference-builder.js +9 -1
- package/dist/cjs/dynamic/dynamic.d.ts +6 -7
- package/dist/cjs/dynamic/dynamic.js +6 -7
- package/dist/cjs/index.d.ts +15 -4
- package/dist/cjs/index.js +12 -1
- package/dist/cjs/kysely.d.ts +170 -11
- package/dist/cjs/kysely.js +69 -9
- package/dist/cjs/migration/migration.d.ts +156 -13
- package/dist/cjs/migration/migration.js +256 -135
- package/dist/cjs/operation-node/column-definition-node.d.ts +6 -5
- 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/create-table-node.d.ts +6 -2
- package/dist/cjs/operation-node/create-table-node.js +6 -6
- package/dist/cjs/operation-node/create-view-node.d.ts +1 -0
- package/dist/cjs/operation-node/insert-query-node.d.ts +4 -4
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +4 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +22 -2
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +4 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +2 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/query-node.d.ts +0 -2
- package/dist/cjs/operation-node/query-node.js +0 -10
- package/dist/cjs/operation-node/values-node.d.ts +15 -0
- package/dist/cjs/operation-node/values-node.js +18 -0
- 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/complex-expression-parser.d.ts +9 -0
- package/dist/cjs/parser/complex-expression-parser.js +25 -0
- package/dist/cjs/parser/filter-parser.d.ts +13 -4
- package/dist/cjs/parser/filter-parser.js +21 -24
- package/dist/cjs/parser/insert-values-parser.d.ts +5 -9
- package/dist/cjs/parser/insert-values-parser.js +27 -41
- package/dist/cjs/parser/order-by-parser.d.ts +1 -1
- package/dist/cjs/parser/parse-context.d.ts +22 -8
- package/dist/cjs/parser/parse-context.js +10 -10
- package/dist/cjs/parser/reference-parser.d.ts +8 -7
- package/dist/cjs/parser/reference-parser.js +8 -17
- package/dist/cjs/parser/returning-parser.d.ts +1 -5
- package/dist/cjs/parser/select-parser.d.ts +12 -14
- package/dist/cjs/parser/select-parser.js +5 -9
- package/dist/cjs/parser/table-parser.d.ts +9 -11
- package/dist/cjs/parser/table-parser.js +2 -8
- package/dist/cjs/parser/union-parser.d.ts +2 -2
- package/dist/cjs/parser/union-parser.js +1 -6
- package/dist/cjs/parser/update-set-parser.d.ts +2 -8
- package/dist/cjs/parser/update-set-parser.js +6 -26
- package/dist/cjs/parser/value-parser.d.ts +9 -6
- package/dist/cjs/parser/value-parser.js +7 -30
- package/dist/cjs/parser/with-parser.d.ts +36 -6
- 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/immediate-value.ts/immediate-value-plugin.js +2 -2
- 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 +647 -0
- package/dist/cjs/query-builder/delete-query-builder.js +185 -0
- package/dist/cjs/query-builder/expression-builder.d.ts +8 -6
- package/dist/cjs/query-builder/expression-builder.js +3 -3
- package/dist/cjs/query-builder/function-builder.d.ts +2 -1
- package/dist/cjs/query-builder/function-builder.js +2 -1
- package/dist/cjs/query-builder/having-interface.d.ts +49 -0
- package/dist/cjs/query-builder/having-interface.js +2 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +504 -0
- package/dist/cjs/query-builder/insert-query-builder.js +256 -0
- package/dist/cjs/query-builder/insert-result.d.ts +3 -2
- package/dist/cjs/query-builder/insert-result.js +3 -2
- package/dist/cjs/query-builder/join-builder.d.ts +19 -20
- package/dist/cjs/query-builder/join-builder.js +12 -12
- package/dist/cjs/query-builder/join-interface.d.ts +130 -0
- package/dist/cjs/query-builder/join-interface.js +2 -0
- package/dist/cjs/query-builder/no-result-error.d.ts +9 -0
- package/dist/cjs/query-builder/no-result-error.js +14 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +73 -0
- package/dist/cjs/query-builder/returning-interface.js +2 -0
- package/dist/cjs/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -651
- package/dist/cjs/query-builder/select-query-builder.js +571 -0
- package/dist/cjs/query-builder/update-query-builder.d.ts +735 -0
- package/dist/cjs/query-builder/update-query-builder.js +279 -0
- package/dist/cjs/query-builder/where-interface.d.ts +378 -0
- package/dist/cjs/query-builder/where-interface.js +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +37 -6
- package/dist/cjs/query-creator.d.ts +69 -43
- package/dist/cjs/query-creator.js +66 -29
- 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/query-executor/query-executor.d.ts +1 -1
- package/dist/cjs/query-executor/query-executor.js +1 -1
- package/dist/cjs/raw-builder/raw-builder.d.ts +2 -0
- package/dist/cjs/raw-builder/raw-builder.js +7 -1
- package/dist/cjs/schema/alter-table-builder.d.ts +230 -2
- package/dist/cjs/schema/alter-table-builder.js +12 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +147 -20
- package/dist/cjs/schema/column-definition-builder.js +4 -1
- package/dist/cjs/schema/create-index-builder.d.ts +2 -1
- package/dist/cjs/schema/create-index-builder.js +2 -1
- package/dist/cjs/schema/create-table-builder.d.ts +26 -9
- package/dist/cjs/schema/create-table-builder.js +42 -9
- package/dist/cjs/schema/create-view-builder.d.ts +17 -3
- package/dist/cjs/schema/create-view-builder.js +25 -16
- package/dist/cjs/schema/schema.d.ts +18 -11
- package/dist/cjs/schema/schema.js +18 -11
- package/dist/cjs/util/log.d.ts +3 -2
- package/dist/cjs/util/log.js +8 -15
- package/dist/cjs/util/type-utils.d.ts +7 -7
- package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
- 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 +16 -0
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
- 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 +16 -0
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +3 -0
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +38 -2
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
- 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/dynamic/dynamic-reference-builder.d.ts +1 -0
- package/dist/esm/dynamic/dynamic-reference-builder.js +7 -0
- package/dist/esm/dynamic/dynamic.d.ts +6 -7
- package/dist/esm/dynamic/dynamic.js +6 -7
- package/dist/esm/index.d.ts +15 -4
- package/dist/esm/index.js +12 -1
- package/dist/esm/kysely.d.ts +170 -11
- package/dist/esm/kysely.js +69 -9
- package/dist/esm/migration/migration.d.ts +156 -13
- package/dist/esm/migration/migration.js +255 -134
- package/dist/esm/operation-node/column-definition-node.d.ts +6 -5
- 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/create-table-node.d.ts +6 -2
- package/dist/esm/operation-node/create-table-node.js +6 -6
- package/dist/esm/operation-node/create-view-node.d.ts +1 -0
- package/dist/esm/operation-node/insert-query-node.d.ts +4 -4
- package/dist/esm/operation-node/operation-node-transformer.d.ts +4 -0
- package/dist/esm/operation-node/operation-node-transformer.js +22 -2
- package/dist/esm/operation-node/operation-node-visitor.d.ts +4 -0
- package/dist/esm/operation-node/operation-node-visitor.js +2 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/query-node.d.ts +0 -2
- package/dist/esm/operation-node/query-node.js +0 -10
- package/dist/esm/operation-node/values-node.d.ts +15 -0
- package/dist/esm/operation-node/values-node.js +15 -0
- 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/complex-expression-parser.d.ts +9 -0
- package/dist/esm/parser/complex-expression-parser.js +20 -0
- package/dist/esm/parser/filter-parser.d.ts +13 -4
- package/dist/esm/parser/filter-parser.js +21 -24
- package/dist/esm/parser/insert-values-parser.d.ts +5 -9
- package/dist/esm/parser/insert-values-parser.js +27 -40
- package/dist/esm/parser/order-by-parser.d.ts +1 -1
- package/dist/esm/parser/parse-context.d.ts +22 -8
- package/dist/esm/parser/parse-context.js +10 -10
- package/dist/esm/parser/reference-parser.d.ts +8 -7
- package/dist/esm/parser/reference-parser.js +9 -18
- package/dist/esm/parser/returning-parser.d.ts +1 -5
- package/dist/esm/parser/select-parser.d.ts +12 -14
- package/dist/esm/parser/select-parser.js +6 -10
- package/dist/esm/parser/table-parser.d.ts +9 -11
- package/dist/esm/parser/table-parser.js +3 -9
- package/dist/esm/parser/union-parser.d.ts +2 -2
- package/dist/esm/parser/union-parser.js +1 -6
- package/dist/esm/parser/update-set-parser.d.ts +2 -8
- package/dist/esm/parser/update-set-parser.js +5 -24
- package/dist/esm/parser/value-parser.d.ts +9 -6
- package/dist/esm/parser/value-parser.js +8 -31
- package/dist/esm/parser/with-parser.d.ts +36 -6
- 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/immediate-value.ts/immediate-value-plugin.js +2 -2
- 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 +647 -0
- package/dist/esm/query-builder/delete-query-builder.js +181 -0
- package/dist/esm/query-builder/expression-builder.d.ts +8 -6
- package/dist/esm/query-builder/expression-builder.js +3 -3
- package/dist/esm/query-builder/function-builder.d.ts +2 -1
- package/dist/esm/query-builder/function-builder.js +2 -1
- package/dist/esm/query-builder/having-interface.d.ts +49 -0
- package/dist/esm/query-builder/having-interface.js +1 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +504 -0
- package/dist/esm/query-builder/insert-query-builder.js +252 -0
- package/dist/esm/query-builder/insert-result.d.ts +3 -2
- package/dist/esm/query-builder/insert-result.js +3 -2
- package/dist/esm/query-builder/join-builder.d.ts +19 -20
- package/dist/esm/query-builder/join-builder.js +12 -12
- package/dist/esm/query-builder/join-interface.d.ts +130 -0
- package/dist/esm/query-builder/join-interface.js +1 -0
- package/dist/esm/query-builder/no-result-error.d.ts +9 -0
- package/dist/esm/query-builder/no-result-error.js +10 -0
- package/dist/esm/query-builder/returning-interface.d.ts +73 -0
- package/dist/esm/query-builder/returning-interface.js +1 -0
- package/dist/esm/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -651
- package/dist/esm/query-builder/select-query-builder.js +566 -0
- package/dist/esm/query-builder/update-query-builder.d.ts +735 -0
- package/dist/esm/query-builder/update-query-builder.js +275 -0
- package/dist/esm/query-builder/where-interface.d.ts +378 -0
- package/dist/esm/query-builder/where-interface.js +1 -0
- package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -0
- package/dist/esm/query-compiler/default-query-compiler.js +37 -6
- package/dist/esm/query-creator.d.ts +69 -43
- package/dist/esm/query-creator.js +66 -29
- 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/query-executor/query-executor.d.ts +1 -1
- package/dist/esm/query-executor/query-executor.js +1 -1
- package/dist/esm/raw-builder/raw-builder.d.ts +2 -0
- package/dist/esm/raw-builder/raw-builder.js +7 -1
- package/dist/esm/schema/alter-table-builder.d.ts +230 -2
- package/dist/esm/schema/alter-table-builder.js +12 -0
- package/dist/esm/schema/column-definition-builder.d.ts +147 -20
- package/dist/esm/schema/column-definition-builder.js +4 -1
- package/dist/esm/schema/create-index-builder.d.ts +2 -1
- package/dist/esm/schema/create-index-builder.js +2 -1
- package/dist/esm/schema/create-table-builder.d.ts +26 -9
- package/dist/esm/schema/create-table-builder.js +43 -10
- package/dist/esm/schema/create-view-builder.d.ts +17 -3
- package/dist/esm/schema/create-view-builder.js +25 -16
- package/dist/esm/schema/schema.d.ts +18 -11
- package/dist/esm/schema/schema.js +18 -11
- package/dist/esm/util/log.d.ts +3 -2
- package/dist/esm/util/log.js +7 -14
- package/dist/esm/util/type-utils.d.ts +7 -7
- package/package.json +10 -8
- package/dist/cjs/query-builder/query-builder.js +0 -1067
- package/dist/esm/query-builder/query-builder.js +0 -1061
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ interface Person {
|
|
|
72
72
|
first_name: string
|
|
73
73
|
// If the column is nullable in the db, make its type nullable.
|
|
74
74
|
// Don't use optional properties.
|
|
75
|
-
last_name: string |
|
|
75
|
+
last_name: string | null
|
|
76
76
|
gender: 'male' | 'female' | 'other'
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -252,32 +252,56 @@ await db.migration.migrateToLatest(pathToMigrationsFolder)
|
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
to run all migrations that have not yet been run. The migrations are executed in alphabetical
|
|
255
|
-
order by their
|
|
255
|
+
order by their name. See the [migration module](https://koskimas.github.io/kysely/classes/MigrationModule.html)
|
|
256
|
+
documentation for more info.
|
|
256
257
|
|
|
257
258
|
Kysely doesn't have a CLI for running migrations and probably never will. This is because Kysely's
|
|
258
259
|
migrations are also written in typescript. To run the migrations, you need to first build the
|
|
259
260
|
typescript code into javascript. The CLI would cause confusion over which migrations are being
|
|
260
|
-
run, the typescript ones or the javascript ones. If we added support for both,
|
|
261
|
-
|
|
261
|
+
run, the typescript ones or the javascript ones. If we added support for both, the CLI would
|
|
262
|
+
need to depend on a typescript compiler, which most production environments don't (and shouldn't)
|
|
262
263
|
have. You will probably want to add a simple migration script to your projects like this:
|
|
263
264
|
|
|
264
265
|
```ts
|
|
265
266
|
import path from 'path'
|
|
267
|
+
|
|
268
|
+
// This example assumes you have a file named `database.ts` that
|
|
269
|
+
// creates and exports a `Kysely` instance `db`. You can just
|
|
270
|
+
// as well create a new `Kysely` instance in the function below
|
|
271
|
+
// or do something completely different to obtain an instance
|
|
272
|
+
// of `Kysely`.
|
|
266
273
|
import { db } from './database'
|
|
267
274
|
|
|
268
|
-
|
|
269
|
-
.migrateToLatest(
|
|
270
|
-
|
|
275
|
+
async function migrateToLatest() {
|
|
276
|
+
const { error, results } = await db.migration.migrateToLatest(
|
|
277
|
+
path.join(__dirname, 'migrations')
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
// Destroy the `Kysely` instance to make the script exit faster.
|
|
281
|
+
await db.destroy()
|
|
282
|
+
|
|
283
|
+
results?.forEach((it) => {
|
|
284
|
+
if (it.status === 'Success') {
|
|
285
|
+
console.log(`migration "${it.migrationName}" was executed successfully`)
|
|
286
|
+
} else if (it.status === 'Error') {
|
|
287
|
+
console.error(`failed to execute migration "${it.migrationName}"`)
|
|
288
|
+
}
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
if (error) {
|
|
292
|
+
console.error('failed to migrate')
|
|
293
|
+
console.error(error)
|
|
294
|
+
process.exit(1)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
migrateToLatest()
|
|
271
299
|
```
|
|
272
300
|
|
|
273
301
|
The migration methods use a lock on the database level, and parallel calls are executed serially.
|
|
274
302
|
This means that you can safely call `migrateToLatest` and other migration methods from multiple
|
|
275
303
|
server instances simultaneously and the migrations are guaranteed to only be executed once.
|
|
276
304
|
|
|
277
|
-
NOTE: Only `db.migration.migrateToLatest` method is implemented at the moment. There is no way
|
|
278
|
-
to run the down migrations, or to go forward to a specific migration. These methods will be
|
|
279
|
-
added soon.
|
|
280
|
-
|
|
281
305
|
# Why not just contribute to knex
|
|
282
306
|
|
|
283
307
|
Kysely is very similar to knex, but it also attempts to fix things that I personally find not-so-good
|
|
@@ -7,8 +7,44 @@ import { DialectAdapter } from './dialect-adapter.js';
|
|
|
7
7
|
* they are added and there will be less breaking changes.
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not this dialect supports transactional DDL.
|
|
12
|
+
*
|
|
13
|
+
* If this is true, migrations are executed inside a transaction.
|
|
14
|
+
*/
|
|
10
15
|
get supportsTransactionalDdl(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not this dialect supports the `returning` in inserts
|
|
18
|
+
* updates and deletes.
|
|
19
|
+
*/
|
|
11
20
|
get supportsReturning(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* This method is used to acquire a lock for the migrations so that
|
|
23
|
+
* it's not possible for two migration processes to run in parallel.
|
|
24
|
+
*
|
|
25
|
+
* Most dialects have explicit locks that can be used, like advisory locks
|
|
26
|
+
* in PostgreSQL and the get_lock function in MySQL.
|
|
27
|
+
*
|
|
28
|
+
* If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
|
|
29
|
+
* created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
|
|
30
|
+
* has two columns `id` and `is_locked` and there's only one row in the
|
|
31
|
+
* table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
|
|
32
|
+
* Kysely takes care of creating the lock table and inserting the one single
|
|
33
|
+
* row to it before this method is executed.
|
|
34
|
+
*
|
|
35
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
36
|
+
* is a transaction inside which the migrations will be executed. Otherwise
|
|
37
|
+
* `db` is a single connection (session) that will be used to execute the
|
|
38
|
+
* migrations.
|
|
39
|
+
*/
|
|
12
40
|
abstract acquireMigrationLock(db: Kysely<any>): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
43
|
+
*
|
|
44
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
45
|
+
* is a transaction inside which the migrations were executed. Otherwise `db`
|
|
46
|
+
* is a single connection (session) that was used to execute the migrations
|
|
47
|
+
* and the `acquireMigrationLock` call.
|
|
48
|
+
*/
|
|
13
49
|
abstract releaseMigrationLock(db: Kysely<any>): Promise<void>;
|
|
14
50
|
}
|
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { Kysely } from '../../kysely.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare class MysqlAdapter
|
|
2
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
3
|
+
export declare class MysqlAdapter extends DialectAdapterBase {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not this dialect supports transactional DDL.
|
|
6
|
+
*
|
|
7
|
+
* If this is true, migrations are executed inside a transaction.
|
|
8
|
+
*/
|
|
4
9
|
get supportsTransactionalDdl(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not this dialect supports the `returning` in inserts
|
|
12
|
+
* updates and deletes.
|
|
13
|
+
*/
|
|
5
14
|
get supportsReturning(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* This method is used to acquire a lock for the migrations so that
|
|
17
|
+
* it's not possible for two migration processes to run in parallel.
|
|
18
|
+
*
|
|
19
|
+
* Most dialects have explicit locks that can be used, like advisory locks
|
|
20
|
+
* in PostgreSQL and the get_lock function in MySQL.
|
|
21
|
+
*
|
|
22
|
+
* If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
|
|
23
|
+
* created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
|
|
24
|
+
* has two columns `id` and `is_locked` and there's only one row in the
|
|
25
|
+
* table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
|
|
26
|
+
* Kysely takes care of creating the lock table and inserting the one single
|
|
27
|
+
* row to it before this method is executed.
|
|
28
|
+
*
|
|
29
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
30
|
+
* is a transaction inside which the migrations will be executed. Otherwise
|
|
31
|
+
* `db` is a single connection (session) that will be used to execute the
|
|
32
|
+
* migrations.
|
|
33
|
+
*/
|
|
6
34
|
acquireMigrationLock(db: Kysely<any>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
37
|
+
*
|
|
38
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
39
|
+
* is a transaction inside which the migrations were executed. Otherwise `db`
|
|
40
|
+
* is a single connection (session) that was used to execute the migrations
|
|
41
|
+
* and the `acquireMigrationLock` call.
|
|
42
|
+
*/
|
|
7
43
|
releaseMigrationLock(db: Kysely<any>): Promise<void>;
|
|
8
44
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlAdapter = void 0;
|
|
4
|
+
const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
|
|
4
5
|
const LOCK_ID = 'ea586330-2c93-47c8-908d-981d9d270f9d';
|
|
5
6
|
const LOCK_TIMEOUT_SECONDS = 60 * 60;
|
|
6
|
-
class MysqlAdapter {
|
|
7
|
+
class MysqlAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
|
|
7
8
|
get supportsTransactionalDdl() {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
@@ -15,9 +15,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
|
15
15
|
export declare class MysqlDialect implements Dialect {
|
|
16
16
|
#private;
|
|
17
17
|
constructor(config: MysqlDialectConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a driver for the dialect.
|
|
20
|
+
*/
|
|
18
21
|
createDriver(): Driver;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a query compiler for the dialect.
|
|
24
|
+
*/
|
|
19
25
|
createQueryCompiler(): QueryCompiler;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an adapter for the dialect.
|
|
28
|
+
*/
|
|
20
29
|
createAdapter(): DialectAdapter;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a database introspector that can be used to get the database metadata
|
|
32
|
+
* such as the tables and columns that exist in the database.
|
|
33
|
+
*
|
|
34
|
+
* `db` never has any plugins installed. It's created using
|
|
35
|
+
* {@link Kysely.withoutPlugins}.
|
|
36
|
+
*/
|
|
21
37
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
@@ -4,11 +4,40 @@ import { MysqlDialectConfig } from './mysql-dialect.js';
|
|
|
4
4
|
export declare class MysqlDriver implements Driver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: MysqlDialectConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the driver.
|
|
9
|
+
*
|
|
10
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
11
|
+
* methods should be callable.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
14
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
15
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
16
|
+
* it supports.
|
|
17
|
+
*/
|
|
7
18
|
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Acquires a new connection from the pool.
|
|
21
|
+
*/
|
|
8
22
|
acquireConnection(): Promise<DatabaseConnection>;
|
|
23
|
+
/**
|
|
24
|
+
* Begins a transaction.
|
|
25
|
+
*/
|
|
9
26
|
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Commits a transaction.
|
|
29
|
+
*/
|
|
10
30
|
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Rolls back a transaction.
|
|
33
|
+
*/
|
|
11
34
|
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Releases a connection back to the pool.
|
|
37
|
+
*/
|
|
12
38
|
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Destroys the driver and releases all resources.
|
|
41
|
+
*/
|
|
13
42
|
destroy(): Promise<void>;
|
|
14
43
|
}
|
|
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
|
|
|
3
3
|
export declare class MysqlIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(db: Kysely<any>);
|
|
6
|
+
/**
|
|
7
|
+
* Get the database metadata such as the names of the tables and columns.
|
|
8
|
+
*/
|
|
6
9
|
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
|
|
7
10
|
}
|
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { Kysely } from '../../kysely.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare class PostgresAdapter
|
|
2
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
3
|
+
export declare class PostgresAdapter extends DialectAdapterBase {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not this dialect supports transactional DDL.
|
|
6
|
+
*
|
|
7
|
+
* If this is true, migrations are executed inside a transaction.
|
|
8
|
+
*/
|
|
4
9
|
get supportsTransactionalDdl(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not this dialect supports the `returning` in inserts
|
|
12
|
+
* updates and deletes.
|
|
13
|
+
*/
|
|
5
14
|
get supportsReturning(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* This method is used to acquire a lock for the migrations so that
|
|
17
|
+
* it's not possible for two migration processes to run in parallel.
|
|
18
|
+
*
|
|
19
|
+
* Most dialects have explicit locks that can be used, like advisory locks
|
|
20
|
+
* in PostgreSQL and the get_lock function in MySQL.
|
|
21
|
+
*
|
|
22
|
+
* If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
|
|
23
|
+
* created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
|
|
24
|
+
* has two columns `id` and `is_locked` and there's only one row in the
|
|
25
|
+
* table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
|
|
26
|
+
* Kysely takes care of creating the lock table and inserting the one single
|
|
27
|
+
* row to it before this method is executed.
|
|
28
|
+
*
|
|
29
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
30
|
+
* is a transaction inside which the migrations will be executed. Otherwise
|
|
31
|
+
* `db` is a single connection (session) that will be used to execute the
|
|
32
|
+
* migrations.
|
|
33
|
+
*/
|
|
6
34
|
acquireMigrationLock(db: Kysely<any>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
37
|
+
*
|
|
38
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
39
|
+
* is a transaction inside which the migrations were executed. Otherwise `db`
|
|
40
|
+
* is a single connection (session) that was used to execute the migrations
|
|
41
|
+
* and the `acquireMigrationLock` call.
|
|
42
|
+
*/
|
|
7
43
|
releaseMigrationLock(): Promise<void>;
|
|
8
44
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PostgresAdapter = void 0;
|
|
4
|
+
const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
|
|
4
5
|
// Random id for our transaction lock.
|
|
5
6
|
const LOCK_ID = '3853314791062309107';
|
|
6
|
-
class PostgresAdapter {
|
|
7
|
+
class PostgresAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
|
|
7
8
|
get supportsTransactionalDdl() {
|
|
8
9
|
return true;
|
|
9
10
|
}
|
|
@@ -21,9 +21,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
|
21
21
|
export declare class PostgresDialect implements Dialect {
|
|
22
22
|
#private;
|
|
23
23
|
constructor(config: PostgresDialectConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a driver for the dialect.
|
|
26
|
+
*/
|
|
24
27
|
createDriver(): Driver;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a query compiler for the dialect.
|
|
30
|
+
*/
|
|
25
31
|
createQueryCompiler(): QueryCompiler;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an adapter for the dialect.
|
|
34
|
+
*/
|
|
26
35
|
createAdapter(): DialectAdapter;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a database introspector that can be used to get the database metadata
|
|
38
|
+
* such as the tables and columns that exist in the database.
|
|
39
|
+
*
|
|
40
|
+
* `db` never has any plugins installed. It's created using
|
|
41
|
+
* {@link Kysely.withoutPlugins}.
|
|
42
|
+
*/
|
|
27
43
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
28
44
|
}
|
|
29
45
|
/**
|
|
@@ -4,11 +4,40 @@ import { PostgresDialectConfig } from './postgres-dialect.js';
|
|
|
4
4
|
export declare class PostgresDriver implements Driver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: PostgresDialectConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the driver.
|
|
9
|
+
*
|
|
10
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
11
|
+
* methods should be callable.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
14
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
15
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
16
|
+
* it supports.
|
|
17
|
+
*/
|
|
7
18
|
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Acquires a new connection from the pool.
|
|
21
|
+
*/
|
|
8
22
|
acquireConnection(): Promise<DatabaseConnection>;
|
|
23
|
+
/**
|
|
24
|
+
* Begins a transaction.
|
|
25
|
+
*/
|
|
9
26
|
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Commits a transaction.
|
|
29
|
+
*/
|
|
10
30
|
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Rolls back a transaction.
|
|
33
|
+
*/
|
|
11
34
|
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Releases a connection back to the pool.
|
|
37
|
+
*/
|
|
12
38
|
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Destroys the driver and releases all resources.
|
|
41
|
+
*/
|
|
13
42
|
destroy(): Promise<void>;
|
|
14
43
|
}
|
|
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
|
|
|
3
3
|
export declare class PostgresIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(db: Kysely<any>);
|
|
6
|
+
/**
|
|
7
|
+
* Get the database metadata such as the names of the tables and columns.
|
|
8
|
+
*/
|
|
6
9
|
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
|
|
7
10
|
}
|
|
@@ -1,7 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class SqliteAdapter implements
|
|
1
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
2
|
+
export declare class SqliteAdapter implements DialectAdapterBase {
|
|
3
|
+
/**
|
|
4
|
+
* Whether or not this dialect supports transactional DDL.
|
|
5
|
+
*
|
|
6
|
+
* If this is true, migrations are executed inside a transaction.
|
|
7
|
+
*/
|
|
3
8
|
get supportsTransactionalDdl(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether or not this dialect supports the `returning` in inserts
|
|
11
|
+
* updates and deletes.
|
|
12
|
+
*/
|
|
4
13
|
get supportsReturning(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* This method is used to acquire a lock for the migrations so that
|
|
16
|
+
* it's not possible for two migration processes to run in parallel.
|
|
17
|
+
*
|
|
18
|
+
* Most dialects have explicit locks that can be used, like advisory locks
|
|
19
|
+
* in PostgreSQL and the get_lock function in MySQL.
|
|
20
|
+
*
|
|
21
|
+
* If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
|
|
22
|
+
* created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
|
|
23
|
+
* has two columns `id` and `is_locked` and there's only one row in the
|
|
24
|
+
* table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
|
|
25
|
+
* Kysely takes care of creating the lock table and inserting the one single
|
|
26
|
+
* row to it before this method is executed.
|
|
27
|
+
*
|
|
28
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
29
|
+
* is a transaction inside which the migrations will be executed. Otherwise
|
|
30
|
+
* `db` is a single connection (session) that will be used to execute the
|
|
31
|
+
* migrations.
|
|
32
|
+
*/
|
|
5
33
|
acquireMigrationLock(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
36
|
+
*
|
|
37
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
38
|
+
* is a transaction inside which the migrations were executed. Otherwise `db`
|
|
39
|
+
* is a single connection (session) that was used to execute the migrations
|
|
40
|
+
* and the `acquireMigrationLock` call.
|
|
41
|
+
*/
|
|
6
42
|
releaseMigrationLock(): Promise<void>;
|
|
7
43
|
}
|
|
@@ -15,9 +15,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
|
15
15
|
export declare class SqliteDialect implements Dialect {
|
|
16
16
|
#private;
|
|
17
17
|
constructor(config: SqliteDialectConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a driver for the dialect.
|
|
20
|
+
*/
|
|
18
21
|
createDriver(): Driver;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a query compiler for the dialect.
|
|
24
|
+
*/
|
|
19
25
|
createQueryCompiler(): QueryCompiler;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an adapter for the dialect.
|
|
28
|
+
*/
|
|
20
29
|
createAdapter(): DialectAdapter;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a database introspector that can be used to get the database metadata
|
|
32
|
+
* such as the tables and columns that exist in the database.
|
|
33
|
+
*
|
|
34
|
+
* `db` never has any plugins installed. It's created using
|
|
35
|
+
* {@link Kysely.withoutPlugins}.
|
|
36
|
+
*/
|
|
21
37
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
@@ -4,11 +4,40 @@ import { SqliteDialectConfig } from './sqlite-dialect.js';
|
|
|
4
4
|
export declare class SqliteDriver implements Driver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: SqliteDialectConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the driver.
|
|
9
|
+
*
|
|
10
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
11
|
+
* methods should be callable.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
14
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
15
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
16
|
+
* it supports.
|
|
17
|
+
*/
|
|
7
18
|
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Acquires a new connection from the pool.
|
|
21
|
+
*/
|
|
8
22
|
acquireConnection(): Promise<DatabaseConnection>;
|
|
23
|
+
/**
|
|
24
|
+
* Begins a transaction.
|
|
25
|
+
*/
|
|
9
26
|
beginTransaction(connection: DatabaseConnection): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Commits a transaction.
|
|
29
|
+
*/
|
|
10
30
|
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Rolls back a transaction.
|
|
33
|
+
*/
|
|
11
34
|
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Releases a connection back to the pool.
|
|
37
|
+
*/
|
|
12
38
|
releaseConnection(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Destroys the driver and releases all resources.
|
|
41
|
+
*/
|
|
13
42
|
destroy(): Promise<void>;
|
|
14
43
|
}
|
|
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
|
|
|
3
3
|
export declare class SqliteIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(db: Kysely<any>);
|
|
6
|
+
/**
|
|
7
|
+
* Get the database metadata such as the names of the tables and columns.
|
|
8
|
+
*/
|
|
6
9
|
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
|
|
7
10
|
}
|
|
@@ -4,5 +4,9 @@ import { Driver } from './driver.js';
|
|
|
4
4
|
export declare class DefaultConnectionProvider implements ConnectionProvider {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(driver: Driver);
|
|
7
|
+
/**
|
|
8
|
+
* Provides a connection for the callback and takes care of disposing
|
|
9
|
+
* the connection after the callback has been run.
|
|
10
|
+
*/
|
|
7
11
|
withConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
8
12
|
}
|
|
@@ -9,11 +9,40 @@ import { Driver, TransactionSettings } from './driver.js';
|
|
|
9
9
|
export declare class RuntimeDriver implements Driver {
|
|
10
10
|
#private;
|
|
11
11
|
constructor(driver: Driver, log: Log);
|
|
12
|
+
/**
|
|
13
|
+
* Initializes the driver.
|
|
14
|
+
*
|
|
15
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
16
|
+
* methods should be callable.
|
|
17
|
+
*
|
|
18
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
19
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
20
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
21
|
+
* it supports.
|
|
22
|
+
*/
|
|
12
23
|
init(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Acquires a new connection from the pool.
|
|
26
|
+
*/
|
|
13
27
|
acquireConnection(): Promise<DatabaseConnection>;
|
|
28
|
+
/**
|
|
29
|
+
* Releases a connection back to the pool.
|
|
30
|
+
*/
|
|
14
31
|
releaseConnection(runtimeConnection: DatabaseConnection): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Begins a transaction.
|
|
34
|
+
*/
|
|
15
35
|
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Commits a transaction.
|
|
38
|
+
*/
|
|
16
39
|
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Rolls back a transaction.
|
|
42
|
+
*/
|
|
17
43
|
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Destroys the driver and releases all resources.
|
|
46
|
+
*/
|
|
18
47
|
destroy(): Promise<void>;
|
|
19
48
|
}
|
|
@@ -3,5 +3,9 @@ import { ConnectionProvider } from './connection-provider.js';
|
|
|
3
3
|
export declare class SingleConnectionProvider implements ConnectionProvider {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(connection: DatabaseConnection);
|
|
6
|
+
/**
|
|
7
|
+
* Provides a connection for the callback and takes care of disposing
|
|
8
|
+
* the connection after the callback has been run.
|
|
9
|
+
*/
|
|
6
10
|
withConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
7
11
|
}
|
|
@@ -16,3 +16,4 @@ export declare class DynamicReferenceBuilder<R extends string = never> implement
|
|
|
16
16
|
constructor(reference: string);
|
|
17
17
|
toOperationNode(): ReferenceNode | ColumnNode;
|
|
18
18
|
}
|
|
19
|
+
export declare function isDynamicReferenceBuilder(obj: unknown): obj is DynamicReferenceBuilder<any>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamicReferenceBuilder = void 0;
|
|
3
|
+
exports.isDynamicReferenceBuilder = exports.DynamicReferenceBuilder = void 0;
|
|
4
|
+
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
4
5
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
6
|
+
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
7
|
class DynamicReferenceBuilder {
|
|
6
8
|
#dynamicReference;
|
|
7
9
|
get dynamicReference() {
|
|
@@ -26,3 +28,9 @@ class DynamicReferenceBuilder {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
exports.DynamicReferenceBuilder = DynamicReferenceBuilder;
|
|
31
|
+
function isDynamicReferenceBuilder(obj) {
|
|
32
|
+
return ((0, object_utils_js_1.isObject)(obj) &&
|
|
33
|
+
(0, operation_node_source_js_1.isOperationNodeSource)(obj) &&
|
|
34
|
+
(0, object_utils_js_1.isString)(obj.dynamicReference));
|
|
35
|
+
}
|
|
36
|
+
exports.isDynamicReferenceBuilder = isDynamicReferenceBuilder;
|
|
@@ -20,7 +20,8 @@ export declare class DynamicModule {
|
|
|
20
20
|
* `ref` to other methods as well. If the types allow you to pass a `ref`
|
|
21
21
|
* value to some place, it should work.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* ### Examples
|
|
24
|
+
*
|
|
24
25
|
* Filter by a column not know at compile time:
|
|
25
26
|
*
|
|
26
27
|
* ```ts
|
|
@@ -38,7 +39,6 @@ export declare class DynamicModule {
|
|
|
38
39
|
* someQuery('person.last_name', 'Aniston')
|
|
39
40
|
* ```
|
|
40
41
|
*
|
|
41
|
-
* @example
|
|
42
42
|
* Order by a column not know at compile time:
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
@@ -55,7 +55,6 @@ export declare class DynamicModule {
|
|
|
55
55
|
* someQuery('fn')
|
|
56
56
|
* ```
|
|
57
57
|
*
|
|
58
|
-
* @example
|
|
59
58
|
* In this example we add selections dynamically:
|
|
60
59
|
*
|
|
61
60
|
* ```ts
|
|
@@ -66,7 +65,7 @@ export declare class DynamicModule {
|
|
|
66
65
|
*
|
|
67
66
|
* // A type that lists all possible values `columnFromUserInput` can have.
|
|
68
67
|
* // You can use `keyof Person` if any column of an interface is allowed.
|
|
69
|
-
* type PossibleColumns = 'last_name' |
|
|
68
|
+
* type PossibleColumns = 'last_name' | 'first_name' | 'birth_date'
|
|
70
69
|
*
|
|
71
70
|
* const [person] = await db.selectFrom('person')
|
|
72
71
|
* .select([
|
|
@@ -78,9 +77,9 @@ export declare class DynamicModule {
|
|
|
78
77
|
* // The resulting type contains all `PossibleColumns` as optional fields
|
|
79
78
|
* // because we cannot know which field was actually selected before
|
|
80
79
|
* // running the code.
|
|
81
|
-
* const lastName: string |
|
|
82
|
-
* const firstName: string |
|
|
83
|
-
* const birthDate: string |
|
|
80
|
+
* const lastName: string | undefined = person.last_name
|
|
81
|
+
* const firstName: string | undefined = person.first_name
|
|
82
|
+
* const birthDate: string | undefined = person.birth_date
|
|
84
83
|
*
|
|
85
84
|
* // The result type also contains the compile time selection `id`.
|
|
86
85
|
* person.id
|