kysely 0.15.3 → 0.16.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.
Files changed (48) hide show
  1. package/README.md +1 -9
  2. package/dist/cjs/dialect/database-introspector.d.ts +1 -1
  3. package/dist/cjs/dialect/dialect-adapter-base.d.ts +1 -1
  4. package/dist/cjs/dialect/dialect-adapter.d.ts +1 -1
  5. package/dist/cjs/dialect/dialect.d.ts +2 -2
  6. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +2 -2
  8. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  9. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +1 -1
  10. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +2 -2
  11. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  12. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +1 -1
  13. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +2 -2
  14. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  15. package/dist/cjs/kysely.js +9 -5
  16. package/dist/cjs/migration/file-migration-provider.d.ts +2 -25
  17. package/dist/cjs/migration/file-migration-provider.js +8 -17
  18. package/dist/cjs/migration/migrator.d.ts +2 -15
  19. package/dist/cjs/migration/migrator.js +2 -15
  20. package/dist/cjs/parser/join-parser.d.ts +4 -4
  21. package/dist/cjs/query-builder/delete-query-builder.d.ts +3 -3
  22. package/dist/cjs/query-builder/join-interface.d.ts +3 -3
  23. package/dist/cjs/query-builder/select-query-builder.d.ts +3 -3
  24. package/dist/cjs/query-builder/update-query-builder.d.ts +3 -3
  25. package/dist/esm/dialect/database-introspector.d.ts +1 -1
  26. package/dist/esm/dialect/dialect-adapter-base.d.ts +1 -1
  27. package/dist/esm/dialect/dialect-adapter.d.ts +1 -1
  28. package/dist/esm/dialect/dialect.d.ts +2 -2
  29. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +1 -1
  30. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +2 -2
  31. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  32. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +1 -1
  33. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +2 -2
  34. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  35. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +1 -1
  36. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +2 -2
  37. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  38. package/dist/esm/kysely.js +9 -5
  39. package/dist/esm/migration/file-migration-provider.d.ts +2 -25
  40. package/dist/esm/migration/file-migration-provider.js +8 -17
  41. package/dist/esm/migration/migrator.d.ts +2 -15
  42. package/dist/esm/migration/migrator.js +2 -15
  43. package/dist/esm/parser/join-parser.d.ts +4 -4
  44. package/dist/esm/query-builder/delete-query-builder.d.ts +3 -3
  45. package/dist/esm/query-builder/join-interface.d.ts +3 -3
  46. package/dist/esm/query-builder/select-query-builder.d.ts +3 -3
  47. package/dist/esm/query-builder/update-query-builder.d.ts +3 -3
  48. package/package.json +1 -1
package/README.md CHANGED
@@ -303,9 +303,6 @@ need to depend on a typescript compiler, which most production environments don'
303
303
  have. You will probably want to add a simple migration script to your projects like this:
304
304
 
305
305
  ```ts
306
- import * as path from 'path'
307
- import * as fs from 'fs/promises'
308
-
309
306
  import {
310
307
  Kysely,
311
308
  Migrator,
@@ -323,14 +320,9 @@ async function migrateToLatest() {
323
320
 
324
321
  const migrator = new Migrator({
325
322
  db,
326
- // The constructor signature of FileMigrationProvider is a
327
- // bit weird to keep Kysely independent of node.js or any
328
- // other environment.
329
323
  provider: new FileMigrationProvider(
330
- fs.readdir,
331
- path.join,
332
324
  // Path to the folder that contains all your migrations.
333
- 'migrations'
325
+ 'some/path/to/migrations'
334
326
  )
335
327
  })
336
328
 
@@ -4,7 +4,7 @@ import { ColumnDataType } from '../operation-node/data-type-node.js';
4
4
  */
5
5
  export interface DatabaseIntrospector {
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -20,7 +20,7 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
20
20
  get supportsReturning(): boolean;
21
21
  /**
22
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.
23
+ * it's not possible for two migration operations to run in parallel.
24
24
  *
25
25
  * Most dialects have explicit locks that can be used, like advisory locks
26
26
  * in PostgreSQL and the get_lock function in MySQL.
@@ -21,7 +21,7 @@ export interface DialectAdapter {
21
21
  readonly supportsReturning: boolean;
22
22
  /**
23
23
  * This method is used to acquire a lock for the migrations so that
24
- * it's not possible for two migration processes to run in parallel.
24
+ * it's not possible for two migration operations to run in parallel.
25
25
  *
26
26
  * Most dialects have explicit locks that can be used, like advisory locks
27
27
  * in PostgreSQL and the get_lock function in MySQL.
@@ -24,8 +24,8 @@ export interface Dialect {
24
24
  */
25
25
  createAdapter(): DialectAdapter;
26
26
  /**
27
- * Creates a database introspector that can be used to get the database metadata
28
- * such as the tables and columns that exist in the database.
27
+ * Creates a database introspector that can be used to get database metadata
28
+ * such as the table names and column names of those tables.
29
29
  *
30
30
  * `db` never has any plugins installed. It's created using
31
31
  * {@link Kysely.withoutPlugins}.
@@ -14,7 +14,7 @@ export declare class MysqlAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
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.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class MysqlDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
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.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class MysqlIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -14,7 +14,7 @@ export declare class PostgresAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
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.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -34,8 +34,8 @@ export declare class PostgresDialect implements Dialect {
34
34
  */
35
35
  createAdapter(): DialectAdapter;
36
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.
37
+ * Creates a database introspector that can be used to get database metadata
38
+ * such as the table names and column names of those tables.
39
39
  *
40
40
  * `db` never has any plugins installed. It's created using
41
41
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class PostgresIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -13,7 +13,7 @@ export declare class SqliteAdapter implements DialectAdapterBase {
13
13
  get supportsReturning(): boolean;
14
14
  /**
15
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.
16
+ * it's not possible for two migration operations to run in parallel.
17
17
  *
18
18
  * Most dialects have explicit locks that can be used, like advisory locks
19
19
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class SqliteDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
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.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class SqliteIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -59,9 +59,11 @@ const private_symbols_js_1 = require("./util/private-symbols.js");
59
59
  class Kysely extends query_creator_js_1.QueryCreator {
60
60
  #props;
61
61
  constructor(args) {
62
+ let superProps;
63
+ let props;
62
64
  if (isKyselyProps(args)) {
63
- super({ executor: args.executor, parseContext: args.parseContext });
64
- this.#props = (0, object_utils_js_1.freeze)({ ...args });
65
+ superProps = { executor: args.executor, parseContext: args.parseContext };
66
+ props = { ...args };
65
67
  }
66
68
  else {
67
69
  const dialect = args.dialect;
@@ -73,15 +75,17 @@ class Kysely extends query_creator_js_1.QueryCreator {
73
75
  const runtimeDriver = new runtime_driver_js_1.RuntimeDriver(driver, log);
74
76
  const connectionProvider = new default_connection_provider_js_1.DefaultConnectionProvider(runtimeDriver);
75
77
  const executor = new default_query_executor_js_1.DefaultQueryExecutor(compiler, connectionProvider, args.plugins ?? []);
76
- super({ executor, parseContext });
77
- this.#props = (0, object_utils_js_1.freeze)({
78
+ superProps = { executor, parseContext };
79
+ props = {
78
80
  config: args,
79
81
  executor,
80
82
  dialect,
81
83
  driver: runtimeDriver,
82
84
  parseContext,
83
- });
85
+ };
84
86
  }
87
+ super(superProps);
88
+ this.#props = (0, object_utils_js_1.freeze)(props);
85
89
  }
86
90
  /**
87
91
  * Returns the {@link SchemaModule} module for building database schema.
@@ -1,41 +1,18 @@
1
1
  import { Migration, MigrationProvider } from './migrator.js';
2
- /**
3
- * A function that takes a folder path and returns names of the
4
- * files insider that folder.
5
- */
6
- export declare type ReadDir = (migrationFolderPath: string) => Promise<string[]>;
7
- /**
8
- * A function that combines two file path parts into a single file path.
9
- *
10
- * ```ts
11
- * joinPath('/some/path', 'file.ts')
12
- * // ==> '/some/path/file.ts'
13
- * ```
14
- */
15
- export declare type JoinPath = (part1: string, part2: string) => string;
16
2
  /**
17
3
  * Reads all migrations from a folder.
18
4
  *
19
- * You need to provide a function for reading files in a folder and a function for
20
- * joining file paths together. The API is like this to make Kysely independent of
21
- * node.js or any other environment. See the example usage on node.js below.
22
- *
23
5
  * ### Examples
24
6
  *
25
7
  * ```ts
26
- * import * as path from 'path'
27
- * import * as fs from 'fs/promises'
28
- *
29
8
  * new FileMigrationProvider(
30
- * fs.readdir,
31
- * path.join,
32
- * path.join(__dirname, 'migrations')
9
+ * 'path/to/migrations/folder'
33
10
  * )
34
11
  * ```
35
12
  */
36
13
  export declare class FileMigrationProvider implements MigrationProvider {
37
14
  #private;
38
- constructor(readDir: ReadDir, joinPath: JoinPath, migrationFolderPath: string);
15
+ constructor(migrationFolderPath: string);
39
16
  /**
40
17
  * Returns all migrations, old and new.
41
18
  *
@@ -5,39 +5,30 @@ const object_utils_js_1 = require("../util/object-utils.js");
5
5
  /**
6
6
  * Reads all migrations from a folder.
7
7
  *
8
- * You need to provide a function for reading files in a folder and a function for
9
- * joining file paths together. The API is like this to make Kysely independent of
10
- * node.js or any other environment. See the example usage on node.js below.
11
- *
12
8
  * ### Examples
13
9
  *
14
10
  * ```ts
15
- * import * as path from 'path'
16
- * import * as fs from 'fs/promises'
17
- *
18
11
  * new FileMigrationProvider(
19
- * fs.readdir,
20
- * path.join,
21
- * path.join(__dirname, 'migrations')
12
+ * 'path/to/migrations/folder'
22
13
  * )
23
14
  * ```
24
15
  */
25
16
  class FileMigrationProvider {
26
- #readDir;
27
- #joinPath;
28
17
  #migrationFolderPath;
29
- constructor(readDir, joinPath, migrationFolderPath) {
30
- this.#readDir = readDir;
31
- this.#joinPath = joinPath;
18
+ constructor(migrationFolderPath) {
32
19
  this.#migrationFolderPath = migrationFolderPath;
33
20
  }
34
21
  async getMigrations() {
22
+ // Import these dynamically so that we don't have any top level
23
+ // node dependencies.
24
+ const fs = await Promise.resolve().then(() => require('fs/promises'));
25
+ const path = await Promise.resolve().then(() => require('path'));
35
26
  const migrations = {};
36
- const files = await this.#readDir(this.#migrationFolderPath);
27
+ const files = await fs.readdir(this.#migrationFolderPath);
37
28
  for (const fileName of files) {
38
29
  if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
39
30
  !fileName.endsWith('.d.ts')) {
40
- const migration = await Promise.resolve().then(() => require(this.#joinPath(this.#migrationFolderPath, fileName)));
31
+ const migration = await Promise.resolve().then(() => require(path.join(this.#migrationFolderPath, fileName)));
41
32
  if (isMigration(migration)) {
42
33
  migrations[fileName.substring(0, fileName.length - 3)] = migration;
43
34
  }
@@ -26,14 +26,9 @@ export interface Migration {
26
26
  * ```ts
27
27
  * const migrator = new Migrator({
28
28
  * db,
29
- * // The constructor signature of FileMigrationProvider is a
30
- * // bit weird to keep Kysely independent of node.js or any
31
- * // other environment.
32
29
  * provider: new FileMigrationProvider(
33
- * fs.readdir,
34
- * path.join,
35
30
  * // Path to the folder that contains all your migrations.
36
- * 'migrations'
31
+ * 'some/path/to/migrations'
37
32
  * )
38
33
  * })
39
34
  * ```
@@ -57,9 +52,6 @@ export declare class Migrator {
57
52
  * ### Examples
58
53
  *
59
54
  * ```ts
60
- * import * as path from 'path'
61
- * import * as fs from 'fs/promises'
62
- *
63
55
  * const db = new Kysely<Database>({
64
56
  * dialect: new PostgresDialect({
65
57
  * host: 'localhost',
@@ -69,14 +61,9 @@ export declare class Migrator {
69
61
  *
70
62
  * const migrator = new Migrator({
71
63
  * db,
72
- * // The constructor signature of FileMigrationProvider is a
73
- * // bit weird to keep Kysely independent of node.js or any
74
- * // other environment.
75
64
  * provider: new FileMigrationProvider(
76
- * fs.readdir,
77
- * path.join,
78
65
  * // Path to the folder that contains all your migrations.
79
- * 'migrations'
66
+ * 'some/path/to/migrations'
80
67
  * )
81
68
  * })
82
69
  *
@@ -20,14 +20,9 @@ exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true }
20
20
  * ```ts
21
21
  * const migrator = new Migrator({
22
22
  * db,
23
- * // The constructor signature of FileMigrationProvider is a
24
- * // bit weird to keep Kysely independent of node.js or any
25
- * // other environment.
26
23
  * provider: new FileMigrationProvider(
27
- * fs.readdir,
28
- * path.join,
29
24
  * // Path to the folder that contains all your migrations.
30
- * 'migrations'
25
+ * 'some/path/to/migrations'
31
26
  * )
32
27
  * })
33
28
  * ```
@@ -53,9 +48,6 @@ class Migrator {
53
48
  * ### Examples
54
49
  *
55
50
  * ```ts
56
- * import * as path from 'path'
57
- * import * as fs from 'fs/promises'
58
- *
59
51
  * const db = new Kysely<Database>({
60
52
  * dialect: new PostgresDialect({
61
53
  * host: 'localhost',
@@ -65,14 +57,9 @@ class Migrator {
65
57
  *
66
58
  * const migrator = new Migrator({
67
59
  * db,
68
- * // The constructor signature of FileMigrationProvider is a
69
- * // bit weird to keep Kysely independent of node.js or any
70
- * // other environment.
71
60
  * provider: new FileMigrationProvider(
72
- * fs.readdir,
73
- * path.join,
74
61
  * // Path to the folder that contains all your migrations.
75
- * 'migrations'
62
+ * 'some/path/to/migrations'
76
63
  * )
77
64
  * })
78
65
  *
@@ -1,11 +1,11 @@
1
1
  import { JoinNode, JoinType } from '../operation-node/join-node.js';
2
2
  import { AnyColumn, AnyColumnWithTable } from '../util/type-utils.js';
3
- import { ExtractAliasFromTableExpression, TableExpressionDatabase } from './table-parser.js';
3
+ import { TableExpressionDatabase, TableExpressionTables } from './table-parser.js';
4
4
  import { JoinBuilder } from '../query-builder/join-builder.js';
5
5
  import { ParseContext } from './parse-context.js';
6
6
  export declare type JoinReferenceExpression<DB, TB extends keyof DB, TE> = AnyJoinColumn<DB, TB, TE> | AnyJoinColumnWithTable<DB, TB, TE>;
7
- export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>) => JoinBuilder<any, any>;
8
- declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
9
- declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
7
+ export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>) => JoinBuilder<any, any>;
8
+ declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
9
+ declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
10
10
  export declare function parseJoin(ctx: ParseContext, joinType: JoinType, args: any[]): JoinNode;
11
11
  export {};
@@ -473,13 +473,13 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
473
473
  * and "pet"."name" = $1
474
474
  * ```
475
475
  *
476
- * You can join a subquery by providing a function as the first
477
- * argument:
476
+ * You can join a subquery by providing a select query (or a callback)
477
+ * as the first argument:
478
478
  *
479
479
  * ```ts
480
480
  * await db.selectFrom('person')
481
481
  * .innerJoin(
482
- * (qb) => qb.selectFrom('pet')
482
+ * qb.selectFrom('pet')
483
483
  * .select(['owner_id', 'name'])
484
484
  * .where('name', '=', 'Doggo')
485
485
  * .as('doggos'),
@@ -80,13 +80,13 @@ export interface JoinInterface<DB, TB extends keyof DB> {
80
80
  * and "pet"."name" = $1
81
81
  * ```
82
82
  *
83
- * You can join a subquery by providing a function as the first
84
- * argument:
83
+ * You can join a subquery by providing a select query (or a callback)
84
+ * as the first argument:
85
85
  *
86
86
  * ```ts
87
87
  * await db.selectFrom('person')
88
88
  * .innerJoin(
89
- * (qb) => qb.selectFrom('pet')
89
+ * qb.selectFrom('pet')
90
90
  * .select(['owner_id', 'name'])
91
91
  * .where('name', '=', 'Doggo')
92
92
  * .as('doggos'),
@@ -811,13 +811,13 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
811
811
  * and "pet"."name" = $1
812
812
  * ```
813
813
  *
814
- * You can join a subquery by providing a function as the first
815
- * argument:
814
+ * You can join a subquery by providing a select query (or a callback)
815
+ * as the first argument:
816
816
  *
817
817
  * ```ts
818
818
  * await db.selectFrom('person')
819
819
  * .innerJoin(
820
- * (qb) => qb.selectFrom('pet')
820
+ * qb.selectFrom('pet')
821
821
  * .select(['owner_id', 'name'])
822
822
  * .where('name', '=', 'Doggo')
823
823
  * .as('doggos'),
@@ -474,13 +474,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
474
474
  * and "pet"."name" = $1
475
475
  * ```
476
476
  *
477
- * You can join a subquery by providing a function as the first
478
- * argument:
477
+ * You can join a subquery by providing a select query (or a callback)
478
+ * as the first argument:
479
479
  *
480
480
  * ```ts
481
481
  * await db.selectFrom('person')
482
482
  * .innerJoin(
483
- * (qb) => qb.selectFrom('pet')
483
+ * qb.selectFrom('pet')
484
484
  * .select(['owner_id', 'name'])
485
485
  * .where('name', '=', 'Doggo')
486
486
  * .as('doggos'),
@@ -4,7 +4,7 @@ import { ColumnDataType } from '../operation-node/data-type-node.js';
4
4
  */
5
5
  export interface DatabaseIntrospector {
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -20,7 +20,7 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
20
20
  get supportsReturning(): boolean;
21
21
  /**
22
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.
23
+ * it's not possible for two migration operations to run in parallel.
24
24
  *
25
25
  * Most dialects have explicit locks that can be used, like advisory locks
26
26
  * in PostgreSQL and the get_lock function in MySQL.
@@ -21,7 +21,7 @@ export interface DialectAdapter {
21
21
  readonly supportsReturning: boolean;
22
22
  /**
23
23
  * This method is used to acquire a lock for the migrations so that
24
- * it's not possible for two migration processes to run in parallel.
24
+ * it's not possible for two migration operations to run in parallel.
25
25
  *
26
26
  * Most dialects have explicit locks that can be used, like advisory locks
27
27
  * in PostgreSQL and the get_lock function in MySQL.
@@ -24,8 +24,8 @@ export interface Dialect {
24
24
  */
25
25
  createAdapter(): DialectAdapter;
26
26
  /**
27
- * Creates a database introspector that can be used to get the database metadata
28
- * such as the tables and columns that exist in the database.
27
+ * Creates a database introspector that can be used to get database metadata
28
+ * such as the table names and column names of those tables.
29
29
  *
30
30
  * `db` never has any plugins installed. It's created using
31
31
  * {@link Kysely.withoutPlugins}.
@@ -14,7 +14,7 @@ export declare class MysqlAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
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.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class MysqlDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
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.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class MysqlIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -14,7 +14,7 @@ export declare class PostgresAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
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.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -34,8 +34,8 @@ export declare class PostgresDialect implements Dialect {
34
34
  */
35
35
  createAdapter(): DialectAdapter;
36
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.
37
+ * Creates a database introspector that can be used to get database metadata
38
+ * such as the table names and column names of those tables.
39
39
  *
40
40
  * `db` never has any plugins installed. It's created using
41
41
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class PostgresIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -13,7 +13,7 @@ export declare class SqliteAdapter implements DialectAdapterBase {
13
13
  get supportsReturning(): boolean;
14
14
  /**
15
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.
16
+ * it's not possible for two migration operations to run in parallel.
17
17
  *
18
18
  * Most dialects have explicit locks that can be used, like advisory locks
19
19
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class SqliteDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
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.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class SqliteIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -56,9 +56,11 @@ import { PRIVATE_ADAPTER } from './util/private-symbols.js';
56
56
  export class Kysely extends QueryCreator {
57
57
  #props;
58
58
  constructor(args) {
59
+ let superProps;
60
+ let props;
59
61
  if (isKyselyProps(args)) {
60
- super({ executor: args.executor, parseContext: args.parseContext });
61
- this.#props = freeze({ ...args });
62
+ superProps = { executor: args.executor, parseContext: args.parseContext };
63
+ props = { ...args };
62
64
  }
63
65
  else {
64
66
  const dialect = args.dialect;
@@ -70,15 +72,17 @@ export class Kysely extends QueryCreator {
70
72
  const runtimeDriver = new RuntimeDriver(driver, log);
71
73
  const connectionProvider = new DefaultConnectionProvider(runtimeDriver);
72
74
  const executor = new DefaultQueryExecutor(compiler, connectionProvider, args.plugins ?? []);
73
- super({ executor, parseContext });
74
- this.#props = freeze({
75
+ superProps = { executor, parseContext };
76
+ props = {
75
77
  config: args,
76
78
  executor,
77
79
  dialect,
78
80
  driver: runtimeDriver,
79
81
  parseContext,
80
- });
82
+ };
81
83
  }
84
+ super(superProps);
85
+ this.#props = freeze(props);
82
86
  }
83
87
  /**
84
88
  * Returns the {@link SchemaModule} module for building database schema.
@@ -1,41 +1,18 @@
1
1
  import { Migration, MigrationProvider } from './migrator.js';
2
- /**
3
- * A function that takes a folder path and returns names of the
4
- * files insider that folder.
5
- */
6
- export declare type ReadDir = (migrationFolderPath: string) => Promise<string[]>;
7
- /**
8
- * A function that combines two file path parts into a single file path.
9
- *
10
- * ```ts
11
- * joinPath('/some/path', 'file.ts')
12
- * // ==> '/some/path/file.ts'
13
- * ```
14
- */
15
- export declare type JoinPath = (part1: string, part2: string) => string;
16
2
  /**
17
3
  * Reads all migrations from a folder.
18
4
  *
19
- * You need to provide a function for reading files in a folder and a function for
20
- * joining file paths together. The API is like this to make Kysely independent of
21
- * node.js or any other environment. See the example usage on node.js below.
22
- *
23
5
  * ### Examples
24
6
  *
25
7
  * ```ts
26
- * import * as path from 'path'
27
- * import * as fs from 'fs/promises'
28
- *
29
8
  * new FileMigrationProvider(
30
- * fs.readdir,
31
- * path.join,
32
- * path.join(__dirname, 'migrations')
9
+ * 'path/to/migrations/folder'
33
10
  * )
34
11
  * ```
35
12
  */
36
13
  export declare class FileMigrationProvider implements MigrationProvider {
37
14
  #private;
38
- constructor(readDir: ReadDir, joinPath: JoinPath, migrationFolderPath: string);
15
+ constructor(migrationFolderPath: string);
39
16
  /**
40
17
  * Returns all migrations, old and new.
41
18
  *
@@ -2,39 +2,30 @@ import { isFunction, isObject } from '../util/object-utils.js';
2
2
  /**
3
3
  * Reads all migrations from a folder.
4
4
  *
5
- * You need to provide a function for reading files in a folder and a function for
6
- * joining file paths together. The API is like this to make Kysely independent of
7
- * node.js or any other environment. See the example usage on node.js below.
8
- *
9
5
  * ### Examples
10
6
  *
11
7
  * ```ts
12
- * import * as path from 'path'
13
- * import * as fs from 'fs/promises'
14
- *
15
8
  * new FileMigrationProvider(
16
- * fs.readdir,
17
- * path.join,
18
- * path.join(__dirname, 'migrations')
9
+ * 'path/to/migrations/folder'
19
10
  * )
20
11
  * ```
21
12
  */
22
13
  export class FileMigrationProvider {
23
- #readDir;
24
- #joinPath;
25
14
  #migrationFolderPath;
26
- constructor(readDir, joinPath, migrationFolderPath) {
27
- this.#readDir = readDir;
28
- this.#joinPath = joinPath;
15
+ constructor(migrationFolderPath) {
29
16
  this.#migrationFolderPath = migrationFolderPath;
30
17
  }
31
18
  async getMigrations() {
19
+ // Import these dynamically so that we don't have any top level
20
+ // node dependencies.
21
+ const fs = await import('fs/promises');
22
+ const path = await import('path');
32
23
  const migrations = {};
33
- const files = await this.#readDir(this.#migrationFolderPath);
24
+ const files = await fs.readdir(this.#migrationFolderPath);
34
25
  for (const fileName of files) {
35
26
  if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
36
27
  !fileName.endsWith('.d.ts')) {
37
- const migration = await import(this.#joinPath(this.#migrationFolderPath, fileName));
28
+ const migration = await import(path.join(this.#migrationFolderPath, fileName));
38
29
  if (isMigration(migration)) {
39
30
  migrations[fileName.substring(0, fileName.length - 3)] = migration;
40
31
  }
@@ -26,14 +26,9 @@ export interface Migration {
26
26
  * ```ts
27
27
  * const migrator = new Migrator({
28
28
  * db,
29
- * // The constructor signature of FileMigrationProvider is a
30
- * // bit weird to keep Kysely independent of node.js or any
31
- * // other environment.
32
29
  * provider: new FileMigrationProvider(
33
- * fs.readdir,
34
- * path.join,
35
30
  * // Path to the folder that contains all your migrations.
36
- * 'migrations'
31
+ * 'some/path/to/migrations'
37
32
  * )
38
33
  * })
39
34
  * ```
@@ -57,9 +52,6 @@ export declare class Migrator {
57
52
  * ### Examples
58
53
  *
59
54
  * ```ts
60
- * import * as path from 'path'
61
- * import * as fs from 'fs/promises'
62
- *
63
55
  * const db = new Kysely<Database>({
64
56
  * dialect: new PostgresDialect({
65
57
  * host: 'localhost',
@@ -69,14 +61,9 @@ export declare class Migrator {
69
61
  *
70
62
  * const migrator = new Migrator({
71
63
  * db,
72
- * // The constructor signature of FileMigrationProvider is a
73
- * // bit weird to keep Kysely independent of node.js or any
74
- * // other environment.
75
64
  * provider: new FileMigrationProvider(
76
- * fs.readdir,
77
- * path.join,
78
65
  * // Path to the folder that contains all your migrations.
79
- * 'migrations'
66
+ * 'some/path/to/migrations'
80
67
  * )
81
68
  * })
82
69
  *
@@ -17,14 +17,9 @@ export const NO_MIGRATIONS = freeze({ __noMigrations__: true });
17
17
  * ```ts
18
18
  * const migrator = new Migrator({
19
19
  * db,
20
- * // The constructor signature of FileMigrationProvider is a
21
- * // bit weird to keep Kysely independent of node.js or any
22
- * // other environment.
23
20
  * provider: new FileMigrationProvider(
24
- * fs.readdir,
25
- * path.join,
26
21
  * // Path to the folder that contains all your migrations.
27
- * 'migrations'
22
+ * 'some/path/to/migrations'
28
23
  * )
29
24
  * })
30
25
  * ```
@@ -50,9 +45,6 @@ export class Migrator {
50
45
  * ### Examples
51
46
  *
52
47
  * ```ts
53
- * import * as path from 'path'
54
- * import * as fs from 'fs/promises'
55
- *
56
48
  * const db = new Kysely<Database>({
57
49
  * dialect: new PostgresDialect({
58
50
  * host: 'localhost',
@@ -62,14 +54,9 @@ export class Migrator {
62
54
  *
63
55
  * const migrator = new Migrator({
64
56
  * db,
65
- * // The constructor signature of FileMigrationProvider is a
66
- * // bit weird to keep Kysely independent of node.js or any
67
- * // other environment.
68
57
  * provider: new FileMigrationProvider(
69
- * fs.readdir,
70
- * path.join,
71
58
  * // Path to the folder that contains all your migrations.
72
- * 'migrations'
59
+ * 'some/path/to/migrations'
73
60
  * )
74
61
  * })
75
62
  *
@@ -1,11 +1,11 @@
1
1
  import { JoinNode, JoinType } from '../operation-node/join-node.js';
2
2
  import { AnyColumn, AnyColumnWithTable } from '../util/type-utils.js';
3
- import { ExtractAliasFromTableExpression, TableExpressionDatabase } from './table-parser.js';
3
+ import { TableExpressionDatabase, TableExpressionTables } from './table-parser.js';
4
4
  import { JoinBuilder } from '../query-builder/join-builder.js';
5
5
  import { ParseContext } from './parse-context.js';
6
6
  export declare type JoinReferenceExpression<DB, TB extends keyof DB, TE> = AnyJoinColumn<DB, TB, TE> | AnyJoinColumnWithTable<DB, TB, TE>;
7
- export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>) => JoinBuilder<any, any>;
8
- declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
9
- declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
7
+ export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>) => JoinBuilder<any, any>;
8
+ declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
9
+ declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
10
10
  export declare function parseJoin(ctx: ParseContext, joinType: JoinType, args: any[]): JoinNode;
11
11
  export {};
@@ -473,13 +473,13 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
473
473
  * and "pet"."name" = $1
474
474
  * ```
475
475
  *
476
- * You can join a subquery by providing a function as the first
477
- * argument:
476
+ * You can join a subquery by providing a select query (or a callback)
477
+ * as the first argument:
478
478
  *
479
479
  * ```ts
480
480
  * await db.selectFrom('person')
481
481
  * .innerJoin(
482
- * (qb) => qb.selectFrom('pet')
482
+ * qb.selectFrom('pet')
483
483
  * .select(['owner_id', 'name'])
484
484
  * .where('name', '=', 'Doggo')
485
485
  * .as('doggos'),
@@ -80,13 +80,13 @@ export interface JoinInterface<DB, TB extends keyof DB> {
80
80
  * and "pet"."name" = $1
81
81
  * ```
82
82
  *
83
- * You can join a subquery by providing a function as the first
84
- * argument:
83
+ * You can join a subquery by providing a select query (or a callback)
84
+ * as the first argument:
85
85
  *
86
86
  * ```ts
87
87
  * await db.selectFrom('person')
88
88
  * .innerJoin(
89
- * (qb) => qb.selectFrom('pet')
89
+ * qb.selectFrom('pet')
90
90
  * .select(['owner_id', 'name'])
91
91
  * .where('name', '=', 'Doggo')
92
92
  * .as('doggos'),
@@ -811,13 +811,13 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
811
811
  * and "pet"."name" = $1
812
812
  * ```
813
813
  *
814
- * You can join a subquery by providing a function as the first
815
- * argument:
814
+ * You can join a subquery by providing a select query (or a callback)
815
+ * as the first argument:
816
816
  *
817
817
  * ```ts
818
818
  * await db.selectFrom('person')
819
819
  * .innerJoin(
820
- * (qb) => qb.selectFrom('pet')
820
+ * qb.selectFrom('pet')
821
821
  * .select(['owner_id', 'name'])
822
822
  * .where('name', '=', 'Doggo')
823
823
  * .as('doggos'),
@@ -474,13 +474,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
474
474
  * and "pet"."name" = $1
475
475
  * ```
476
476
  *
477
- * You can join a subquery by providing a function as the first
478
- * argument:
477
+ * You can join a subquery by providing a select query (or a callback)
478
+ * as the first argument:
479
479
  *
480
480
  * ```ts
481
481
  * await db.selectFrom('person')
482
482
  * .innerJoin(
483
- * (qb) => qb.selectFrom('pet')
483
+ * qb.selectFrom('pet')
484
484
  * .select(['owner_id', 'name'])
485
485
  * .where('name', '=', 'Doggo')
486
486
  * .as('doggos'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",