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
|
@@ -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
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
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;
|
|
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
|
}
|
|
@@ -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
|
/**
|
|
@@ -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
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
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;
|
|
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
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export * from './operation-node/column-definition-node.js';
|
|
|
73
73
|
export * from './operation-node/column-node.js';
|
|
74
74
|
export * from './operation-node/column-update-node.js';
|
|
75
75
|
export * from './operation-node/common-table-expression-node.js';
|
|
76
|
+
export * from './operation-node/common-table-expression-name-node.js';
|
|
76
77
|
export * from './operation-node/constraint-node.js';
|
|
77
78
|
export * from './operation-node/create-index-node.js';
|
|
78
79
|
export * from './operation-node/create-schema-node.js';
|
|
@@ -90,7 +91,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
90
91
|
export * from './operation-node/filter-node.js';
|
|
91
92
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
92
93
|
export * from './operation-node/from-node.js';
|
|
93
|
-
export * from './operation-node/generated-
|
|
94
|
+
export * from './operation-node/generated-node.js';
|
|
94
95
|
export * from './operation-node/group-by-item-node.js';
|
|
95
96
|
export * from './operation-node/group-by-node.js';
|
|
96
97
|
export * from './operation-node/having-node.js';
|
|
@@ -135,11 +136,11 @@ export * from './operation-node/value-node.js';
|
|
|
135
136
|
export * from './operation-node/values-node.js';
|
|
136
137
|
export * from './operation-node/where-node.js';
|
|
137
138
|
export * from './operation-node/with-node.js';
|
|
138
|
-
export * from './
|
|
139
|
+
export * from './dialect/database-introspector.js';
|
|
139
140
|
export * from './util/compilable.js';
|
|
140
141
|
export * from './util/log.js';
|
|
141
142
|
export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
|
|
142
|
-
export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
|
|
143
|
+
export { SelectExpression, SelectExpressionOrList, Selection, } from './parser/select-parser.js';
|
|
143
144
|
export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
|
|
144
145
|
export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
145
146
|
export { FilterValueExpression, FilterValueExpressionOrList, ExistsExpression, FilterOperator, } from './parser/filter-parser.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -73,6 +73,7 @@ export * from './operation-node/column-definition-node.js';
|
|
|
73
73
|
export * from './operation-node/column-node.js';
|
|
74
74
|
export * from './operation-node/column-update-node.js';
|
|
75
75
|
export * from './operation-node/common-table-expression-node.js';
|
|
76
|
+
export * from './operation-node/common-table-expression-name-node.js';
|
|
76
77
|
export * from './operation-node/constraint-node.js';
|
|
77
78
|
export * from './operation-node/create-index-node.js';
|
|
78
79
|
export * from './operation-node/create-schema-node.js';
|
|
@@ -90,7 +91,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
90
91
|
export * from './operation-node/filter-node.js';
|
|
91
92
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
92
93
|
export * from './operation-node/from-node.js';
|
|
93
|
-
export * from './operation-node/generated-
|
|
94
|
+
export * from './operation-node/generated-node.js';
|
|
94
95
|
export * from './operation-node/group-by-item-node.js';
|
|
95
96
|
export * from './operation-node/group-by-node.js';
|
|
96
97
|
export * from './operation-node/having-node.js';
|
|
@@ -135,6 +136,6 @@ export * from './operation-node/value-node.js';
|
|
|
135
136
|
export * from './operation-node/values-node.js';
|
|
136
137
|
export * from './operation-node/where-node.js';
|
|
137
138
|
export * from './operation-node/with-node.js';
|
|
138
|
-
export * from './
|
|
139
|
+
export * from './dialect/database-introspector.js';
|
|
139
140
|
export * from './util/compilable.js';
|
|
140
141
|
export * from './util/log.js';
|
package/dist/esm/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/esm/kysely.js
CHANGED
|
@@ -258,6 +258,40 @@ export class Kysely extends QueryCreator {
|
|
|
258
258
|
executor: this.#props.executor.withoutPlugins(),
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Returns a copy of this Kysely instance with tables added to its
|
|
263
|
+
* database type.
|
|
264
|
+
*
|
|
265
|
+
* This method only modifies the types and doesn't affect any of the
|
|
266
|
+
* executed queries in any way.
|
|
267
|
+
*
|
|
268
|
+
* ### Examples
|
|
269
|
+
*
|
|
270
|
+
* The following example adds and uses a temporary table:
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* await db.schema
|
|
275
|
+
* .createTable('temp_table')
|
|
276
|
+
* .temporary()
|
|
277
|
+
* .addColumn('some_column', 'integer')
|
|
278
|
+
* .execute()
|
|
279
|
+
*
|
|
280
|
+
* const tempDb = db.withTables<{
|
|
281
|
+
* temp_table: {
|
|
282
|
+
* some_column: number
|
|
283
|
+
* }
|
|
284
|
+
* }>()
|
|
285
|
+
*
|
|
286
|
+
* await tempDb
|
|
287
|
+
* .insertInto('temp_table')
|
|
288
|
+
* .values({ some_column: 100 })
|
|
289
|
+
* .execute()
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
withTables() {
|
|
293
|
+
return new Kysely({ ...this.#props });
|
|
294
|
+
}
|
|
261
295
|
/**
|
|
262
296
|
* Releases all resources and disconnects from the database.
|
|
263
297
|
*
|
|
@@ -311,6 +345,9 @@ export class Transaction extends Kysely {
|
|
|
311
345
|
executor: this.#props.executor.withoutPlugins(),
|
|
312
346
|
});
|
|
313
347
|
}
|
|
348
|
+
withTables() {
|
|
349
|
+
return new Transaction({ ...this.#props });
|
|
350
|
+
}
|
|
314
351
|
}
|
|
315
352
|
export function isKyselyProps(obj) {
|
|
316
353
|
return (isObject(obj) &&
|