kysely 0.14.1 → 0.15.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 (66) hide show
  1. package/README.md +92 -32
  2. package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
  3. package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
  4. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
  5. package/dist/cjs/index.d.ts +3 -1
  6. package/dist/cjs/index.js +3 -1
  7. package/dist/cjs/kysely.d.ts +7 -39
  8. package/dist/cjs/kysely.js +8 -40
  9. package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
  10. package/dist/cjs/migration/file-migration-provider.js +52 -0
  11. package/dist/cjs/migration/{migration.d.ts → migrator.d.ts} +159 -134
  12. package/dist/cjs/migration/{migration.js → migrator.js} +166 -57
  13. package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
  14. package/dist/cjs/parser/insert-values-parser.js +2 -3
  15. package/dist/cjs/parser/reference-parser.d.ts +2 -1
  16. package/dist/cjs/parser/select-parser.d.ts +9 -3
  17. package/dist/cjs/parser/update-set-parser.d.ts +2 -1
  18. package/dist/cjs/query-builder/delete-query-builder.d.ts +0 -3
  19. package/dist/cjs/query-builder/insert-query-builder.d.ts +3 -20
  20. package/dist/cjs/query-builder/insert-query-builder.js +2 -7
  21. package/dist/cjs/query-builder/on-conflict-builder.d.ts +2 -2
  22. package/dist/cjs/query-builder/on-conflict-builder.js +2 -2
  23. package/dist/cjs/query-builder/returning-interface.d.ts +0 -3
  24. package/dist/cjs/query-builder/update-query-builder.d.ts +0 -3
  25. package/dist/cjs/query-creator.d.ts +0 -2
  26. package/dist/cjs/query-creator.js +0 -2
  27. package/dist/cjs/util/column-type.d.ts +165 -0
  28. package/dist/cjs/util/column-type.js +2 -0
  29. package/dist/cjs/util/private-symbols.d.ts +5 -0
  30. package/dist/cjs/util/private-symbols.js +8 -0
  31. package/dist/cjs/util/type-utils.d.ts +0 -40
  32. package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
  33. package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
  34. package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
  35. package/dist/esm/index.d.ts +3 -1
  36. package/dist/esm/index.js +3 -1
  37. package/dist/esm/kysely.d.ts +7 -39
  38. package/dist/esm/kysely.js +8 -40
  39. package/dist/esm/migration/file-migration-provider.d.ts +52 -0
  40. package/dist/esm/migration/file-migration-provider.js +48 -0
  41. package/dist/esm/migration/{migration.d.ts → migrator.d.ts} +159 -134
  42. package/dist/esm/migration/{migration.js → migrator.js} +165 -56
  43. package/dist/esm/parser/insert-values-parser.d.ts +4 -4
  44. package/dist/esm/parser/insert-values-parser.js +2 -3
  45. package/dist/esm/parser/reference-parser.d.ts +2 -1
  46. package/dist/esm/parser/select-parser.d.ts +9 -3
  47. package/dist/esm/parser/update-set-parser.d.ts +2 -1
  48. package/dist/esm/query-builder/delete-query-builder.d.ts +0 -3
  49. package/dist/esm/query-builder/insert-query-builder.d.ts +3 -20
  50. package/dist/esm/query-builder/insert-query-builder.js +1 -6
  51. package/dist/esm/query-builder/on-conflict-builder.d.ts +2 -2
  52. package/dist/esm/query-builder/on-conflict-builder.js +2 -2
  53. package/dist/esm/query-builder/returning-interface.d.ts +0 -3
  54. package/dist/esm/query-builder/update-query-builder.d.ts +0 -3
  55. package/dist/esm/query-creator.d.ts +0 -2
  56. package/dist/esm/query-creator.js +0 -2
  57. package/dist/esm/util/column-type.d.ts +165 -0
  58. package/dist/esm/util/column-type.js +1 -0
  59. package/dist/esm/util/private-symbols.d.ts +5 -0
  60. package/dist/esm/util/private-symbols.js +5 -0
  61. package/dist/esm/util/type-utils.d.ts +0 -40
  62. package/package.json +1 -1
  63. package/dist/cjs/util/generated-placeholder.d.ts +0 -3
  64. package/dist/cjs/util/generated-placeholder.js +0 -11
  65. package/dist/esm/util/generated-placeholder.d.ts +0 -3
  66. package/dist/esm/util/generated-placeholder.js +0 -7
package/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
  # [Kysely](https://koskimas.github.io/kysely/index.html)
5
5
 
6
6
  A type-safe and autocompletion-friendly typescript SQL query builder for node.js. Inspired by
7
- [knex](http://knexjs.org/). [Here's](https://www.jakso.me/blog/kysely-a-type-safe-sql-query-builder-for-typescript)
8
- an introductory blog post for you.
7
+ [knex](http://knexjs.org/).
9
8
 
10
9
  ![](https://github.com/koskimas/kysely/blob/master/assets/demo.gif)
11
10
 
@@ -29,6 +28,9 @@ Kysely is still young and some useful features are propably not yet implemented.
29
28
  using Kysely and can't find something you'd want to use, please open an issue or join our
30
29
  [discord server](https://discord.gg/C9aJ49mCra).
31
30
 
31
+ [Here's](https://www.jakso.me/blog/kysely-a-type-safe-sql-query-builder-for-typescript)
32
+ an introductory blog post.
33
+
32
34
  # Table of contents
33
35
 
34
36
  - [Installation](#installation)
@@ -36,6 +38,7 @@ using Kysely and can't find something you'd want to use, please open an issue or
36
38
  - [Query examples](#query-examples)
37
39
  - [Migrations](#migrations)
38
40
  - [API reference](https://koskimas.github.io/kysely/index.html)
41
+ - [Changelog](https://github.com/koskimas/kysely/releases)
39
42
 
40
43
  # Installation
41
44
 
@@ -65,34 +68,55 @@ All you need to do is define an interface for each table in the database and pas
65
68
  interfaces to the `Kysely` constructor:
66
69
 
67
70
  ```ts
68
- import { Kysely, PostgresDialect } from 'kysely'
71
+ import {
72
+ Kysely,
73
+ PostgresDialect,
74
+ Generated,
75
+ ColumnType,
76
+ Selectable,
77
+ Insertable,
78
+ Updateable,
79
+ } from 'kysely'
80
+
81
+ interface PersonTable {
82
+ // Columns that are generated by the database should be marked
83
+ // using the `Generated` type. This way they are automatically
84
+ // made optional in inserts.
85
+ id: Generated<number>
69
86
 
70
- interface Person {
71
- id: number
72
87
  first_name: string
73
- // If the column is nullable in the db, make its type nullable.
74
- // Don't use optional properties.
75
- last_name: string | null
76
88
  gender: 'male' | 'female' | 'other'
89
+
90
+ // If the column is nullable in the database, make its type nullable.
91
+ // Don't use optional properties. Optionality is always determined
92
+ // automatically by Kysely.
93
+ last_name: string | null
94
+
95
+ // You can specity a type for each operation (select, insert and update)
96
+ // using the `ColumnType<SelectType, InsertType, UpdateType>` wrapper.
97
+ // Here we define a column `modified_at` that is selected as a `Date`,
98
+ // can optionally be provided as a `string` in inserts and can never
99
+ // be updated:
100
+ modified_at: ColumnType<Date, string | undefined, never>
77
101
  }
78
102
 
79
- interface Pet {
80
- id: number
103
+ interface PetTable {
104
+ id: Generated<number>
81
105
  name: string
82
106
  owner_id: number
83
107
  species: 'dog' | 'cat'
84
108
  }
85
109
 
86
- interface Movie {
87
- id: string
110
+ interface MovieTable {
111
+ id: Generated<string>
88
112
  stars: number
89
113
  }
90
114
 
91
115
  // Keys of this interface are table names.
92
116
  interface Database {
93
- person: Person
94
- pet: Pet
95
- movie: Movie
117
+ person: PersonTable
118
+ pet: PetTable
119
+ movie: MovieTable
96
120
  }
97
121
 
98
122
  // You'd create one of these when you start your app.
@@ -101,15 +125,26 @@ const db = new Kysely<Database>({
101
125
  dialect: new PostgresDialect({
102
126
  host: 'localhost',
103
127
  database: 'kysely_test',
104
- })
128
+ }),
105
129
  })
106
130
 
107
131
  async function demo() {
132
+ const { id } = await db
133
+ .insertInto('person')
134
+ .values({ first_name: 'Jennifer', gender: 'female' })
135
+ .returning('id')
136
+ .executeTakeFirstOrThrow()
137
+
138
+ await db
139
+ .insertInto('pet')
140
+ .values({ name: 'Catto', species: 'cat', owner_id: id })
141
+ .execute()
142
+
108
143
  const person = await db
109
144
  .selectFrom('person')
110
145
  .innerJoin('pet', 'pet.owner_id', 'person.id')
111
146
  .select(['first_name', 'pet.name as pet_name'])
112
- .where('person.id', '=', 1)
147
+ .where('person.id', '=', id)
113
148
  .executeTakeFirst()
114
149
 
115
150
  if (person) {
@@ -118,6 +153,14 @@ async function demo() {
118
153
  }
119
154
  ```
120
155
 
156
+ ```ts
157
+ // You can extract the select, insert and update interfaces like this
158
+ // if you want (you don't need to):
159
+ type Person = Selectable<PersonTable>
160
+ type InsertablePerson = Insertable<PersonTable>
161
+ type UpdateablePerson = Updateable<PersonTable>
162
+ ```
163
+
121
164
  # Query examples
122
165
 
123
166
  ## Select queries
@@ -248,37 +291,54 @@ export async function down(db: Kysely<any>): Promise<void> {
248
291
  You can then use
249
292
 
250
293
  ```ts
251
- await db.migration.migrateToLatest(pathToMigrationsFolder)
294
+ const migrator = new Migrator(migratorConfig);
295
+ await migrator.migrateToLatest(pathToMigrationsFolder)
252
296
  ```
253
297
 
254
298
  to run all migrations that have not yet been run. The migrations are executed in alphabetical
255
- order by their name. See the [migration module](https://koskimas.github.io/kysely/classes/MigrationModule.html)
299
+ order by their name. See the [Migrator](https://koskimas.github.io/kysely/classes/Migrator.html)
256
300
  documentation for more info.
257
301
 
258
302
  Kysely doesn't have a CLI for running migrations and probably never will. This is because Kysely's
259
303
  migrations are also written in typescript. To run the migrations, you need to first build the
260
- typescript code into javascript. The CLI would cause confusion over which migrations are being
304
+ typescript code into javascript. A CLI would cause confusion over which migrations are being
261
305
  run, the typescript ones or the javascript ones. If we added support for both, the CLI would
262
306
  need to depend on a typescript compiler, which most production environments don't (and shouldn't)
263
307
  have. You will probably want to add a simple migration script to your projects like this:
264
308
 
265
309
  ```ts
266
- import path from 'path'
310
+ import * as path from 'path'
311
+ import * as fs from 'fs/promises'
267
312
 
268
- // This example assumes you have a file named `database.ts` that
269
- // creates and exports a `Kysely` instance `db`. You can just
270
- // as well create a new `Kysely` instance in the function below
271
- // or do something completely different to obtain an instance
272
- // of `Kysely`.
273
- import { db } from './database'
313
+ import {
314
+ Kysely,
315
+ Migrator,
316
+ PostgresDialect,
317
+ FileMigrationProvider
318
+ } from 'kysely'
274
319
 
275
320
  async function migrateToLatest() {
276
- const { error, results } = await db.migration.migrateToLatest(
277
- path.join(__dirname, 'migrations')
278
- )
321
+ const db = new Kysely<Database>({
322
+ dialect: new PostgresDialect({
323
+ host: 'localhost',
324
+ database: 'kysely_test',
325
+ }),
326
+ })
327
+
328
+ const migrator = new Migrator({
329
+ db,
330
+ // The constructor signature of FileMigrationProvider is a
331
+ // bit weird to keep Kysely independent of node.js or any
332
+ // other environment.
333
+ provider: new FileMigrationProvider(
334
+ fs.readdir,
335
+ path.join,
336
+ // Path to the folder that contains all your migrations.
337
+ 'migrations'
338
+ )
339
+ })
279
340
 
280
- // Destroy the `Kysely` instance to make the script exit faster.
281
- await db.destroy()
341
+ const { error, results } = await migrator.migrateToLatest()
282
342
 
283
343
  results?.forEach((it) => {
284
344
  if (it.status === 'Success') {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MysqlIntrospector = void 0;
4
- const migration_js_1 = require("../../migration/migration.js");
4
+ const migrator_js_1 = require("../../migration/migrator.js");
5
5
  const object_utils_js_1 = require("../../util/object-utils.js");
6
6
  class MysqlIntrospector {
7
7
  #db;
@@ -16,8 +16,8 @@ class MysqlIntrospector {
16
16
  .castTo();
17
17
  if (!options.withInternalKyselyTables) {
18
18
  query = query
19
- .where('table_name', '!=', migration_js_1.MIGRATION_TABLE)
20
- .where('table_name', '!=', migration_js_1.MIGRATION_LOCK_TABLE);
19
+ .where('table_name', '!=', migrator_js_1.MIGRATION_TABLE)
20
+ .where('table_name', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
21
21
  }
22
22
  const rawColumns = await query.execute();
23
23
  return {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresIntrospector = void 0;
4
- const migration_js_1 = require("../../migration/migration.js");
4
+ const migrator_js_1 = require("../../migration/migrator.js");
5
5
  const object_utils_js_1 = require("../../util/object-utils.js");
6
6
  class PostgresIntrospector {
7
7
  #db;
@@ -28,8 +28,8 @@ class PostgresIntrospector {
28
28
  .castTo();
29
29
  if (!options.withInternalKyselyTables) {
30
30
  query = query
31
- .where('t.tablename', '!=', migration_js_1.MIGRATION_TABLE)
32
- .where('t.tablename', '!=', migration_js_1.MIGRATION_LOCK_TABLE);
31
+ .where('t.tablename', '!=', migrator_js_1.MIGRATION_TABLE)
32
+ .where('t.tablename', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
33
33
  }
34
34
  const rawColumns = await query.execute();
35
35
  return {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteIntrospector = void 0;
4
- const migration_js_1 = require("../../migration/migration.js");
4
+ const migrator_js_1 = require("../../migration/migrator.js");
5
5
  class SqliteIntrospector {
6
6
  #db;
7
7
  constructor(db) {
@@ -16,8 +16,8 @@ class SqliteIntrospector {
16
16
  .castTo();
17
17
  if (!options.withInternalKyselyTables) {
18
18
  query = query
19
- .where('name', '!=', migration_js_1.MIGRATION_TABLE)
20
- .where('name', '!=', migration_js_1.MIGRATION_LOCK_TABLE);
19
+ .where('name', '!=', migrator_js_1.MIGRATION_TABLE)
20
+ .where('name', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
21
21
  }
22
22
  const tables = await query.execute();
23
23
  return {
@@ -57,7 +57,8 @@ export * from './dialect/sqlite/sqlite-introspector.js';
57
57
  export * from './dialect/sqlite/sqlite-adapter.js';
58
58
  export * from './query-compiler/default-query-compiler.js';
59
59
  export * from './query-compiler/query-compiler.js';
60
- export * from './migration/migration.js';
60
+ export * from './migration/migrator.js';
61
+ export * from './migration/file-migration-provider.js';
61
62
  export * from './dialect/dialect.js';
62
63
  export * from './dialect/dialect-adapter.js';
63
64
  export * from './dialect/dialect-adapter-base.js';
@@ -138,6 +139,7 @@ export * from './operation-node/values-node.js';
138
139
  export * from './operation-node/where-node.js';
139
140
  export * from './operation-node/with-node.js';
140
141
  export * from './dialect/database-introspector.js';
142
+ export * from './util/column-type.js';
141
143
  export * from './util/compilable.js';
142
144
  export * from './util/log.js';
143
145
  export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
package/dist/cjs/index.js CHANGED
@@ -69,7 +69,8 @@ __exportStar(require("./dialect/sqlite/sqlite-introspector.js"), exports);
69
69
  __exportStar(require("./dialect/sqlite/sqlite-adapter.js"), exports);
70
70
  __exportStar(require("./query-compiler/default-query-compiler.js"), exports);
71
71
  __exportStar(require("./query-compiler/query-compiler.js"), exports);
72
- __exportStar(require("./migration/migration.js"), exports);
72
+ __exportStar(require("./migration/migrator.js"), exports);
73
+ __exportStar(require("./migration/file-migration-provider.js"), exports);
73
74
  __exportStar(require("./dialect/dialect.js"), exports);
74
75
  __exportStar(require("./dialect/dialect-adapter.js"), exports);
75
76
  __exportStar(require("./dialect/dialect-adapter-base.js"), exports);
@@ -150,5 +151,6 @@ __exportStar(require("./operation-node/values-node.js"), exports);
150
151
  __exportStar(require("./operation-node/where-node.js"), exports);
151
152
  __exportStar(require("./operation-node/with-node.js"), exports);
152
153
  __exportStar(require("./dialect/database-introspector.js"), exports);
154
+ __exportStar(require("./util/column-type.js"), exports);
153
155
  __exportStar(require("./util/compilable.js"), exports);
154
156
  __exportStar(require("./util/log.js"), exports);
@@ -1,16 +1,16 @@
1
1
  import { Dialect } from './dialect/dialect.js';
2
2
  import { SchemaModule } from './schema/schema.js';
3
3
  import { DynamicModule } from './dynamic/dynamic.js';
4
- import { MigrationModule } from './migration/migration.js';
5
4
  import { QueryExecutor } from './query-executor/query-executor.js';
6
5
  import { QueryCreator } from './query-creator.js';
7
6
  import { KyselyPlugin } from './plugin/kysely-plugin.js';
8
- import { GeneratedPlaceholder } from './util/type-utils.js';
9
7
  import { DatabaseIntrospector } from './dialect/database-introspector.js';
10
8
  import { Driver, IsolationLevel } from './driver/driver.js';
11
9
  import { ParseContext } from './parser/parse-context.js';
12
10
  import { FunctionBuilder } from './query-builder/function-builder.js';
13
11
  import { LogConfig } from './util/log.js';
12
+ import { PRIVATE_ADAPTER } from './util/private-symbols.js';
13
+ import { DialectAdapter } from './dialect/dialect-adapter.js';
14
14
  /**
15
15
  * The main Kysely class.
16
16
  *
@@ -60,10 +60,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
60
60
  * Returns the {@link SchemaModule} module for building database schema.
61
61
  */
62
62
  get schema(): SchemaModule;
63
- /**
64
- * Returns the {@link MigrationModule} module for managing and running migrations.
65
- */
66
- get migration(): MigrationModule;
67
63
  /**
68
64
  * Returns a the {@link DynamicModule} module.
69
65
  *
@@ -75,31 +71,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
75
71
  * Returns a {@link DatabaseIntrospector | database introspector}.
76
72
  */
77
73
  get introspection(): DatabaseIntrospector;
78
- /**
79
- * A value to be used in place of columns that are generated in the database
80
- * when inserting rows.
81
- *
82
- * ### Examples
83
- *
84
- * In this example the `Person` table has non-null properties `id` and `created_at`
85
- * which are both automatically genereted by the database. Since their types are
86
- * `number` and `string` respectively instead of `number | null` and `string | null`
87
- * the `values` method requires you to give a value for them. the `generated`
88
- * placeholder can be used in these cases.
89
- *
90
- * ```ts
91
- * await db.insertInto('person')
92
- * .values({
93
- * id: db.generated,
94
- * created_at: db.generated,
95
- * first_name: 'Jennifer',
96
- * last_name: 'Aniston',
97
- * gender: 'female'
98
- * })
99
- * .execute()
100
- * ```
101
- */
102
- get generated(): GeneratedPlaceholder;
103
74
  /**
104
75
  * Returns a {@link FunctionBuilder} that can be used to write type safe function
105
76
  * calls.
@@ -149,7 +120,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
149
120
  * const catto = await db.transaction().execute(async (trx) => {
150
121
  * const jennifer = await trx.insertInto('person')
151
122
  * .values({
152
- * id: db.generated,
153
123
  * first_name: 'Jennifer',
154
124
  * last_name: 'Aniston',
155
125
  * })
@@ -160,7 +130,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
160
130
  *
161
131
  * return await trx.insertInto('pet')
162
132
  * .values({
163
- * id: db.generated,
164
133
  * user_id: jennifer.id,
165
134
  * name: 'Catto',
166
135
  * species: 'cat'
@@ -251,6 +220,11 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
251
220
  * You can also use `db instanceof Transaction`.
252
221
  */
253
222
  get isTransaction(): boolean;
223
+ /**
224
+ * @internal
225
+ * @private
226
+ */
227
+ get [PRIVATE_ADAPTER](): DialectAdapter;
254
228
  }
255
229
  export declare class Transaction<DB> extends Kysely<DB> {
256
230
  #private;
@@ -261,10 +235,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
261
235
  * You can also use `db instanceof Transaction`.
262
236
  */
263
237
  get isTransaction(): true;
264
- /**
265
- * Returns the {@link MigrationModule} module for managing and running migrations.
266
- */
267
- get migration(): MigrationModule;
268
238
  /**
269
239
  * Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
270
240
  *
@@ -285,7 +255,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
285
255
  * const catto = await db.transaction().execute(async (trx) => {
286
256
  * const jennifer = await trx.insertInto('person')
287
257
  * .values({
288
- * id: db.generated,
289
258
  * first_name: 'Jennifer',
290
259
  * last_name: 'Aniston',
291
260
  * })
@@ -296,7 +265,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
296
265
  *
297
266
  * return await trx.insertInto('pet')
298
267
  * .values({
299
- * id: db.generated,
300
268
  * user_id: jennifer.id,
301
269
  * name: 'Catto',
302
270
  * species: 'cat'
@@ -4,9 +4,7 @@ exports.TransactionBuilder = exports.ConnectionBuilder = exports.isKyselyProps =
4
4
  const schema_js_1 = require("./schema/schema.js");
5
5
  const dynamic_js_1 = require("./dynamic/dynamic.js");
6
6
  const default_connection_provider_js_1 = require("./driver/default-connection-provider.js");
7
- const migration_js_1 = require("./migration/migration.js");
8
7
  const query_creator_js_1 = require("./query-creator.js");
9
- const generated_placeholder_js_1 = require("./util/generated-placeholder.js");
10
8
  const default_query_executor_js_1 = require("./query-executor/default-query-executor.js");
11
9
  const object_utils_js_1 = require("./util/object-utils.js");
12
10
  const runtime_driver_js_1 = require("./driver/runtime-driver.js");
@@ -16,6 +14,7 @@ const prevent_await_js_1 = require("./util/prevent-await.js");
16
14
  const parse_context_js_1 = require("./parser/parse-context.js");
17
15
  const function_builder_js_1 = require("./query-builder/function-builder.js");
18
16
  const log_js_1 = require("./util/log.js");
17
+ const private_symbols_js_1 = require("./util/private-symbols.js");
19
18
  /**
20
19
  * The main Kysely class.
21
20
  *
@@ -90,12 +89,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
90
89
  get schema() {
91
90
  return new schema_js_1.SchemaModule(this.#props.executor);
92
91
  }
93
- /**
94
- * Returns the {@link MigrationModule} module for managing and running migrations.
95
- */
96
- get migration() {
97
- return new migration_js_1.MigrationModule(this, this.#props.parseContext.adapter);
98
- }
99
92
  /**
100
93
  * Returns a the {@link DynamicModule} module.
101
94
  *
@@ -111,33 +104,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
111
104
  get introspection() {
112
105
  return this.#props.dialect.createIntrospector(this.withoutPlugins());
113
106
  }
114
- /**
115
- * A value to be used in place of columns that are generated in the database
116
- * when inserting rows.
117
- *
118
- * ### Examples
119
- *
120
- * In this example the `Person` table has non-null properties `id` and `created_at`
121
- * which are both automatically genereted by the database. Since their types are
122
- * `number` and `string` respectively instead of `number | null` and `string | null`
123
- * the `values` method requires you to give a value for them. the `generated`
124
- * placeholder can be used in these cases.
125
- *
126
- * ```ts
127
- * await db.insertInto('person')
128
- * .values({
129
- * id: db.generated,
130
- * created_at: db.generated,
131
- * first_name: 'Jennifer',
132
- * last_name: 'Aniston',
133
- * gender: 'female'
134
- * })
135
- * .execute()
136
- * ```
137
- */
138
- get generated() {
139
- return generated_placeholder_js_1.GENERATED_PLACEHOLDER;
140
- }
141
107
  /**
142
108
  * Returns a {@link FunctionBuilder} that can be used to write type safe function
143
109
  * calls.
@@ -189,7 +155,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
189
155
  * const catto = await db.transaction().execute(async (trx) => {
190
156
  * const jennifer = await trx.insertInto('person')
191
157
  * .values({
192
- * id: db.generated,
193
158
  * first_name: 'Jennifer',
194
159
  * last_name: 'Aniston',
195
160
  * })
@@ -200,7 +165,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
200
165
  *
201
166
  * return await trx.insertInto('pet')
202
167
  * .values({
203
- * id: db.generated,
204
168
  * user_id: jennifer.id,
205
169
  * name: 'Catto',
206
170
  * species: 'cat'
@@ -311,6 +275,13 @@ class Kysely extends query_creator_js_1.QueryCreator {
311
275
  get isTransaction() {
312
276
  return false;
313
277
  }
278
+ /**
279
+ * @internal
280
+ * @private
281
+ */
282
+ get [private_symbols_js_1.PRIVATE_ADAPTER]() {
283
+ return this.#props.parseContext.adapter;
284
+ }
314
285
  }
315
286
  exports.Kysely = Kysely;
316
287
  class Transaction extends Kysely {
@@ -325,9 +296,6 @@ class Transaction extends Kysely {
325
296
  get isTransaction() {
326
297
  return true;
327
298
  }
328
- get migration() {
329
- throw new Error('the migration module is not available for a transaction. Use the main Kysely instance to run migrations');
330
- }
331
299
  transaction() {
332
300
  throw new Error('calling the transaction method for a Transaction is not supported');
333
301
  }
@@ -0,0 +1,52 @@
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
+ /**
17
+ * Reads all migrations from a folder.
18
+ *
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
+ * ### Examples
24
+ *
25
+ * ```ts
26
+ * import * as path from 'path'
27
+ * import * as fs from 'fs/promises'
28
+ *
29
+ * new FileMigrationProvider(
30
+ * fs.readdir,
31
+ * path.join,
32
+ * path.join(__dirname, 'migrations')
33
+ * )
34
+ * ```
35
+ */
36
+ export declare class FileMigrationProvider implements MigrationProvider {
37
+ #private;
38
+ constructor(readDir: ReadDir, joinPath: JoinPath, migrationFolderPath: string);
39
+ /**
40
+ * Returns all migrations, old and new.
41
+ *
42
+ * For example if you have your migrations in a folder as separate files,
43
+ * you can use the {@link FileMigrationProvider} that implements this
44
+ * method to return all migrations in a folder.
45
+ *
46
+ * The keys of the returned object are migration names and values are the
47
+ * migrations. The order of the migrations is determined by the alphabetical
48
+ * order of the migration names. The items in the object don't need to be
49
+ * sorted, they are sorted by Kysely.
50
+ */
51
+ getMigrations(): Promise<Record<string, Migration>>;
52
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileMigrationProvider = void 0;
4
+ const object_utils_js_1 = require("../util/object-utils.js");
5
+ /**
6
+ * Reads all migrations from a folder.
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
+ * ### Examples
13
+ *
14
+ * ```ts
15
+ * import * as path from 'path'
16
+ * import * as fs from 'fs/promises'
17
+ *
18
+ * new FileMigrationProvider(
19
+ * fs.readdir,
20
+ * path.join,
21
+ * path.join(__dirname, 'migrations')
22
+ * )
23
+ * ```
24
+ */
25
+ class FileMigrationProvider {
26
+ #readDir;
27
+ #joinPath;
28
+ #migrationFolderPath;
29
+ constructor(readDir, joinPath, migrationFolderPath) {
30
+ this.#readDir = readDir;
31
+ this.#joinPath = joinPath;
32
+ this.#migrationFolderPath = migrationFolderPath;
33
+ }
34
+ async getMigrations() {
35
+ const migrations = {};
36
+ const files = await this.#readDir(this.#migrationFolderPath);
37
+ for (const fileName of files) {
38
+ if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
39
+ !fileName.endsWith('.d.ts')) {
40
+ const migration = await Promise.resolve().then(() => require(this.#joinPath(this.#migrationFolderPath, fileName)));
41
+ if (isMigration(migration)) {
42
+ migrations[fileName.substring(0, fileName.length - 3)] = migration;
43
+ }
44
+ }
45
+ }
46
+ return migrations;
47
+ }
48
+ }
49
+ exports.FileMigrationProvider = FileMigrationProvider;
50
+ function isMigration(obj) {
51
+ return (0, object_utils_js_1.isObject)(obj) && (0, object_utils_js_1.isFunction)(obj.up);
52
+ }