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
@@ -163,7 +163,7 @@ class OnConflictBuilder {
163
163
  * ```ts
164
164
  * await db
165
165
  * .insertInto('person')
166
- * .values({ id: db.generated, first_name, pic })
166
+ * .values({ first_name, pic })
167
167
  * .onConflict((oc) => oc
168
168
  * .column('pic')
169
169
  * .doNothing()
@@ -194,7 +194,7 @@ class OnConflictBuilder {
194
194
  * ```ts
195
195
  * await db
196
196
  * .insertInto('person')
197
- * .values({ id: db.generated, first_name, pic })
197
+ * .values({ first_name, pic })
198
198
  * .onConflict((oc) => oc
199
199
  * .column('pic')
200
200
  * .doUpdateSet({ first_name })
@@ -21,7 +21,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
21
21
  * const { id } = await db
22
22
  * .insertInto('person')
23
23
  * .values({
24
- * id: db.generated,
25
24
  * first_name: 'Jennifer',
26
25
  * last_name: 'Aniston'
27
26
  * })
@@ -35,7 +34,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
35
34
  * const { id, first_name } = await db
36
35
  * .insertInto('person')
37
36
  * .values({
38
- * id: db.generated,
39
37
  * first_name: 'Jennifer',
40
38
  * last_name: 'Aniston'
41
39
  * })
@@ -51,7 +49,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
51
49
  * const { id, full_name, first_pet_id } = await db
52
50
  * .insertInto('person')
53
51
  * .values({
54
- * id: db.generated,
55
52
  * first_name: 'Jennifer',
56
53
  * last_name: 'Aniston'
57
54
  * })
@@ -626,7 +626,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
626
626
  * const { id } = await db
627
627
  * .insertInto('person')
628
628
  * .values({
629
- * id: db.generated,
630
629
  * first_name: 'Jennifer',
631
630
  * last_name: 'Aniston'
632
631
  * })
@@ -640,7 +639,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
640
639
  * const { id, first_name } = await db
641
640
  * .insertInto('person')
642
641
  * .values({
643
- * id: db.generated,
644
642
  * first_name: 'Jennifer',
645
643
  * last_name: 'Aniston'
646
644
  * })
@@ -656,7 +654,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
656
654
  * const { id, full_name, first_pet_id } = await db
657
655
  * .insertInto('person')
658
656
  * .values({
659
- * id: db.generated,
660
657
  * first_name: 'Jennifer',
661
658
  * last_name: 'Aniston'
662
659
  * })
@@ -137,7 +137,6 @@ export declare class QueryCreator<DB> {
137
137
  * const result = await db
138
138
  * .insertInto('person')
139
139
  * .values({
140
- * id: db.generated,
141
140
  * first_name: 'Jennifer',
142
141
  * last_name: 'Aniston'
143
142
  * })
@@ -152,7 +151,6 @@ export declare class QueryCreator<DB> {
152
151
  * const { id } = await db
153
152
  * .insertInto('person')
154
153
  * .values({
155
- * id: db.generated,
156
154
  * first_name: 'Jennifer',
157
155
  * last_name: 'Aniston'
158
156
  * })
@@ -46,7 +46,6 @@ class QueryCreator {
46
46
  * const result = await db
47
47
  * .insertInto('person')
48
48
  * .values({
49
- * id: db.generated,
50
49
  * first_name: 'Jennifer',
51
50
  * last_name: 'Aniston'
52
51
  * })
@@ -61,7 +60,6 @@ class QueryCreator {
61
60
  * const { id } = await db
62
61
  * .insertInto('person')
63
62
  * .values({
64
- * id: db.generated,
65
63
  * first_name: 'Jennifer',
66
64
  * last_name: 'Aniston'
67
65
  * })
@@ -0,0 +1,165 @@
1
+ /**
2
+ * This type can be used to specify a different type for
3
+ * select, insert and update operations.
4
+ *
5
+ * Also see the {@link Generated} type.
6
+ *
7
+ * ### Examples
8
+ *
9
+ * The next example defines a number column that is optional
10
+ * in inserts and updates. All columns are always optional
11
+ * in updates so therefore we don't need to specify `undefined`
12
+ * for the update type. The type below is useful for all kinds of
13
+ * database generated columns like identifiers. The `Generated`
14
+ * type is actually just a shortcut for the type in this example:
15
+ *
16
+ * ```ts
17
+ * ColumnType<number, number | undefined, number>
18
+ * ```
19
+ *
20
+ * The above example makes the column optional in inserts
21
+ * and updates, but you can still choose to provide the
22
+ * column. If you want to prevent insertion/update you
23
+ * can se the type as `never`:
24
+ *
25
+ * ```ts
26
+ * ColumnType<number, never, never>
27
+ * ```
28
+ *
29
+ * Here's one more example where the type is different
30
+ * for each different operation:
31
+ *
32
+ * ```ts
33
+ * ColumnType<Date, string, never>
34
+ * ```
35
+ */
36
+ export declare type ColumnType<SelectType, InsertType = SelectType, UpdateType = SelectType> = {
37
+ readonly __select__: SelectType;
38
+ readonly __insert__: InsertType;
39
+ readonly __update__: UpdateType;
40
+ };
41
+ /**
42
+ * A shortcut for defining database-generated columns. The type
43
+ * is the same for all selects, inserts and updates but the
44
+ * column is optional for inserts and updates.
45
+ *
46
+ * This is implemented using {@link ColumnType} like this:
47
+ *
48
+ * ```ts
49
+ * type Generated<S> = ColumnType<S, S | undefined, S>
50
+ * ```
51
+ */
52
+ export declare type Generated<S> = ColumnType<S, S | undefined, S>;
53
+ /**
54
+ * Evaluates to `K` if `T` can be `null` or `undefined`.
55
+ */
56
+ declare type IfNullable<T, K> = undefined extends T ? K : null extends T ? K : never;
57
+ /**
58
+ * Evaluates to `K` if `T` can't be `null` or `undefined`.
59
+ */
60
+ declare type IfNotNullable<T, K> = undefined extends T ? never : null extends T ? never : T extends never ? never : K;
61
+ /**
62
+ * Evaluates to `K` if `T` isn't `never`.
63
+ */
64
+ declare type IfNotNever<T, K> = T extends never ? never : K;
65
+ export declare type SelectType<T> = T extends ColumnType<infer S, any, any> ? S : T;
66
+ export declare type InsertType<T> = T extends ColumnType<any, infer I, any> ? I : T;
67
+ export declare type UpdateType<T> = T extends ColumnType<any, any, infer U> ? U : T;
68
+ /**
69
+ * Keys of `R` whose `InsertType` values can be `null` or `undefined`.
70
+ */
71
+ export declare type NullableInsertKeys<R> = {
72
+ [K in keyof R]: IfNullable<InsertType<R[K]>, K>;
73
+ }[keyof R];
74
+ /**
75
+ * Keys of `R` whose `InsertType` values can't be `null` or `undefined`.
76
+ */
77
+ export declare type NonNullableInsertKeys<R> = {
78
+ [K in keyof R]: IfNotNullable<InsertType<R[K]>, K>;
79
+ }[keyof R];
80
+ /**
81
+ * Keys of `R` whose `SelectType` values are not `never`
82
+ */
83
+ declare type NonNeverSelectKeys<R> = {
84
+ [K in keyof R]: IfNotNever<SelectType<R[K]>, K>;
85
+ }[keyof R];
86
+ /**
87
+ * Keys of `R` whose `UpdateType` values are not `never`
88
+ */
89
+ export declare type UpdateKeys<R> = {
90
+ [K in keyof R]: IfNotNever<UpdateType<R[K]>, K>;
91
+ }[keyof R];
92
+ /**
93
+ * Given a table interface, extracts the select type from all
94
+ * {@link ColumnType} types.
95
+ *
96
+ * ### Examples
97
+ *
98
+ * ```ts
99
+ * interface PersonTable {
100
+ * id: Generated<number>
101
+ * first_name: string
102
+ * modified_at: ColumnType<Date, string, never>
103
+ * }
104
+ *
105
+ * type Person = Selectable<PersonTable>
106
+ * // {
107
+ * // id: number,
108
+ * // first_name: string
109
+ * // modified_at: Date
110
+ * // }
111
+ * ```
112
+ */
113
+ export declare type Selectable<R> = {
114
+ [K in NonNeverSelectKeys<R>]: SelectType<R[K]>;
115
+ };
116
+ /**
117
+ * Given a table interface, extracts the insert type from all
118
+ * {@link ColumnType} types.
119
+ *
120
+ * ### Examples
121
+ *
122
+ * ```ts
123
+ * interface PersonTable {
124
+ * id: Generated<number>
125
+ * first_name: string
126
+ * modified_at: ColumnType<Date, string, never>
127
+ * }
128
+ *
129
+ * type InsertablePerson = Insertable<PersonTable>
130
+ * // {
131
+ * // id?: number,
132
+ * // first_name: string
133
+ * // modified_at: string
134
+ * // }
135
+ * ```
136
+ */
137
+ export declare type Insertable<R> = {
138
+ [K in NonNullableInsertKeys<R>]: InsertType<R[K]>;
139
+ } & {
140
+ [K in NullableInsertKeys<R>]?: InsertType<R[K]>;
141
+ };
142
+ /**
143
+ * Given a table interface, extracts the update type from all
144
+ * {@link ColumnType} types.
145
+ *
146
+ * ### Examples
147
+ *
148
+ * ```ts
149
+ * interface PersonTable {
150
+ * id: Generated<number>
151
+ * first_name: string
152
+ * modified_at: ColumnType<Date, string, never>
153
+ * }
154
+ *
155
+ * type UpdateablePerson = Updateable<PersonTable>
156
+ * // {
157
+ * // id?: number,
158
+ * // first_name?: string
159
+ * // }
160
+ * ```
161
+ */
162
+ export declare type Updateable<R> = {
163
+ [K in UpdateKeys<R>]?: UpdateType<R[K]>;
164
+ };
165
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @internal
3
+ * @private
4
+ */
5
+ export declare const PRIVATE_ADAPTER: unique symbol;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRIVATE_ADAPTER = void 0;
4
+ /**
5
+ * @internal
6
+ * @private
7
+ */
8
+ exports.PRIVATE_ADAPTER = Symbol();
@@ -8,42 +8,6 @@ import { UpdateResult } from '../query-builder/update-result.js';
8
8
  * Given an object type, extracts the union of all value types.
9
9
  */
10
10
  export declare type ValueType<T> = T[keyof T];
11
- /**
12
- * Given a database type and a union of table names returns the row type
13
- * that you would get by selecting all columns from tables TB.
14
- *
15
- * Example:
16
- *
17
- * ```ts
18
- * interface Person {
19
- * id: number
20
- * }
21
- *
22
- * interface Pet {
23
- * name: string
24
- * species: 'cat' | 'dog'
25
- * }
26
- *
27
- * interface Movie {
28
- * stars: number
29
- * }
30
- *
31
- * interface Database {
32
- * person: Person
33
- * pet: Pet
34
- * movie: Movie
35
- * }
36
- *
37
- * type Row = RowType<Database, 'person' | 'movie'>
38
- *
39
- * // Row == Person & Movie
40
- * ```
41
- */
42
- export declare type RowType<DB, TB extends keyof DB> = {
43
- [C in AnyColumn<DB, TB>]: {
44
- [T in TB]: C extends keyof DB[T] ? DB[T][C] : never;
45
- }[TB];
46
- };
47
11
  /**
48
12
  * Given a database type and a union of table names in that db, returns
49
13
  * a union type with all possible column names.
@@ -142,10 +106,6 @@ export declare type SelectQueryBuilderFactory<DB, TB extends keyof DB> = (qb: Ex
142
106
  export declare type AliasedQueryBuilderFactory<DB, TB extends keyof DB> = (qb: ExpressionBuilder<DB, TB>) => AnyAliasedQueryBuilder;
143
107
  export declare type RawBuilderFactory<DB, TB extends keyof DB> = (qb: ExpressionBuilder<DB, TB>) => AnyRawBuilder;
144
108
  export declare type AliasedRawBuilderFactory<DB, TB extends keyof DB> = (qb: ExpressionBuilder<DB, TB>) => AnyAliasedRawBuilder;
145
- export interface GeneratedPlaceholder {
146
- /** @internal */
147
- readonly __isGeneratedPlaceholder__: true;
148
- }
149
109
  export declare type SingleResultType<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O | undefined;
150
110
  export declare type UnknownRow = Record<string, unknown>;
151
111
  export declare type Nullable<T> = {
@@ -1,4 +1,4 @@
1
- import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migration.js';
1
+ import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migrator.js';
2
2
  import { freeze } from '../../util/object-utils.js';
3
3
  export class MysqlIntrospector {
4
4
  #db;
@@ -1,4 +1,4 @@
1
- import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migration.js';
1
+ import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migrator.js';
2
2
  import { freeze } from '../../util/object-utils.js';
3
3
  export class PostgresIntrospector {
4
4
  #db;
@@ -1,4 +1,4 @@
1
- import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migration.js';
1
+ import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migrator.js';
2
2
  export class SqliteIntrospector {
3
3
  #db;
4
4
  constructor(db) {
@@ -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/esm/index.js CHANGED
@@ -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,5 +139,6 @@ 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';
@@ -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'
@@ -1,9 +1,7 @@
1
1
  import { SchemaModule } from './schema/schema.js';
2
2
  import { DynamicModule } from './dynamic/dynamic.js';
3
3
  import { DefaultConnectionProvider } from './driver/default-connection-provider.js';
4
- import { MigrationModule } from './migration/migration.js';
5
4
  import { QueryCreator } from './query-creator.js';
6
- import { GENERATED_PLACEHOLDER } from './util/generated-placeholder.js';
7
5
  import { DefaultQueryExecutor } from './query-executor/default-query-executor.js';
8
6
  import { freeze, isObject } from './util/object-utils.js';
9
7
  import { RuntimeDriver } from './driver/runtime-driver.js';
@@ -13,6 +11,7 @@ import { preventAwait } from './util/prevent-await.js';
13
11
  import { DefaultParseContext } from './parser/parse-context.js';
14
12
  import { FunctionBuilder } from './query-builder/function-builder.js';
15
13
  import { Log } from './util/log.js';
14
+ import { PRIVATE_ADAPTER } from './util/private-symbols.js';
16
15
  /**
17
16
  * The main Kysely class.
18
17
  *
@@ -87,12 +86,6 @@ export class Kysely extends QueryCreator {
87
86
  get schema() {
88
87
  return new SchemaModule(this.#props.executor);
89
88
  }
90
- /**
91
- * Returns the {@link MigrationModule} module for managing and running migrations.
92
- */
93
- get migration() {
94
- return new MigrationModule(this, this.#props.parseContext.adapter);
95
- }
96
89
  /**
97
90
  * Returns a the {@link DynamicModule} module.
98
91
  *
@@ -108,33 +101,6 @@ export class Kysely extends QueryCreator {
108
101
  get introspection() {
109
102
  return this.#props.dialect.createIntrospector(this.withoutPlugins());
110
103
  }
111
- /**
112
- * A value to be used in place of columns that are generated in the database
113
- * when inserting rows.
114
- *
115
- * ### Examples
116
- *
117
- * In this example the `Person` table has non-null properties `id` and `created_at`
118
- * which are both automatically genereted by the database. Since their types are
119
- * `number` and `string` respectively instead of `number | null` and `string | null`
120
- * the `values` method requires you to give a value for them. the `generated`
121
- * placeholder can be used in these cases.
122
- *
123
- * ```ts
124
- * await db.insertInto('person')
125
- * .values({
126
- * id: db.generated,
127
- * created_at: db.generated,
128
- * first_name: 'Jennifer',
129
- * last_name: 'Aniston',
130
- * gender: 'female'
131
- * })
132
- * .execute()
133
- * ```
134
- */
135
- get generated() {
136
- return GENERATED_PLACEHOLDER;
137
- }
138
104
  /**
139
105
  * Returns a {@link FunctionBuilder} that can be used to write type safe function
140
106
  * calls.
@@ -186,7 +152,6 @@ export class Kysely extends QueryCreator {
186
152
  * const catto = await db.transaction().execute(async (trx) => {
187
153
  * const jennifer = await trx.insertInto('person')
188
154
  * .values({
189
- * id: db.generated,
190
155
  * first_name: 'Jennifer',
191
156
  * last_name: 'Aniston',
192
157
  * })
@@ -197,7 +162,6 @@ export class Kysely extends QueryCreator {
197
162
  *
198
163
  * return await trx.insertInto('pet')
199
164
  * .values({
200
- * id: db.generated,
201
165
  * user_id: jennifer.id,
202
166
  * name: 'Catto',
203
167
  * species: 'cat'
@@ -308,6 +272,13 @@ export class Kysely extends QueryCreator {
308
272
  get isTransaction() {
309
273
  return false;
310
274
  }
275
+ /**
276
+ * @internal
277
+ * @private
278
+ */
279
+ get [PRIVATE_ADAPTER]() {
280
+ return this.#props.parseContext.adapter;
281
+ }
311
282
  }
312
283
  export class Transaction extends Kysely {
313
284
  #props;
@@ -321,9 +292,6 @@ export class Transaction extends Kysely {
321
292
  get isTransaction() {
322
293
  return true;
323
294
  }
324
- get migration() {
325
- throw new Error('the migration module is not available for a transaction. Use the main Kysely instance to run migrations');
326
- }
327
295
  transaction() {
328
296
  throw new Error('calling the transaction method for a Transaction is not supported');
329
297
  }
@@ -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
+ }