kysely 0.12.0 → 0.12.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.
Files changed (65) hide show
  1. package/dist/cjs/dialect/dialect-adapter-base.d.ts +36 -0
  2. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +36 -0
  3. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +16 -0
  4. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
  5. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +3 -0
  6. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +36 -0
  7. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +16 -0
  8. package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
  9. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +3 -0
  10. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  11. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  12. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
  13. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  14. package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
  15. package/dist/cjs/driver/runtime-driver.d.ts +29 -0
  16. package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
  17. package/dist/cjs/package.json +1 -3
  18. package/dist/cjs/parser/parse-context.d.ts +14 -0
  19. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  20. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  21. package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  22. package/dist/cjs/query-builder/delete-query-builder.d.ts +545 -0
  23. package/dist/cjs/query-builder/insert-query-builder.d.ts +69 -4
  24. package/dist/cjs/query-builder/join-interface.d.ts +3 -6
  25. package/dist/cjs/query-builder/returning-interface.d.ts +1 -1
  26. package/dist/cjs/query-builder/select-query-builder.d.ts +513 -2
  27. package/dist/cjs/query-builder/select-query-builder.js +2 -2
  28. package/dist/cjs/query-builder/update-query-builder.d.ts +547 -2
  29. package/dist/cjs/query-builder/update-query-builder.js +2 -2
  30. package/dist/cjs/query-builder/where-interface.d.ts +7 -10
  31. package/dist/cjs/schema/alter-table-builder.d.ts +216 -0
  32. package/dist/cjs/schema/column-definition-builder.d.ts +108 -0
  33. package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
  34. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +36 -0
  35. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +16 -0
  36. package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
  37. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
  38. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +36 -0
  39. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +16 -0
  40. package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
  41. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +3 -0
  42. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  43. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  44. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
  45. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  46. package/dist/esm/driver/default-connection-provider.d.ts +4 -0
  47. package/dist/esm/driver/runtime-driver.d.ts +29 -0
  48. package/dist/esm/driver/single-connection-provider.d.ts +4 -0
  49. package/dist/esm/package.json +1 -3
  50. package/dist/esm/parser/parse-context.d.ts +14 -0
  51. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  52. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  53. package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  54. package/dist/esm/query-builder/delete-query-builder.d.ts +545 -0
  55. package/dist/esm/query-builder/insert-query-builder.d.ts +69 -4
  56. package/dist/esm/query-builder/join-interface.d.ts +3 -6
  57. package/dist/esm/query-builder/returning-interface.d.ts +1 -1
  58. package/dist/esm/query-builder/select-query-builder.d.ts +513 -2
  59. package/dist/esm/query-builder/select-query-builder.js +2 -2
  60. package/dist/esm/query-builder/update-query-builder.d.ts +547 -2
  61. package/dist/esm/query-builder/update-query-builder.js +2 -2
  62. package/dist/esm/query-builder/where-interface.d.ts +7 -10
  63. package/dist/esm/schema/alter-table-builder.d.ts +216 -0
  64. package/dist/esm/schema/column-definition-builder.d.ts +108 -0
  65. package/package.json +7 -5
@@ -1,7 +1,43 @@
1
1
  import { DialectAdapter } from '../dialect-adapter.js';
2
2
  export declare class SqliteAdapter implements DialectAdapter {
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
  }
@@ -1,3 +1 @@
1
- {
2
- "type": "module"
3
- }
1
+ {"type":"module"}
@@ -34,8 +34,22 @@ export declare class DefaultParseContext implements ParseContext {
34
34
  #private;
35
35
  constructor(adapter: DialectAdapter);
36
36
  get adapter(): DialectAdapter;
37
+ /**
38
+ * Creates a select query builder with a {@link NoopQueryExecutor}.
39
+ */
37
40
  createSelectQueryBuilder(): SelectQueryBuilder<any, any, any>;
41
+ /**
42
+ * Creates an expression builder for building stuff like subqueries.
43
+ * {@link NoopQueryExecutor} is used as the executor and the queries
44
+ * built using the returned builder can never be executed.
45
+ */
38
46
  createExpressionBuilder(): ExpressionBuilder<any, any>;
47
+ /**
48
+ * Creates a query creator with a {@link NoopQueryExecutor}.
49
+ */
39
50
  createQueryCreator(): QueryCreator<any>;
51
+ /**
52
+ * Creates an instance of a join builder.
53
+ */
40
54
  createJoinBuilder(joinType: JoinType, table: TableExpression<any, any>): JoinBuilder<any, any>;
41
55
  }
@@ -94,7 +94,41 @@ export interface CamelCasePluginOptions {
94
94
  export declare class CamelCasePlugin implements KyselyPlugin {
95
95
  #private;
96
96
  constructor(opt?: CamelCasePluginOptions);
97
+ /**
98
+ * This is called for each query before it is executed. You can modify the query by
99
+ * transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
100
+ * and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
101
+ * for this.
102
+ *
103
+ * If you need to pass some query-related data between this method and `transformResult` you
104
+ * can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
105
+ *
106
+ * ```ts
107
+ * const plugin = {
108
+ * data: new WeakMap<QueryId, SomeData>(),
109
+ *
110
+ * transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
111
+ * this.data.set(args.queryId, something)
112
+ * return args.node
113
+ * },
114
+ *
115
+ * transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
116
+ * const data = this.data.get(args.queryId)
117
+ * return args.result
118
+ * }
119
+ * }
120
+ * ```
121
+ *
122
+ * You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
123
+ * is not always matched by a call to `transformResult` which would leave orphaned items in the map
124
+ * and cause a memory leak.
125
+ */
97
126
  transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
127
+ /**
128
+ * This method is called for each query after it has been executed. The result
129
+ * of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
130
+ * You can modify the result and return the modifier result.
131
+ */
98
132
  transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
99
133
  protected mapRow(row: UnknownRow): UnknownRow;
100
134
  protected snakeCase(str: string): string;
@@ -12,6 +12,40 @@ import { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs } fro
12
12
  */
13
13
  export declare class ImmediateValuePlugin implements KyselyPlugin {
14
14
  #private;
15
+ /**
16
+ * This is called for each query before it is executed. You can modify the query by
17
+ * transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
18
+ * and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
19
+ * for this.
20
+ *
21
+ * If you need to pass some query-related data between this method and `transformResult` you
22
+ * can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
23
+ *
24
+ * ```ts
25
+ * const plugin = {
26
+ * data: new WeakMap<QueryId, SomeData>(),
27
+ *
28
+ * transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
29
+ * this.data.set(args.queryId, something)
30
+ * return args.node
31
+ * },
32
+ *
33
+ * transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
34
+ * const data = this.data.get(args.queryId)
35
+ * return args.result
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
41
+ * is not always matched by a call to `transformResult` which would leave orphaned items in the map
42
+ * and cause a memory leak.
43
+ */
15
44
  transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
45
+ /**
46
+ * This method is called for each query after it has been executed. The result
47
+ * of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
48
+ * You can modify the result and return the modifier result.
49
+ */
16
50
  transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
17
51
  }
@@ -5,6 +5,40 @@ import { UnknownRow } from '../../util/type-utils.js';
5
5
  export declare class WithSchemaPlugin implements KyselyPlugin {
6
6
  #private;
7
7
  constructor(schema: string);
8
+ /**
9
+ * This is called for each query before it is executed. You can modify the query by
10
+ * transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
11
+ * and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
12
+ * for this.
13
+ *
14
+ * If you need to pass some query-related data between this method and `transformResult` you
15
+ * can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
16
+ *
17
+ * ```ts
18
+ * const plugin = {
19
+ * data: new WeakMap<QueryId, SomeData>(),
20
+ *
21
+ * transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
22
+ * this.data.set(args.queryId, something)
23
+ * return args.node
24
+ * },
25
+ *
26
+ * transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
27
+ * const data = this.data.get(args.queryId)
28
+ * return args.result
29
+ * }
30
+ * }
31
+ * ```
32
+ *
33
+ * You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
34
+ * is not always matched by a call to `transformResult` which would leave orphaned items in the map
35
+ * and cause a memory leak.
36
+ */
8
37
  transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
38
+ /**
39
+ * This method is called for each query after it has been executed. The result
40
+ * of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
41
+ * You can modify the result and return the modifier result.
42
+ */
9
43
  transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
10
44
  }