kysely 0.12.2 → 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 (156) hide show
  1. package/README.md +115 -31
  2. package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
  3. package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
  4. package/dist/cjs/dialect/dialect.d.ts +1 -1
  5. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +2 -2
  6. package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -1
  7. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
  8. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  9. package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
  10. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +2 -2
  11. package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -1
  12. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
  13. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  14. package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
  15. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +2 -2
  16. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
  17. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  18. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
  19. package/dist/cjs/index.d.ts +7 -4
  20. package/dist/cjs/index.js +6 -3
  21. package/dist/cjs/kysely.d.ts +8 -40
  22. package/dist/cjs/kysely.js +8 -40
  23. package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
  24. package/dist/cjs/migration/file-migration-provider.js +52 -0
  25. package/dist/cjs/migration/migrator.d.ts +234 -0
  26. package/dist/cjs/migration/migrator.js +417 -0
  27. package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
  28. package/dist/cjs/operation-node/check-constraint-node.js +2 -3
  29. package/dist/cjs/operation-node/column-definition-node.d.ts +8 -7
  30. package/dist/cjs/operation-node/column-definition-node.js +0 -4
  31. package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
  32. package/dist/cjs/operation-node/generated-node.d.ts +20 -0
  33. package/dist/cjs/operation-node/generated-node.js +31 -0
  34. package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
  35. package/dist/cjs/operation-node/on-conflict-node.js +39 -1
  36. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
  37. package/dist/cjs/operation-node/operation-node-transformer.js +13 -6
  38. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
  39. package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
  40. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  41. package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
  42. package/dist/cjs/parser/insert-values-parser.js +2 -3
  43. package/dist/cjs/parser/reference-parser.d.ts +4 -3
  44. package/dist/cjs/parser/select-parser.d.ts +10 -4
  45. package/dist/cjs/parser/update-set-parser.d.ts +2 -1
  46. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +2 -2
  47. package/dist/cjs/query-builder/delete-query-builder.d.ts +0 -3
  48. package/dist/cjs/query-builder/insert-query-builder.d.ts +78 -94
  49. package/dist/cjs/query-builder/insert-query-builder.js +145 -15
  50. package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
  51. package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
  52. package/dist/cjs/query-builder/returning-interface.d.ts +0 -3
  53. package/dist/cjs/query-builder/update-query-builder.d.ts +0 -3
  54. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
  55. package/dist/cjs/query-compiler/default-query-compiler.js +37 -8
  56. package/dist/cjs/query-creator.d.ts +0 -2
  57. package/dist/cjs/query-creator.js +0 -2
  58. package/dist/cjs/schema/alter-table-builder.d.ts +41 -9
  59. package/dist/cjs/schema/alter-table-builder.js +45 -9
  60. package/dist/cjs/schema/column-definition-builder.d.ts +40 -8
  61. package/dist/cjs/schema/column-definition-builder.js +21 -8
  62. package/dist/cjs/schema/create-index-builder.d.ts +3 -2
  63. package/dist/cjs/schema/create-index-builder.js +2 -2
  64. package/dist/cjs/schema/create-table-builder.d.ts +3 -2
  65. package/dist/cjs/schema/create-table-builder.js +2 -2
  66. package/dist/cjs/util/column-type.d.ts +165 -0
  67. package/dist/cjs/util/column-type.js +2 -0
  68. package/dist/cjs/util/private-symbols.d.ts +5 -0
  69. package/dist/cjs/util/private-symbols.js +8 -0
  70. package/dist/cjs/util/type-utils.d.ts +6 -42
  71. package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
  72. package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
  73. package/dist/esm/dialect/dialect.d.ts +1 -1
  74. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +2 -2
  75. package/dist/esm/dialect/mysql/mysql-adapter.js +2 -1
  76. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
  77. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  78. package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
  79. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +2 -2
  80. package/dist/esm/dialect/postgres/postgres-adapter.js +2 -1
  81. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
  82. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  83. package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
  84. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +2 -2
  85. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
  86. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  87. package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
  88. package/dist/esm/index.d.ts +7 -4
  89. package/dist/esm/index.js +6 -3
  90. package/dist/esm/kysely.d.ts +8 -40
  91. package/dist/esm/kysely.js +8 -40
  92. package/dist/esm/migration/file-migration-provider.d.ts +52 -0
  93. package/dist/esm/migration/file-migration-provider.js +48 -0
  94. package/dist/esm/migration/migrator.d.ts +234 -0
  95. package/dist/esm/migration/migrator.js +413 -0
  96. package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
  97. package/dist/esm/operation-node/check-constraint-node.js +2 -3
  98. package/dist/esm/operation-node/column-definition-node.d.ts +8 -7
  99. package/dist/esm/operation-node/column-definition-node.js +0 -4
  100. package/dist/esm/operation-node/data-type-node.d.ts +1 -1
  101. package/dist/esm/operation-node/generated-node.d.ts +20 -0
  102. package/dist/esm/operation-node/generated-node.js +28 -0
  103. package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
  104. package/dist/esm/operation-node/on-conflict-node.js +39 -1
  105. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
  106. package/dist/esm/operation-node/operation-node-transformer.js +13 -6
  107. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
  108. package/dist/esm/operation-node/operation-node-visitor.js +1 -1
  109. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  110. package/dist/esm/parser/insert-values-parser.d.ts +4 -4
  111. package/dist/esm/parser/insert-values-parser.js +2 -3
  112. package/dist/esm/parser/reference-parser.d.ts +4 -3
  113. package/dist/esm/parser/select-parser.d.ts +10 -4
  114. package/dist/esm/parser/update-set-parser.d.ts +2 -1
  115. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +2 -2
  116. package/dist/esm/query-builder/delete-query-builder.d.ts +0 -3
  117. package/dist/esm/query-builder/insert-query-builder.d.ts +78 -94
  118. package/dist/esm/query-builder/insert-query-builder.js +145 -15
  119. package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
  120. package/dist/esm/query-builder/on-conflict-builder.js +317 -0
  121. package/dist/esm/query-builder/returning-interface.d.ts +0 -3
  122. package/dist/esm/query-builder/update-query-builder.d.ts +0 -3
  123. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
  124. package/dist/esm/query-compiler/default-query-compiler.js +37 -8
  125. package/dist/esm/query-creator.d.ts +0 -2
  126. package/dist/esm/query-creator.js +0 -2
  127. package/dist/esm/schema/alter-table-builder.d.ts +41 -9
  128. package/dist/esm/schema/alter-table-builder.js +45 -9
  129. package/dist/esm/schema/column-definition-builder.d.ts +40 -8
  130. package/dist/esm/schema/column-definition-builder.js +21 -8
  131. package/dist/esm/schema/create-index-builder.d.ts +3 -2
  132. package/dist/esm/schema/create-index-builder.js +2 -2
  133. package/dist/esm/schema/create-table-builder.d.ts +3 -2
  134. package/dist/esm/schema/create-table-builder.js +2 -2
  135. package/dist/esm/util/column-type.d.ts +165 -0
  136. package/dist/esm/util/column-type.js +1 -0
  137. package/dist/esm/util/private-symbols.d.ts +5 -0
  138. package/dist/esm/util/private-symbols.js +5 -0
  139. package/dist/esm/util/type-utils.d.ts +6 -42
  140. package/package.json +1 -1
  141. package/dist/cjs/migration/migration.d.ts +0 -66
  142. package/dist/cjs/migration/migration.js +0 -187
  143. package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
  144. package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
  145. package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
  146. package/dist/cjs/parser/on-conflict-parser.js +0 -35
  147. package/dist/cjs/util/generated-placeholder.d.ts +0 -3
  148. package/dist/cjs/util/generated-placeholder.js +0 -11
  149. package/dist/esm/migration/migration.d.ts +0 -66
  150. package/dist/esm/migration/migration.js +0 -183
  151. package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
  152. package/dist/esm/operation-node/generated-always-as-node.js +0 -22
  153. package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
  154. package/dist/esm/parser/on-conflict-parser.js +0 -30
  155. package/dist/esm/util/generated-placeholder.d.ts +0 -3
  156. 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,36 +291,77 @@ 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 file name.
299
+ order by their name. See the [Migrator](https://koskimas.github.io/kysely/classes/Migrator.html)
300
+ documentation for more info.
256
301
 
257
302
  Kysely doesn't have a CLI for running migrations and probably never will. This is because Kysely's
258
303
  migrations are also written in typescript. To run the migrations, you need to first build the
259
- typescript code into javascript. The CLI would cause confusion over which migrations are being
260
- run, the typescript ones or the javascript ones. If we added support for both, it would mean the
261
- CLI would depend on a typescript compiler, which most production environments don't (and shouldn't)
304
+ typescript code into javascript. A CLI would cause confusion over which migrations are being
305
+ run, the typescript ones or the javascript ones. If we added support for both, the CLI would
306
+ need to depend on a typescript compiler, which most production environments don't (and shouldn't)
262
307
  have. You will probably want to add a simple migration script to your projects like this:
263
308
 
264
309
  ```ts
265
- import path from 'path'
266
- import { db } from './database'
310
+ import * as path from 'path'
311
+ import * as fs from 'fs/promises'
312
+
313
+ import {
314
+ Kysely,
315
+ Migrator,
316
+ PostgresDialect,
317
+ FileMigrationProvider
318
+ } from 'kysely'
319
+
320
+ async function migrateToLatest() {
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
+ })
340
+
341
+ const { error, results } = await migrator.migrateToLatest()
267
342
 
268
- db.migration
269
- .migrateToLatest(path.join(__dirname, 'migrations'))
270
- .then(() => db.destroy())
343
+ results?.forEach((it) => {
344
+ if (it.status === 'Success') {
345
+ console.log(`migration "${it.migrationName}" was executed successfully`)
346
+ } else if (it.status === 'Error') {
347
+ console.error(`failed to execute migration "${it.migrationName}"`)
348
+ }
349
+ })
350
+
351
+ if (error) {
352
+ console.error('failed to migrate')
353
+ console.error(error)
354
+ process.exit(1)
355
+ }
356
+ }
357
+
358
+ migrateToLatest()
271
359
  ```
272
360
 
273
361
  The migration methods use a lock on the database level, and parallel calls are executed serially.
274
362
  This means that you can safely call `migrateToLatest` and other migration methods from multiple
275
363
  server instances simultaneously and the migrations are guaranteed to only be executed once.
276
364
 
277
- NOTE: Only `db.migration.migrateToLatest` method is implemented at the moment. There is no way
278
- to run the down migrations, or to go forward to a specific migration. These methods will be
279
- added soon.
280
-
281
365
  # Why not just contribute to knex
282
366
 
283
367
  Kysely is very similar to knex, but it also attempts to fix things that I personally find not-so-good
@@ -1,7 +1,7 @@
1
1
  import { Driver } from '../driver/driver.js';
2
2
  import { Kysely } from '../kysely.js';
3
3
  import { QueryCompiler } from '../query-compiler/query-compiler.js';
4
- import { DatabaseIntrospector } from '../introspection/database-introspector.js';
4
+ import { DatabaseIntrospector } from './database-introspector.js';
5
5
  import { DialectAdapter } from './dialect-adapter.js';
6
6
  /**
7
7
  * A Dialect is the glue between Kysely and the underlying database engine.
@@ -1,6 +1,6 @@
1
1
  import { Kysely } from '../../kysely.js';
2
- import { DialectAdapter } from '../dialect-adapter.js';
3
- export declare class MysqlAdapter implements DialectAdapter {
2
+ import { DialectAdapterBase } from '../dialect-adapter-base.js';
3
+ export declare class MysqlAdapter extends DialectAdapterBase {
4
4
  /**
5
5
  * Whether or not this dialect supports transactional DDL.
6
6
  *
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MysqlAdapter = void 0;
4
+ const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
4
5
  const LOCK_ID = 'ea586330-2c93-47c8-908d-981d9d270f9d';
5
6
  const LOCK_TIMEOUT_SECONDS = 60 * 60;
6
- class MysqlAdapter {
7
+ class MysqlAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
7
8
  get supportsTransactionalDdl() {
8
9
  return false;
9
10
  }
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
2
2
  import { Kysely } from '../../kysely.js';
3
3
  import { QueryCompiler } from '../../query-compiler/query-compiler.js';
4
4
  import { Dialect } from '../dialect.js';
5
- import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
5
+ import { DatabaseIntrospector } from '../database-introspector.js';
6
6
  import { DialectAdapter } from '../dialect-adapter.js';
7
7
  import { DatabaseConnection } from '../../driver/database-connection.js';
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../../introspection/database-introspector.js';
1
+ import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
2
2
  import { Kysely } from '../../kysely.js';
3
3
  export declare class MysqlIntrospector implements DatabaseIntrospector {
4
4
  #private;
@@ -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,6 +1,6 @@
1
1
  import { Kysely } from '../../kysely.js';
2
- import { DialectAdapter } from '../dialect-adapter.js';
3
- export declare class PostgresAdapter implements DialectAdapter {
2
+ import { DialectAdapterBase } from '../dialect-adapter-base.js';
3
+ export declare class PostgresAdapter extends DialectAdapterBase {
4
4
  /**
5
5
  * Whether or not this dialect supports transactional DDL.
6
6
  *
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresAdapter = void 0;
4
+ const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
4
5
  // Random id for our transaction lock.
5
6
  const LOCK_ID = '3853314791062309107';
6
- class PostgresAdapter {
7
+ class PostgresAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
7
8
  get supportsTransactionalDdl() {
8
9
  return true;
9
10
  }
@@ -5,7 +5,7 @@ import { Driver } from '../../driver/driver.js';
5
5
  import { Kysely } from '../../kysely.js';
6
6
  import { QueryCompiler } from '../../query-compiler/query-compiler.js';
7
7
  import { Dialect } from '../dialect.js';
8
- import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
8
+ import { DatabaseIntrospector } from '../database-introspector.js';
9
9
  import { DialectAdapter } from '../dialect-adapter.js';
10
10
  import { DatabaseConnection } from '../../driver/database-connection.js';
11
11
  /**
@@ -1,4 +1,4 @@
1
- import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../../introspection/database-introspector.js';
1
+ import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
2
2
  import { Kysely } from '../../kysely.js';
3
3
  export declare class PostgresIntrospector implements DatabaseIntrospector {
4
4
  #private;
@@ -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,5 +1,5 @@
1
- import { DialectAdapter } from '../dialect-adapter.js';
2
- export declare class SqliteAdapter implements DialectAdapter {
1
+ import { DialectAdapterBase } from '../dialect-adapter-base.js';
2
+ export declare class SqliteAdapter implements DialectAdapterBase {
3
3
  /**
4
4
  * Whether or not this dialect supports transactional DDL.
5
5
  *
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
2
2
  import { Kysely } from '../../kysely.js';
3
3
  import { QueryCompiler } from '../../query-compiler/query-compiler.js';
4
4
  import { Dialect } from '../dialect.js';
5
- import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
5
+ import { DatabaseIntrospector } from '../database-introspector.js';
6
6
  import { DialectAdapter } from '../dialect-adapter.js';
7
7
  import { DatabaseConnection } from '../../driver/database-connection.js';
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../../introspection/database-introspector.js';
1
+ import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
2
2
  import { Kysely } from '../../kysely.js';
3
3
  export declare class SqliteIntrospector implements DatabaseIntrospector {
4
4
  #private;
@@ -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 {
@@ -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/migration.js';
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-always-as-node.js';
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,11 +138,12 @@ 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 './introspection/database-introspector.js';
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';
143
- export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
146
+ export { SelectExpression, SelectExpressionOrList, Selection, } from './parser/select-parser.js';
144
147
  export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
145
148
  export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
146
149
  export { FilterValueExpression, FilterValueExpressionOrList, ExistsExpression, FilterOperator, } from './parser/filter-parser.js';
package/dist/cjs/index.js CHANGED
@@ -27,6 +27,7 @@ __exportStar(require("./query-builder/function-builder.js"), exports);
27
27
  __exportStar(require("./query-builder/insert-result.js"), exports);
28
28
  __exportStar(require("./query-builder/delete-result.js"), exports);
29
29
  __exportStar(require("./query-builder/update-result.js"), exports);
30
+ __exportStar(require("./query-builder/on-conflict-builder.js"), exports);
30
31
  __exportStar(require("./raw-builder/raw-builder.js"), exports);
31
32
  __exportStar(require("./query-executor/query-executor.js"), exports);
32
33
  __exportStar(require("./query-executor/default-query-executor.js"), exports);
@@ -68,7 +69,8 @@ __exportStar(require("./dialect/sqlite/sqlite-introspector.js"), exports);
68
69
  __exportStar(require("./dialect/sqlite/sqlite-adapter.js"), exports);
69
70
  __exportStar(require("./query-compiler/default-query-compiler.js"), exports);
70
71
  __exportStar(require("./query-compiler/query-compiler.js"), exports);
71
- __exportStar(require("./migration/migration.js"), exports);
72
+ __exportStar(require("./migration/migrator.js"), exports);
73
+ __exportStar(require("./migration/file-migration-provider.js"), exports);
72
74
  __exportStar(require("./dialect/dialect.js"), exports);
73
75
  __exportStar(require("./dialect/dialect-adapter.js"), exports);
74
76
  __exportStar(require("./dialect/dialect-adapter-base.js"), exports);
@@ -103,7 +105,7 @@ __exportStar(require("./operation-node/drop-view-node.js"), exports);
103
105
  __exportStar(require("./operation-node/filter-node.js"), exports);
104
106
  __exportStar(require("./operation-node/foreign-key-constraint-node.js"), exports);
105
107
  __exportStar(require("./operation-node/from-node.js"), exports);
106
- __exportStar(require("./operation-node/generated-always-as-node.js"), exports);
108
+ __exportStar(require("./operation-node/generated-node.js"), exports);
107
109
  __exportStar(require("./operation-node/group-by-item-node.js"), exports);
108
110
  __exportStar(require("./operation-node/group-by-node.js"), exports);
109
111
  __exportStar(require("./operation-node/having-node.js"), exports);
@@ -148,6 +150,7 @@ __exportStar(require("./operation-node/value-node.js"), exports);
148
150
  __exportStar(require("./operation-node/values-node.js"), exports);
149
151
  __exportStar(require("./operation-node/where-node.js"), exports);
150
152
  __exportStar(require("./operation-node/with-node.js"), exports);
151
- __exportStar(require("./introspection/database-introspector.js"), exports);
153
+ __exportStar(require("./dialect/database-introspector.js"), exports);
154
+ __exportStar(require("./util/column-type.js"), exports);
152
155
  __exportStar(require("./util/compilable.js"), exports);
153
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
- 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'