kysely 0.13.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -32
- package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/cjs/dialect/dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/kysely.d.ts +8 -40
- package/dist/cjs/kysely.js +8 -40
- package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
- package/dist/cjs/migration/file-migration-provider.js +52 -0
- package/dist/{esm/migration/migration.d.ts → cjs/migration/migrator.d.ts} +159 -134
- package/dist/cjs/migration/{migration.js → migrator.js} +166 -57
- package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/cjs/operation-node/check-constraint-node.js +2 -3
- package/dist/cjs/operation-node/column-definition-node.d.ts +2 -2
- package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
- package/dist/cjs/operation-node/generated-node.d.ts +20 -0
- package/dist/cjs/operation-node/generated-node.js +31 -0
- package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/cjs/operation-node/on-conflict-node.js +39 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -5
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
- package/dist/cjs/parser/insert-values-parser.js +2 -3
- package/dist/cjs/parser/reference-parser.d.ts +4 -3
- package/dist/cjs/parser/select-parser.d.ts +10 -4
- package/dist/cjs/parser/update-set-parser.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/cjs/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/cjs/query-builder/insert-query-builder.js +145 -15
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -4
- package/dist/cjs/query-builder/select-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/update-query-builder.d.ts +2 -4
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +33 -7
- package/dist/cjs/query-creator.d.ts +0 -2
- package/dist/cjs/query-creator.js +0 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +29 -9
- package/dist/cjs/schema/alter-table-builder.js +33 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +28 -8
- package/dist/cjs/schema/column-definition-builder.js +17 -7
- package/dist/cjs/schema/create-index-builder.d.ts +3 -2
- package/dist/cjs/schema/create-index-builder.js +2 -2
- package/dist/cjs/schema/create-table-builder.d.ts +3 -2
- package/dist/cjs/schema/create-table-builder.js +2 -2
- package/dist/cjs/util/column-type.d.ts +165 -0
- package/dist/cjs/util/column-type.js +2 -0
- package/dist/cjs/util/private-symbols.d.ts +5 -0
- package/dist/cjs/util/private-symbols.js +8 -0
- package/dist/cjs/util/type-utils.d.ts +6 -42
- package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +6 -3
- package/dist/esm/kysely.d.ts +8 -40
- package/dist/esm/kysely.js +8 -40
- package/dist/esm/migration/file-migration-provider.d.ts +52 -0
- package/dist/esm/migration/file-migration-provider.js +48 -0
- package/dist/{cjs/migration/migration.d.ts → esm/migration/migrator.d.ts} +159 -134
- package/dist/esm/migration/{migration.js → migrator.js} +165 -56
- package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/esm/operation-node/check-constraint-node.js +2 -3
- package/dist/esm/operation-node/column-definition-node.d.ts +2 -2
- package/dist/esm/operation-node/data-type-node.d.ts +1 -1
- package/dist/esm/operation-node/generated-node.d.ts +20 -0
- package/dist/esm/operation-node/generated-node.js +28 -0
- package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/esm/operation-node/on-conflict-node.js +39 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +11 -5
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-visitor.js +1 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/parser/insert-values-parser.d.ts +4 -4
- package/dist/esm/parser/insert-values-parser.js +2 -3
- package/dist/esm/parser/reference-parser.d.ts +4 -3
- package/dist/esm/parser/select-parser.d.ts +10 -4
- package/dist/esm/parser/update-set-parser.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/esm/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/esm/query-builder/insert-query-builder.js +145 -15
- package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-builder/returning-interface.d.ts +2 -4
- package/dist/esm/query-builder/select-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/update-query-builder.d.ts +2 -4
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +33 -7
- package/dist/esm/query-creator.d.ts +0 -2
- package/dist/esm/query-creator.js +0 -2
- package/dist/esm/schema/alter-table-builder.d.ts +29 -9
- package/dist/esm/schema/alter-table-builder.js +33 -9
- package/dist/esm/schema/column-definition-builder.d.ts +28 -8
- package/dist/esm/schema/column-definition-builder.js +17 -7
- package/dist/esm/schema/create-index-builder.d.ts +3 -2
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/schema/create-table-builder.d.ts +3 -2
- package/dist/esm/schema/create-table-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +165 -0
- package/dist/esm/util/column-type.js +1 -0
- package/dist/esm/util/private-symbols.d.ts +5 -0
- package/dist/esm/util/private-symbols.js +5 -0
- package/dist/esm/util/type-utils.d.ts +6 -42
- package/package.json +1 -1
- package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
- package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
- package/dist/cjs/parser/on-conflict-parser.js +0 -35
- package/dist/cjs/util/generated-placeholder.d.ts +0 -3
- package/dist/cjs/util/generated-placeholder.js +0 -11
- package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/esm/operation-node/generated-always-as-node.js +0 -22
- package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
- package/dist/esm/parser/on-conflict-parser.js +0 -30
- package/dist/esm/util/generated-placeholder.d.ts +0 -3
- package/dist/esm/util/generated-placeholder.js +0 -7
package/dist/esm/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './query-builder/function-builder.js';
|
|
|
15
15
|
export * from './query-builder/insert-result.js';
|
|
16
16
|
export * from './query-builder/delete-result.js';
|
|
17
17
|
export * from './query-builder/update-result.js';
|
|
18
|
+
export * from './query-builder/on-conflict-builder.js';
|
|
18
19
|
export * from './raw-builder/raw-builder.js';
|
|
19
20
|
export * from './query-executor/query-executor.js';
|
|
20
21
|
export * from './query-executor/default-query-executor.js';
|
|
@@ -56,7 +57,8 @@ export * from './dialect/sqlite/sqlite-introspector.js';
|
|
|
56
57
|
export * from './dialect/sqlite/sqlite-adapter.js';
|
|
57
58
|
export * from './query-compiler/default-query-compiler.js';
|
|
58
59
|
export * from './query-compiler/query-compiler.js';
|
|
59
|
-
export * from './migration/
|
|
60
|
+
export * from './migration/migrator.js';
|
|
61
|
+
export * from './migration/file-migration-provider.js';
|
|
60
62
|
export * from './dialect/dialect.js';
|
|
61
63
|
export * from './dialect/dialect-adapter.js';
|
|
62
64
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -91,7 +93,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
91
93
|
export * from './operation-node/filter-node.js';
|
|
92
94
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
93
95
|
export * from './operation-node/from-node.js';
|
|
94
|
-
export * from './operation-node/generated-
|
|
96
|
+
export * from './operation-node/generated-node.js';
|
|
95
97
|
export * from './operation-node/group-by-item-node.js';
|
|
96
98
|
export * from './operation-node/group-by-node.js';
|
|
97
99
|
export * from './operation-node/having-node.js';
|
|
@@ -136,7 +138,8 @@ export * from './operation-node/value-node.js';
|
|
|
136
138
|
export * from './operation-node/values-node.js';
|
|
137
139
|
export * from './operation-node/where-node.js';
|
|
138
140
|
export * from './operation-node/with-node.js';
|
|
139
|
-
export * from './
|
|
141
|
+
export * from './dialect/database-introspector.js';
|
|
142
|
+
export * from './util/column-type.js';
|
|
140
143
|
export * from './util/compilable.js';
|
|
141
144
|
export * from './util/log.js';
|
|
142
145
|
export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from './query-builder/function-builder.js';
|
|
|
15
15
|
export * from './query-builder/insert-result.js';
|
|
16
16
|
export * from './query-builder/delete-result.js';
|
|
17
17
|
export * from './query-builder/update-result.js';
|
|
18
|
+
export * from './query-builder/on-conflict-builder.js';
|
|
18
19
|
export * from './raw-builder/raw-builder.js';
|
|
19
20
|
export * from './query-executor/query-executor.js';
|
|
20
21
|
export * from './query-executor/default-query-executor.js';
|
|
@@ -56,7 +57,8 @@ export * from './dialect/sqlite/sqlite-introspector.js';
|
|
|
56
57
|
export * from './dialect/sqlite/sqlite-adapter.js';
|
|
57
58
|
export * from './query-compiler/default-query-compiler.js';
|
|
58
59
|
export * from './query-compiler/query-compiler.js';
|
|
59
|
-
export * from './migration/
|
|
60
|
+
export * from './migration/migrator.js';
|
|
61
|
+
export * from './migration/file-migration-provider.js';
|
|
60
62
|
export * from './dialect/dialect.js';
|
|
61
63
|
export * from './dialect/dialect-adapter.js';
|
|
62
64
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -91,7 +93,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
91
93
|
export * from './operation-node/filter-node.js';
|
|
92
94
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
93
95
|
export * from './operation-node/from-node.js';
|
|
94
|
-
export * from './operation-node/generated-
|
|
96
|
+
export * from './operation-node/generated-node.js';
|
|
95
97
|
export * from './operation-node/group-by-item-node.js';
|
|
96
98
|
export * from './operation-node/group-by-node.js';
|
|
97
99
|
export * from './operation-node/having-node.js';
|
|
@@ -136,6 +138,7 @@ export * from './operation-node/value-node.js';
|
|
|
136
138
|
export * from './operation-node/values-node.js';
|
|
137
139
|
export * from './operation-node/where-node.js';
|
|
138
140
|
export * from './operation-node/with-node.js';
|
|
139
|
-
export * from './
|
|
141
|
+
export * from './dialect/database-introspector.js';
|
|
142
|
+
export * from './util/column-type.js';
|
|
140
143
|
export * from './util/compilable.js';
|
|
141
144
|
export * from './util/log.js';
|
package/dist/esm/kysely.d.ts
CHANGED
|
@@ -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 {
|
|
9
|
-
import { DatabaseIntrospector } from './introspection/database-introspector.js';
|
|
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'
|
package/dist/esm/kysely.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isFunction, isObject } from '../util/object-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads all migrations from a folder.
|
|
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
|
+
* ### Examples
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as path from 'path'
|
|
13
|
+
* import * as fs from 'fs/promises'
|
|
14
|
+
*
|
|
15
|
+
* new FileMigrationProvider(
|
|
16
|
+
* fs.readdir,
|
|
17
|
+
* path.join,
|
|
18
|
+
* path.join(__dirname, 'migrations')
|
|
19
|
+
* )
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class FileMigrationProvider {
|
|
23
|
+
#readDir;
|
|
24
|
+
#joinPath;
|
|
25
|
+
#migrationFolderPath;
|
|
26
|
+
constructor(readDir, joinPath, migrationFolderPath) {
|
|
27
|
+
this.#readDir = readDir;
|
|
28
|
+
this.#joinPath = joinPath;
|
|
29
|
+
this.#migrationFolderPath = migrationFolderPath;
|
|
30
|
+
}
|
|
31
|
+
async getMigrations() {
|
|
32
|
+
const migrations = {};
|
|
33
|
+
const files = await this.#readDir(this.#migrationFolderPath);
|
|
34
|
+
for (const fileName of files) {
|
|
35
|
+
if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
|
|
36
|
+
!fileName.endsWith('.d.ts')) {
|
|
37
|
+
const migration = await import(this.#joinPath(this.#migrationFolderPath, fileName));
|
|
38
|
+
if (isMigration(migration)) {
|
|
39
|
+
migrations[fileName.substring(0, fileName.length - 3)] = migration;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return migrations;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isMigration(obj) {
|
|
47
|
+
return isObject(obj) && isFunction(obj.up);
|
|
48
|
+
}
|