kysely 0.12.1 → 0.14.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 +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.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +2 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/index.d.ts +5 -3
- package/dist/cjs/index.js +4 -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/parser/reference-parser.d.ts +2 -2
- package/dist/cjs/parser/select-parser.d.ts +2 -2
- 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 +2 -2
- package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +76 -75
- package/dist/cjs/query-builder/insert-query-builder.js +150 -15
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-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 +41 -9
- package/dist/cjs/schema/alter-table-builder.js +45 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +40 -8
- 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/cjs/util/type-utils.d.ts +11 -7
- package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +2 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.js +2 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +2 -2
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +4 -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/parser/reference-parser.d.ts +2 -2
- package/dist/esm/parser/select-parser.d.ts +2 -2
- 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 +2 -2
- package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +76 -75
- package/dist/esm/query-builder/insert-query-builder.js +150 -15
- package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-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 +41 -9
- package/dist/esm/schema/alter-table-builder.js +45 -9
- package/dist/esm/schema/column-definition-builder.d.ts +40 -8
- 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/dist/esm/util/type-utils.d.ts +11 -7
- package/package.json +2 -2
- 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/README.md
CHANGED
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Driver } from '../driver/driver.js';
|
|
2
2
|
import { Kysely } from '../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../query-compiler/query-compiler.js';
|
|
4
|
-
import { DatabaseIntrospector } from '
|
|
4
|
+
import { DatabaseIntrospector } from './database-introspector.js';
|
|
5
5
|
import { DialectAdapter } from './dialect-adapter.js';
|
|
6
6
|
/**
|
|
7
7
|
* A Dialect is the glue between Kysely and the underlying database engine.
|
|
@@ -1,6 +1,6 @@
|
|
|
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
4
|
/**
|
|
5
5
|
* Whether or not this dialect supports transactional DDL.
|
|
6
6
|
*
|
|
@@ -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
|
}
|
|
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
4
4
|
import { Dialect } from '../dialect.js';
|
|
5
|
-
import { DatabaseIntrospector } from '
|
|
5
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
7
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class MysqlIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
@@ -1,6 +1,6 @@
|
|
|
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
4
|
/**
|
|
5
5
|
* Whether or not this dialect supports transactional DDL.
|
|
6
6
|
*
|
|
@@ -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
|
}
|
|
@@ -5,7 +5,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
5
5
|
import { Kysely } from '../../kysely.js';
|
|
6
6
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
7
7
|
import { Dialect } from '../dialect.js';
|
|
8
|
-
import { DatabaseIntrospector } from '
|
|
8
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
9
9
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
10
10
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
11
11
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class PostgresIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class SqliteAdapter implements
|
|
1
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
2
|
+
export declare class SqliteAdapter implements DialectAdapterBase {
|
|
3
3
|
/**
|
|
4
4
|
* Whether or not this dialect supports transactional DDL.
|
|
5
5
|
*
|
|
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
4
4
|
import { Dialect } from '../dialect.js';
|
|
5
|
-
import { DatabaseIntrospector } from '
|
|
5
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
7
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class SqliteIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './query-builder/function-builder.js';
|
|
|
15
15
|
export * from './query-builder/insert-result.js';
|
|
16
16
|
export * from './query-builder/delete-result.js';
|
|
17
17
|
export * from './query-builder/update-result.js';
|
|
18
|
+
export * from './query-builder/on-conflict-builder.js';
|
|
18
19
|
export * from './raw-builder/raw-builder.js';
|
|
19
20
|
export * from './query-executor/query-executor.js';
|
|
20
21
|
export * from './query-executor/default-query-executor.js';
|
|
@@ -73,6 +74,7 @@ export * from './operation-node/column-definition-node.js';
|
|
|
73
74
|
export * from './operation-node/column-node.js';
|
|
74
75
|
export * from './operation-node/column-update-node.js';
|
|
75
76
|
export * from './operation-node/common-table-expression-node.js';
|
|
77
|
+
export * from './operation-node/common-table-expression-name-node.js';
|
|
76
78
|
export * from './operation-node/constraint-node.js';
|
|
77
79
|
export * from './operation-node/create-index-node.js';
|
|
78
80
|
export * from './operation-node/create-schema-node.js';
|
|
@@ -90,7 +92,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
90
92
|
export * from './operation-node/filter-node.js';
|
|
91
93
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
92
94
|
export * from './operation-node/from-node.js';
|
|
93
|
-
export * from './operation-node/generated-
|
|
95
|
+
export * from './operation-node/generated-node.js';
|
|
94
96
|
export * from './operation-node/group-by-item-node.js';
|
|
95
97
|
export * from './operation-node/group-by-node.js';
|
|
96
98
|
export * from './operation-node/having-node.js';
|
|
@@ -135,11 +137,11 @@ export * from './operation-node/value-node.js';
|
|
|
135
137
|
export * from './operation-node/values-node.js';
|
|
136
138
|
export * from './operation-node/where-node.js';
|
|
137
139
|
export * from './operation-node/with-node.js';
|
|
138
|
-
export * from './
|
|
140
|
+
export * from './dialect/database-introspector.js';
|
|
139
141
|
export * from './util/compilable.js';
|
|
140
142
|
export * from './util/log.js';
|
|
141
143
|
export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
|
|
142
|
-
export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
|
|
144
|
+
export { SelectExpression, SelectExpressionOrList, Selection, } from './parser/select-parser.js';
|
|
143
145
|
export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
|
|
144
146
|
export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
145
147
|
export { FilterValueExpression, FilterValueExpressionOrList, ExistsExpression, FilterOperator, } from './parser/filter-parser.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./query-builder/function-builder.js"), exports);
|
|
|
27
27
|
__exportStar(require("./query-builder/insert-result.js"), exports);
|
|
28
28
|
__exportStar(require("./query-builder/delete-result.js"), exports);
|
|
29
29
|
__exportStar(require("./query-builder/update-result.js"), exports);
|
|
30
|
+
__exportStar(require("./query-builder/on-conflict-builder.js"), exports);
|
|
30
31
|
__exportStar(require("./raw-builder/raw-builder.js"), exports);
|
|
31
32
|
__exportStar(require("./query-executor/query-executor.js"), exports);
|
|
32
33
|
__exportStar(require("./query-executor/default-query-executor.js"), exports);
|
|
@@ -85,6 +86,7 @@ __exportStar(require("./operation-node/column-definition-node.js"), exports);
|
|
|
85
86
|
__exportStar(require("./operation-node/column-node.js"), exports);
|
|
86
87
|
__exportStar(require("./operation-node/column-update-node.js"), exports);
|
|
87
88
|
__exportStar(require("./operation-node/common-table-expression-node.js"), exports);
|
|
89
|
+
__exportStar(require("./operation-node/common-table-expression-name-node.js"), exports);
|
|
88
90
|
__exportStar(require("./operation-node/constraint-node.js"), exports);
|
|
89
91
|
__exportStar(require("./operation-node/create-index-node.js"), exports);
|
|
90
92
|
__exportStar(require("./operation-node/create-schema-node.js"), exports);
|
|
@@ -102,7 +104,7 @@ __exportStar(require("./operation-node/drop-view-node.js"), exports);
|
|
|
102
104
|
__exportStar(require("./operation-node/filter-node.js"), exports);
|
|
103
105
|
__exportStar(require("./operation-node/foreign-key-constraint-node.js"), exports);
|
|
104
106
|
__exportStar(require("./operation-node/from-node.js"), exports);
|
|
105
|
-
__exportStar(require("./operation-node/generated-
|
|
107
|
+
__exportStar(require("./operation-node/generated-node.js"), exports);
|
|
106
108
|
__exportStar(require("./operation-node/group-by-item-node.js"), exports);
|
|
107
109
|
__exportStar(require("./operation-node/group-by-node.js"), exports);
|
|
108
110
|
__exportStar(require("./operation-node/having-node.js"), exports);
|
|
@@ -147,6 +149,6 @@ __exportStar(require("./operation-node/value-node.js"), exports);
|
|
|
147
149
|
__exportStar(require("./operation-node/values-node.js"), exports);
|
|
148
150
|
__exportStar(require("./operation-node/where-node.js"), exports);
|
|
149
151
|
__exportStar(require("./operation-node/with-node.js"), exports);
|
|
150
|
-
__exportStar(require("./
|
|
152
|
+
__exportStar(require("./dialect/database-introspector.js"), exports);
|
|
151
153
|
__exportStar(require("./util/compilable.js"), exports);
|
|
152
154
|
__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) {
|