kysely 0.15.3 → 0.16.3

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 (239) hide show
  1. package/README.md +1 -9
  2. package/dist/cjs/dialect/database-introspector.d.ts +1 -1
  3. package/dist/cjs/dialect/dialect-adapter-base.d.ts +1 -1
  4. package/dist/cjs/dialect/dialect-adapter.d.ts +1 -1
  5. package/dist/cjs/dialect/dialect.d.ts +2 -2
  6. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +2 -2
  8. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  9. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +1 -1
  10. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +2 -2
  11. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  12. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +1 -1
  13. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +2 -2
  14. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  15. package/dist/cjs/kysely.js +9 -5
  16. package/dist/cjs/migration/file-migration-provider.d.ts +2 -25
  17. package/dist/cjs/migration/file-migration-provider.js +8 -17
  18. package/dist/cjs/migration/migrator.d.ts +2 -15
  19. package/dist/cjs/migration/migrator.js +2 -15
  20. package/dist/cjs/operation-node/constraint-node.d.ts +4 -4
  21. package/dist/cjs/parser/join-parser.d.ts +4 -4
  22. package/dist/cjs/plugin/camel-case/camel-case-plugin.js +1 -1
  23. package/dist/cjs/query-builder/delete-query-builder.d.ts +3 -3
  24. package/dist/cjs/query-builder/expression-builder.d.ts +42 -0
  25. package/dist/cjs/query-builder/expression-builder.js +48 -0
  26. package/dist/cjs/query-builder/insert-query-builder.d.ts +16 -0
  27. package/dist/cjs/query-builder/insert-query-builder.js +16 -0
  28. package/dist/cjs/query-builder/join-interface.d.ts +3 -3
  29. package/dist/cjs/query-builder/on-conflict-builder.d.ts +5 -3
  30. package/dist/cjs/query-builder/select-query-builder.d.ts +3 -3
  31. package/dist/cjs/query-builder/update-query-builder.d.ts +3 -3
  32. package/dist/cjs/query-creator.d.ts +1 -1
  33. package/dist/cjs/util/object-utils.d.ts +1 -1
  34. package/dist/cjs/util/object-utils.js +8 -8
  35. package/dist/esm/dialect/database-introspector.d.ts +1 -1
  36. package/dist/esm/dialect/database-introspector.js +1 -0
  37. package/dist/esm/dialect/dialect-adapter-base.d.ts +1 -1
  38. package/dist/esm/dialect/dialect-adapter-base.js +1 -0
  39. package/dist/esm/dialect/dialect-adapter.d.ts +1 -1
  40. package/dist/esm/dialect/dialect-adapter.js +1 -0
  41. package/dist/esm/dialect/dialect.d.ts +2 -2
  42. package/dist/esm/dialect/dialect.js +1 -0
  43. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +1 -1
  44. package/dist/esm/dialect/mysql/mysql-adapter.js +1 -0
  45. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +2 -2
  46. package/dist/esm/dialect/mysql/mysql-dialect.js +1 -0
  47. package/dist/esm/dialect/mysql/mysql-driver.js +1 -0
  48. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  49. package/dist/esm/dialect/mysql/mysql-introspector.js +1 -0
  50. package/dist/esm/dialect/mysql/mysql-query-compiler.js +1 -0
  51. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +1 -1
  52. package/dist/esm/dialect/postgres/postgres-adapter.js +1 -0
  53. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +2 -2
  54. package/dist/esm/dialect/postgres/postgres-dialect.js +1 -0
  55. package/dist/esm/dialect/postgres/postgres-driver.js +1 -0
  56. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  57. package/dist/esm/dialect/postgres/postgres-introspector.js +1 -0
  58. package/dist/esm/dialect/postgres/postgres-query-compiler.js +1 -0
  59. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +1 -1
  60. package/dist/esm/dialect/sqlite/sqlite-adapter.js +1 -0
  61. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +2 -2
  62. package/dist/esm/dialect/sqlite/sqlite-dialect.js +1 -0
  63. package/dist/esm/dialect/sqlite/sqlite-driver.js +1 -0
  64. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  65. package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -0
  66. package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +1 -0
  67. package/dist/esm/driver/connection-provider.js +1 -0
  68. package/dist/esm/driver/database-connection.js +1 -0
  69. package/dist/esm/driver/default-connection-provider.js +1 -0
  70. package/dist/esm/driver/driver.js +1 -0
  71. package/dist/esm/driver/runtime-driver.js +1 -0
  72. package/dist/esm/driver/single-connection-provider.js +1 -0
  73. package/dist/esm/dynamic/dynamic-reference-builder.js +1 -0
  74. package/dist/esm/dynamic/dynamic.js +1 -0
  75. package/dist/esm/index-nodeless.js +1 -0
  76. package/dist/esm/index.js +1 -0
  77. package/dist/esm/kysely.js +10 -5
  78. package/dist/esm/migration/file-migration-provider.d.ts +2 -25
  79. package/dist/esm/migration/file-migration-provider.js +9 -17
  80. package/dist/esm/migration/migrator.d.ts +2 -15
  81. package/dist/esm/migration/migrator.js +3 -15
  82. package/dist/esm/operation-node/add-column-node.js +1 -0
  83. package/dist/esm/operation-node/add-constraint-node.js +1 -0
  84. package/dist/esm/operation-node/alias-node.js +1 -0
  85. package/dist/esm/operation-node/alter-column-node.js +1 -0
  86. package/dist/esm/operation-node/alter-table-node.js +1 -0
  87. package/dist/esm/operation-node/and-node.js +1 -0
  88. package/dist/esm/operation-node/check-constraint-node.js +1 -0
  89. package/dist/esm/operation-node/column-definition-node.js +1 -0
  90. package/dist/esm/operation-node/column-node.js +1 -0
  91. package/dist/esm/operation-node/column-update-node.js +1 -0
  92. package/dist/esm/operation-node/common-table-expression-name-node.js +1 -0
  93. package/dist/esm/operation-node/common-table-expression-node.js +1 -0
  94. package/dist/esm/operation-node/constraint-node.d.ts +4 -4
  95. package/dist/esm/operation-node/constraint-node.js +1 -0
  96. package/dist/esm/operation-node/create-index-node.js +1 -0
  97. package/dist/esm/operation-node/create-schema-node.js +1 -0
  98. package/dist/esm/operation-node/create-table-node.js +1 -0
  99. package/dist/esm/operation-node/create-view-node.js +1 -0
  100. package/dist/esm/operation-node/data-type-node.js +1 -0
  101. package/dist/esm/operation-node/default-value-node.js +1 -0
  102. package/dist/esm/operation-node/delete-query-node.js +1 -0
  103. package/dist/esm/operation-node/drop-column-node.js +1 -0
  104. package/dist/esm/operation-node/drop-constraint-node.js +1 -0
  105. package/dist/esm/operation-node/drop-index-node.js +1 -0
  106. package/dist/esm/operation-node/drop-schema-node.js +1 -0
  107. package/dist/esm/operation-node/drop-table-node.js +1 -0
  108. package/dist/esm/operation-node/drop-view-node.js +1 -0
  109. package/dist/esm/operation-node/filter-node.js +1 -0
  110. package/dist/esm/operation-node/foreign-key-constraint-node.js +1 -0
  111. package/dist/esm/operation-node/from-node.js +1 -0
  112. package/dist/esm/operation-node/generated-node.js +1 -0
  113. package/dist/esm/operation-node/group-by-item-node.js +1 -0
  114. package/dist/esm/operation-node/group-by-node.js +1 -0
  115. package/dist/esm/operation-node/having-node.js +1 -0
  116. package/dist/esm/operation-node/identifier-node.js +1 -0
  117. package/dist/esm/operation-node/insert-query-node.js +1 -0
  118. package/dist/esm/operation-node/join-node.js +1 -0
  119. package/dist/esm/operation-node/limit-node.js +1 -0
  120. package/dist/esm/operation-node/list-node.js +1 -0
  121. package/dist/esm/operation-node/modify-column-node.js +1 -0
  122. package/dist/esm/operation-node/offset-node.js +1 -0
  123. package/dist/esm/operation-node/on-conflict-node.js +1 -0
  124. package/dist/esm/operation-node/on-duplicate-key-node.js +1 -0
  125. package/dist/esm/operation-node/on-node.js +1 -0
  126. package/dist/esm/operation-node/operation-node-source.js +1 -0
  127. package/dist/esm/operation-node/operation-node-transformer.js +1 -0
  128. package/dist/esm/operation-node/operation-node-utils.js +1 -0
  129. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  130. package/dist/esm/operation-node/operation-node.js +1 -0
  131. package/dist/esm/operation-node/operator-node.js +1 -0
  132. package/dist/esm/operation-node/or-node.js +1 -0
  133. package/dist/esm/operation-node/order-by-item-node.js +1 -0
  134. package/dist/esm/operation-node/order-by-node.js +1 -0
  135. package/dist/esm/operation-node/parens-node.js +1 -0
  136. package/dist/esm/operation-node/primary-constraint-node.js +1 -0
  137. package/dist/esm/operation-node/primitive-value-list-node.js +1 -0
  138. package/dist/esm/operation-node/query-node.js +1 -0
  139. package/dist/esm/operation-node/raw-node.js +1 -0
  140. package/dist/esm/operation-node/reference-node.js +1 -0
  141. package/dist/esm/operation-node/references-node.js +1 -0
  142. package/dist/esm/operation-node/rename-column-node.js +1 -0
  143. package/dist/esm/operation-node/returning-node.js +1 -0
  144. package/dist/esm/operation-node/select-all-node.js +1 -0
  145. package/dist/esm/operation-node/select-query-node.js +1 -0
  146. package/dist/esm/operation-node/selection-node.js +1 -0
  147. package/dist/esm/operation-node/table-node.js +1 -0
  148. package/dist/esm/operation-node/union-node.js +1 -0
  149. package/dist/esm/operation-node/unique-constraint-node.js +1 -0
  150. package/dist/esm/operation-node/update-query-node.js +1 -0
  151. package/dist/esm/operation-node/value-list-node.js +1 -0
  152. package/dist/esm/operation-node/value-node.js +1 -0
  153. package/dist/esm/operation-node/values-node.js +1 -0
  154. package/dist/esm/operation-node/where-node.js +1 -0
  155. package/dist/esm/operation-node/with-node.js +1 -0
  156. package/dist/esm/parser/complex-expression-parser.js +1 -0
  157. package/dist/esm/parser/data-type-parser.js +1 -0
  158. package/dist/esm/parser/default-value-parser.js +1 -0
  159. package/dist/esm/parser/filter-parser.js +1 -0
  160. package/dist/esm/parser/group-by-parser.js +1 -0
  161. package/dist/esm/parser/insert-values-parser.js +1 -0
  162. package/dist/esm/parser/join-parser.d.ts +4 -4
  163. package/dist/esm/parser/join-parser.js +1 -0
  164. package/dist/esm/parser/order-by-parser.js +1 -0
  165. package/dist/esm/parser/parse-context.js +1 -0
  166. package/dist/esm/parser/reference-parser.js +1 -0
  167. package/dist/esm/parser/returning-parser.js +1 -0
  168. package/dist/esm/parser/select-parser.js +1 -0
  169. package/dist/esm/parser/table-parser.js +1 -0
  170. package/dist/esm/parser/union-parser.js +1 -0
  171. package/dist/esm/parser/update-set-parser.js +1 -0
  172. package/dist/esm/parser/value-parser.js +1 -0
  173. package/dist/esm/parser/with-parser.js +1 -0
  174. package/dist/esm/plugin/camel-case/camel-case-plugin.js +3 -2
  175. package/dist/esm/plugin/camel-case/camel-case-transformer.js +1 -0
  176. package/dist/esm/plugin/camel-case/camel-case.js +1 -0
  177. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.js +1 -0
  178. package/dist/esm/plugin/immediate-value.ts/immediate-value-transformer.js +1 -0
  179. package/dist/esm/plugin/kysely-plugin.js +1 -0
  180. package/dist/esm/plugin/with-schema/with-schema-plugin.js +1 -0
  181. package/dist/esm/plugin/with-schema/with-schema-transformer.js +1 -0
  182. package/dist/esm/query-builder/delete-query-builder.d.ts +3 -3
  183. package/dist/esm/query-builder/delete-query-builder.js +1 -0
  184. package/dist/esm/query-builder/delete-result.js +1 -0
  185. package/dist/esm/query-builder/expression-builder.d.ts +42 -0
  186. package/dist/esm/query-builder/expression-builder.js +49 -0
  187. package/dist/esm/query-builder/function-builder.js +1 -0
  188. package/dist/esm/query-builder/having-interface.js +1 -0
  189. package/dist/esm/query-builder/insert-query-builder.d.ts +16 -0
  190. package/dist/esm/query-builder/insert-query-builder.js +17 -0
  191. package/dist/esm/query-builder/insert-result.js +1 -0
  192. package/dist/esm/query-builder/join-builder.js +1 -0
  193. package/dist/esm/query-builder/join-interface.d.ts +3 -3
  194. package/dist/esm/query-builder/join-interface.js +1 -0
  195. package/dist/esm/query-builder/no-result-error.js +1 -0
  196. package/dist/esm/query-builder/on-conflict-builder.d.ts +5 -3
  197. package/dist/esm/query-builder/on-conflict-builder.js +1 -0
  198. package/dist/esm/query-builder/returning-interface.js +1 -0
  199. package/dist/esm/query-builder/select-query-builder.d.ts +3 -3
  200. package/dist/esm/query-builder/select-query-builder.js +1 -0
  201. package/dist/esm/query-builder/update-query-builder.d.ts +3 -3
  202. package/dist/esm/query-builder/update-query-builder.js +1 -0
  203. package/dist/esm/query-builder/update-result.js +1 -0
  204. package/dist/esm/query-builder/where-interface.js +1 -0
  205. package/dist/esm/query-compiler/compiled-query.js +1 -0
  206. package/dist/esm/query-compiler/default-query-compiler.js +1 -0
  207. package/dist/esm/query-compiler/query-compiler.js +1 -0
  208. package/dist/esm/query-creator.d.ts +1 -1
  209. package/dist/esm/query-creator.js +1 -0
  210. package/dist/esm/query-executor/default-query-executor.js +1 -0
  211. package/dist/esm/query-executor/noop-query-executor.js +1 -0
  212. package/dist/esm/query-executor/query-executor.js +1 -0
  213. package/dist/esm/raw-builder/raw-builder.js +1 -0
  214. package/dist/esm/schema/alter-table-builder.js +1 -0
  215. package/dist/esm/schema/column-definition-builder.js +1 -0
  216. package/dist/esm/schema/create-index-builder.js +1 -0
  217. package/dist/esm/schema/create-schema-builder.js +1 -0
  218. package/dist/esm/schema/create-table-builder.js +1 -0
  219. package/dist/esm/schema/create-view-builder.js +1 -0
  220. package/dist/esm/schema/drop-index-builder.js +1 -0
  221. package/dist/esm/schema/drop-schema-builder.js +1 -0
  222. package/dist/esm/schema/drop-table-builder.js +1 -0
  223. package/dist/esm/schema/drop-view-builder.js +1 -0
  224. package/dist/esm/schema/foreign-key-constraint-builder.js +1 -0
  225. package/dist/esm/schema/schema.js +1 -0
  226. package/dist/esm/util/assert.js +1 -0
  227. package/dist/esm/util/column-type.js +1 -0
  228. package/dist/esm/util/compilable.js +1 -0
  229. package/dist/esm/util/dynamic-import.js +1 -0
  230. package/dist/esm/util/log.js +1 -0
  231. package/dist/esm/util/object-utils.d.ts +1 -1
  232. package/dist/esm/util/object-utils.js +7 -6
  233. package/dist/esm/util/performance-now.js +1 -0
  234. package/dist/esm/util/prevent-await.js +1 -0
  235. package/dist/esm/util/private-symbols.js +1 -0
  236. package/dist/esm/util/query-id.js +1 -0
  237. package/dist/esm/util/random-string.js +1 -0
  238. package/dist/esm/util/type-utils.js +1 -0
  239. package/package.json +3 -2
package/README.md CHANGED
@@ -303,9 +303,6 @@ need to depend on a typescript compiler, which most production environments don'
303
303
  have. You will probably want to add a simple migration script to your projects like this:
304
304
 
305
305
  ```ts
306
- import * as path from 'path'
307
- import * as fs from 'fs/promises'
308
-
309
306
  import {
310
307
  Kysely,
311
308
  Migrator,
@@ -323,14 +320,9 @@ async function migrateToLatest() {
323
320
 
324
321
  const migrator = new Migrator({
325
322
  db,
326
- // The constructor signature of FileMigrationProvider is a
327
- // bit weird to keep Kysely independent of node.js or any
328
- // other environment.
329
323
  provider: new FileMigrationProvider(
330
- fs.readdir,
331
- path.join,
332
324
  // Path to the folder that contains all your migrations.
333
- 'migrations'
325
+ 'some/path/to/migrations'
334
326
  )
335
327
  })
336
328
 
@@ -4,7 +4,7 @@ import { ColumnDataType } from '../operation-node/data-type-node.js';
4
4
  */
5
5
  export interface DatabaseIntrospector {
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -20,7 +20,7 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
20
20
  get supportsReturning(): boolean;
21
21
  /**
22
22
  * This method is used to acquire a lock for the migrations so that
23
- * it's not possible for two migration processes to run in parallel.
23
+ * it's not possible for two migration operations to run in parallel.
24
24
  *
25
25
  * Most dialects have explicit locks that can be used, like advisory locks
26
26
  * in PostgreSQL and the get_lock function in MySQL.
@@ -21,7 +21,7 @@ export interface DialectAdapter {
21
21
  readonly supportsReturning: boolean;
22
22
  /**
23
23
  * This method is used to acquire a lock for the migrations so that
24
- * it's not possible for two migration processes to run in parallel.
24
+ * it's not possible for two migration operations to run in parallel.
25
25
  *
26
26
  * Most dialects have explicit locks that can be used, like advisory locks
27
27
  * in PostgreSQL and the get_lock function in MySQL.
@@ -24,8 +24,8 @@ export interface Dialect {
24
24
  */
25
25
  createAdapter(): DialectAdapter;
26
26
  /**
27
- * Creates a database introspector that can be used to get the database metadata
28
- * such as the tables and columns that exist in the database.
27
+ * Creates a database introspector that can be used to get database metadata
28
+ * such as the table names and column names of those tables.
29
29
  *
30
30
  * `db` never has any plugins installed. It's created using
31
31
  * {@link Kysely.withoutPlugins}.
@@ -14,7 +14,7 @@ export declare class MysqlAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
16
  * This method is used to acquire a lock for the migrations so that
17
- * it's not possible for two migration processes to run in parallel.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class MysqlDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
30
  /**
31
- * Creates a database introspector that can be used to get the database metadata
32
- * such as the tables and columns that exist in the database.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class MysqlIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -14,7 +14,7 @@ export declare class PostgresAdapter extends DialectAdapterBase {
14
14
  get supportsReturning(): boolean;
15
15
  /**
16
16
  * This method is used to acquire a lock for the migrations so that
17
- * it's not possible for two migration processes to run in parallel.
17
+ * it's not possible for two migration operations to run in parallel.
18
18
  *
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
@@ -34,8 +34,8 @@ export declare class PostgresDialect implements Dialect {
34
34
  */
35
35
  createAdapter(): DialectAdapter;
36
36
  /**
37
- * Creates a database introspector that can be used to get the database metadata
38
- * such as the tables and columns that exist in the database.
37
+ * Creates a database introspector that can be used to get database metadata
38
+ * such as the table names and column names of those tables.
39
39
  *
40
40
  * `db` never has any plugins installed. It's created using
41
41
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class PostgresIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -13,7 +13,7 @@ export declare class SqliteAdapter implements DialectAdapterBase {
13
13
  get supportsReturning(): boolean;
14
14
  /**
15
15
  * This method is used to acquire a lock for the migrations so that
16
- * it's not possible for two migration processes to run in parallel.
16
+ * it's not possible for two migration operations to run in parallel.
17
17
  *
18
18
  * Most dialects have explicit locks that can be used, like advisory locks
19
19
  * in PostgreSQL and the get_lock function in MySQL.
@@ -28,8 +28,8 @@ export declare class SqliteDialect implements Dialect {
28
28
  */
29
29
  createAdapter(): DialectAdapter;
30
30
  /**
31
- * Creates a database introspector that can be used to get the database metadata
32
- * such as the tables and columns that exist in the database.
31
+ * Creates a database introspector that can be used to get database metadata
32
+ * such as the table names and column names of those tables.
33
33
  *
34
34
  * `db` never has any plugins installed. It's created using
35
35
  * {@link Kysely.withoutPlugins}.
@@ -4,7 +4,7 @@ export declare class SqliteIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
6
  /**
7
- * Get the database metadata such as the names of the tables and columns.
7
+ * Get the database metadata such as table and column names.
8
8
  */
9
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
10
  }
@@ -59,9 +59,11 @@ const private_symbols_js_1 = require("./util/private-symbols.js");
59
59
  class Kysely extends query_creator_js_1.QueryCreator {
60
60
  #props;
61
61
  constructor(args) {
62
+ let superProps;
63
+ let props;
62
64
  if (isKyselyProps(args)) {
63
- super({ executor: args.executor, parseContext: args.parseContext });
64
- this.#props = (0, object_utils_js_1.freeze)({ ...args });
65
+ superProps = { executor: args.executor, parseContext: args.parseContext };
66
+ props = { ...args };
65
67
  }
66
68
  else {
67
69
  const dialect = args.dialect;
@@ -73,15 +75,17 @@ class Kysely extends query_creator_js_1.QueryCreator {
73
75
  const runtimeDriver = new runtime_driver_js_1.RuntimeDriver(driver, log);
74
76
  const connectionProvider = new default_connection_provider_js_1.DefaultConnectionProvider(runtimeDriver);
75
77
  const executor = new default_query_executor_js_1.DefaultQueryExecutor(compiler, connectionProvider, args.plugins ?? []);
76
- super({ executor, parseContext });
77
- this.#props = (0, object_utils_js_1.freeze)({
78
+ superProps = { executor, parseContext };
79
+ props = {
78
80
  config: args,
79
81
  executor,
80
82
  dialect,
81
83
  driver: runtimeDriver,
82
84
  parseContext,
83
- });
85
+ };
84
86
  }
87
+ super(superProps);
88
+ this.#props = (0, object_utils_js_1.freeze)(props);
85
89
  }
86
90
  /**
87
91
  * Returns the {@link SchemaModule} module for building database schema.
@@ -1,41 +1,18 @@
1
1
  import { Migration, MigrationProvider } from './migrator.js';
2
- /**
3
- * A function that takes a folder path and returns names of the
4
- * files insider that folder.
5
- */
6
- export declare type ReadDir = (migrationFolderPath: string) => Promise<string[]>;
7
- /**
8
- * A function that combines two file path parts into a single file path.
9
- *
10
- * ```ts
11
- * joinPath('/some/path', 'file.ts')
12
- * // ==> '/some/path/file.ts'
13
- * ```
14
- */
15
- export declare type JoinPath = (part1: string, part2: string) => string;
16
2
  /**
17
3
  * Reads all migrations from a folder.
18
4
  *
19
- * You need to provide a function for reading files in a folder and a function for
20
- * joining file paths together. The API is like this to make Kysely independent of
21
- * node.js or any other environment. See the example usage on node.js below.
22
- *
23
5
  * ### Examples
24
6
  *
25
7
  * ```ts
26
- * import * as path from 'path'
27
- * import * as fs from 'fs/promises'
28
- *
29
8
  * new FileMigrationProvider(
30
- * fs.readdir,
31
- * path.join,
32
- * path.join(__dirname, 'migrations')
9
+ * 'path/to/migrations/folder'
33
10
  * )
34
11
  * ```
35
12
  */
36
13
  export declare class FileMigrationProvider implements MigrationProvider {
37
14
  #private;
38
- constructor(readDir: ReadDir, joinPath: JoinPath, migrationFolderPath: string);
15
+ constructor(migrationFolderPath: string);
39
16
  /**
40
17
  * Returns all migrations, old and new.
41
18
  *
@@ -5,39 +5,30 @@ const object_utils_js_1 = require("../util/object-utils.js");
5
5
  /**
6
6
  * Reads all migrations from a folder.
7
7
  *
8
- * You need to provide a function for reading files in a folder and a function for
9
- * joining file paths together. The API is like this to make Kysely independent of
10
- * node.js or any other environment. See the example usage on node.js below.
11
- *
12
8
  * ### Examples
13
9
  *
14
10
  * ```ts
15
- * import * as path from 'path'
16
- * import * as fs from 'fs/promises'
17
- *
18
11
  * new FileMigrationProvider(
19
- * fs.readdir,
20
- * path.join,
21
- * path.join(__dirname, 'migrations')
12
+ * 'path/to/migrations/folder'
22
13
  * )
23
14
  * ```
24
15
  */
25
16
  class FileMigrationProvider {
26
- #readDir;
27
- #joinPath;
28
17
  #migrationFolderPath;
29
- constructor(readDir, joinPath, migrationFolderPath) {
30
- this.#readDir = readDir;
31
- this.#joinPath = joinPath;
18
+ constructor(migrationFolderPath) {
32
19
  this.#migrationFolderPath = migrationFolderPath;
33
20
  }
34
21
  async getMigrations() {
22
+ // Import these dynamically so that we don't have any top level
23
+ // node dependencies.
24
+ const fs = await Promise.resolve().then(() => require('fs/promises'));
25
+ const path = await Promise.resolve().then(() => require('path'));
35
26
  const migrations = {};
36
- const files = await this.#readDir(this.#migrationFolderPath);
27
+ const files = await fs.readdir(this.#migrationFolderPath);
37
28
  for (const fileName of files) {
38
29
  if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
39
30
  !fileName.endsWith('.d.ts')) {
40
- const migration = await Promise.resolve().then(() => require(this.#joinPath(this.#migrationFolderPath, fileName)));
31
+ const migration = await Promise.resolve().then(() => require(path.join(this.#migrationFolderPath, fileName)));
41
32
  if (isMigration(migration)) {
42
33
  migrations[fileName.substring(0, fileName.length - 3)] = migration;
43
34
  }
@@ -26,14 +26,9 @@ export interface Migration {
26
26
  * ```ts
27
27
  * const migrator = new Migrator({
28
28
  * db,
29
- * // The constructor signature of FileMigrationProvider is a
30
- * // bit weird to keep Kysely independent of node.js or any
31
- * // other environment.
32
29
  * provider: new FileMigrationProvider(
33
- * fs.readdir,
34
- * path.join,
35
30
  * // Path to the folder that contains all your migrations.
36
- * 'migrations'
31
+ * 'some/path/to/migrations'
37
32
  * )
38
33
  * })
39
34
  * ```
@@ -57,9 +52,6 @@ export declare class Migrator {
57
52
  * ### Examples
58
53
  *
59
54
  * ```ts
60
- * import * as path from 'path'
61
- * import * as fs from 'fs/promises'
62
- *
63
55
  * const db = new Kysely<Database>({
64
56
  * dialect: new PostgresDialect({
65
57
  * host: 'localhost',
@@ -69,14 +61,9 @@ export declare class Migrator {
69
61
  *
70
62
  * const migrator = new Migrator({
71
63
  * db,
72
- * // The constructor signature of FileMigrationProvider is a
73
- * // bit weird to keep Kysely independent of node.js or any
74
- * // other environment.
75
64
  * provider: new FileMigrationProvider(
76
- * fs.readdir,
77
- * path.join,
78
65
  * // Path to the folder that contains all your migrations.
79
- * 'migrations'
66
+ * 'some/path/to/migrations'
80
67
  * )
81
68
  * })
82
69
  *
@@ -20,14 +20,9 @@ exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true }
20
20
  * ```ts
21
21
  * const migrator = new Migrator({
22
22
  * db,
23
- * // The constructor signature of FileMigrationProvider is a
24
- * // bit weird to keep Kysely independent of node.js or any
25
- * // other environment.
26
23
  * provider: new FileMigrationProvider(
27
- * fs.readdir,
28
- * path.join,
29
24
  * // Path to the folder that contains all your migrations.
30
- * 'migrations'
25
+ * 'some/path/to/migrations'
31
26
  * )
32
27
  * })
33
28
  * ```
@@ -53,9 +48,6 @@ class Migrator {
53
48
  * ### Examples
54
49
  *
55
50
  * ```ts
56
- * import * as path from 'path'
57
- * import * as fs from 'fs/promises'
58
- *
59
51
  * const db = new Kysely<Database>({
60
52
  * dialect: new PostgresDialect({
61
53
  * host: 'localhost',
@@ -65,14 +57,9 @@ class Migrator {
65
57
  *
66
58
  * const migrator = new Migrator({
67
59
  * db,
68
- * // The constructor signature of FileMigrationProvider is a
69
- * // bit weird to keep Kysely independent of node.js or any
70
- * // other environment.
71
60
  * provider: new FileMigrationProvider(
72
- * fs.readdir,
73
- * path.join,
74
61
  * // Path to the folder that contains all your migrations.
75
- * 'migrations'
62
+ * 'some/path/to/migrations'
76
63
  * )
77
64
  * })
78
65
  *
@@ -1,5 +1,5 @@
1
- import { CheckConstraintNode } from "./check-constraint-node";
2
- import { ForeignKeyConstraintNode } from "./foreign-key-constraint-node";
3
- import { PrimaryKeyConstraintNode } from "./primary-constraint-node";
4
- import { UniqueConstraintNode } from "./unique-constraint-node";
1
+ import { CheckConstraintNode } from './check-constraint-node.js';
2
+ import { ForeignKeyConstraintNode } from './foreign-key-constraint-node.js';
3
+ import { PrimaryKeyConstraintNode } from './primary-constraint-node.js';
4
+ import { UniqueConstraintNode } from './unique-constraint-node.js';
5
5
  export declare type ConstraintNode = PrimaryKeyConstraintNode | UniqueConstraintNode | CheckConstraintNode | ForeignKeyConstraintNode;
@@ -1,11 +1,11 @@
1
1
  import { JoinNode, JoinType } from '../operation-node/join-node.js';
2
2
  import { AnyColumn, AnyColumnWithTable } from '../util/type-utils.js';
3
- import { ExtractAliasFromTableExpression, TableExpressionDatabase } from './table-parser.js';
3
+ import { TableExpressionDatabase, TableExpressionTables } from './table-parser.js';
4
4
  import { JoinBuilder } from '../query-builder/join-builder.js';
5
5
  import { ParseContext } from './parse-context.js';
6
6
  export declare type JoinReferenceExpression<DB, TB extends keyof DB, TE> = AnyJoinColumn<DB, TB, TE> | AnyJoinColumnWithTable<DB, TB, TE>;
7
- export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>) => JoinBuilder<any, any>;
8
- declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
9
- declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TB | ExtractAliasFromTableExpression<DB, TE>>;
7
+ export declare type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (join: JoinBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>) => JoinBuilder<any, any>;
8
+ declare type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
9
+ declare type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
10
10
  export declare function parseJoin(ctx: ParseContext, joinType: JoinType, args: any[]): JoinNode;
11
11
  export {};
@@ -111,5 +111,5 @@ class CamelCasePlugin {
111
111
  }
112
112
  exports.CamelCasePlugin = CamelCasePlugin;
113
113
  function canMap(obj) {
114
- return (0, object_utils_js_1.isObject)(obj) && !(obj instanceof Date) && !Buffer.isBuffer(obj);
114
+ return (0, object_utils_js_1.isObject)(obj) && !(0, object_utils_js_1.isDate)(obj) && !(0, object_utils_js_1.isBuffer)(obj);
115
115
  }
@@ -473,13 +473,13 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
473
473
  * and "pet"."name" = $1
474
474
  * ```
475
475
  *
476
- * You can join a subquery by providing a function as the first
477
- * argument:
476
+ * You can join a subquery by providing a select query (or a callback)
477
+ * as the first argument:
478
478
  *
479
479
  * ```ts
480
480
  * await db.selectFrom('person')
481
481
  * .innerJoin(
482
- * (qb) => qb.selectFrom('pet')
482
+ * qb.selectFrom('pet')
483
483
  * .select(['owner_id', 'name'])
484
484
  * .where('name', '=', 'Doggo')
485
485
  * .as('doggos'),
@@ -3,6 +3,8 @@ import { TableExpression, TableExpressionDatabase, TableExpressionTables } from
3
3
  import { NoopQueryExecutor } from '../query-executor/noop-query-executor.js';
4
4
  import { ParseContext } from '../parser/parse-context.js';
5
5
  import { FunctionBuilder } from './function-builder.js';
6
+ import { RawBuilder } from '../index-nodeless.js';
7
+ import { ExtractTypeFromReferenceExpression, StringReference } from '../parser/reference-parser.js';
6
8
  export declare class ExpressionBuilder<DB, TB extends keyof DB> {
7
9
  #private;
8
10
  constructor(props: ExpressionBuilderProps);
@@ -44,6 +46,8 @@ export declare class ExpressionBuilder<DB, TB extends keyof DB> {
44
46
  * The query builder returned by this method is typed in a way that you can refer to
45
47
  * all tables of the parent query in addition to the subquery's tables.
46
48
  *
49
+ * This method accepts all the same inputs as {@link QueryCreator.selectFrom}.
50
+ *
47
51
  * ### Examples
48
52
  *
49
53
  * This example shows that you can refer to both `pet.owner_id` and `person.id`
@@ -86,6 +90,44 @@ export declare class ExpressionBuilder<DB, TB extends keyof DB> {
86
90
  * See {@link QueryCreator.withSchema}
87
91
  */
88
92
  withSchema(schema: string): ExpressionBuilder<DB, TB>;
93
+ /**
94
+ * See {@link QueryCreator.raw}.
95
+ */
96
+ raw<T = unknown>(sql: string, parameters?: unknown[]): RawBuilder<T>;
97
+ /**
98
+ * This can be used to reference columns.
99
+ *
100
+ * ### Examples
101
+ *
102
+ * In the next example we use the `ref` method to reference
103
+ * columns of the virtual table `excluded` in a type-safe way
104
+ * to create an upsert operation:
105
+ *
106
+ * ```ts
107
+ * db.insertInto('person')
108
+ * .values(person)
109
+ * .onConflict(oc => oc
110
+ * .column('id')
111
+ * .doUpdateSet({
112
+ * first_name: (eb) => eb.ref('excluded.first_name'),
113
+ * last_name: (eb) => eb.ref('excluded.last_name')
114
+ * })
115
+ * )
116
+ * ```
117
+ *
118
+ * In the next example we use `ref` in a raw expression. Unless you
119
+ * want to be as type-safe as possible, this is probably overkill:
120
+ *
121
+ * ```ts
122
+ * db.update('pet').set({
123
+ * name: (eb) => eb.raw('concat(?, ?)', [
124
+ * eb.ref('pet.name'),
125
+ * suffix,
126
+ * ])
127
+ * })
128
+ * ```
129
+ */
130
+ ref<RE extends StringReference<DB, TB>>(reference: RE): RawBuilder<ExtractTypeFromReferenceExpression<DB, TB, RE>>;
89
131
  }
90
132
  export interface ExpressionBuilderProps {
91
133
  readonly executor: NoopQueryExecutor;
@@ -8,6 +8,7 @@ const with_schema_plugin_js_1 = require("../plugin/with-schema/with-schema-plugi
8
8
  const query_id_js_1 = require("../util/query-id.js");
9
9
  const object_utils_js_1 = require("../util/object-utils.js");
10
10
  const function_builder_js_1 = require("./function-builder.js");
11
+ const index_nodeless_js_1 = require("../index-nodeless.js");
11
12
  class ExpressionBuilder {
12
13
  #props;
13
14
  constructor(props) {
@@ -64,5 +65,52 @@ class ExpressionBuilder {
64
65
  executor: this.#props.executor.withPluginAtFront(new with_schema_plugin_js_1.WithSchemaPlugin(schema)),
65
66
  });
66
67
  }
68
+ /**
69
+ * See {@link QueryCreator.raw}.
70
+ */
71
+ raw(sql, parameters) {
72
+ return new index_nodeless_js_1.RawBuilder({
73
+ queryId: (0, query_id_js_1.createQueryId)(),
74
+ executor: this.#props.executor,
75
+ sql,
76
+ parameters,
77
+ });
78
+ }
79
+ /**
80
+ * This can be used to reference columns.
81
+ *
82
+ * ### Examples
83
+ *
84
+ * In the next example we use the `ref` method to reference
85
+ * columns of the virtual table `excluded` in a type-safe way
86
+ * to create an upsert operation:
87
+ *
88
+ * ```ts
89
+ * db.insertInto('person')
90
+ * .values(person)
91
+ * .onConflict(oc => oc
92
+ * .column('id')
93
+ * .doUpdateSet({
94
+ * first_name: (eb) => eb.ref('excluded.first_name'),
95
+ * last_name: (eb) => eb.ref('excluded.last_name')
96
+ * })
97
+ * )
98
+ * ```
99
+ *
100
+ * In the next example we use `ref` in a raw expression. Unless you
101
+ * want to be as type-safe as possible, this is probably overkill:
102
+ *
103
+ * ```ts
104
+ * db.update('pet').set({
105
+ * name: (eb) => eb.raw('concat(?, ?)', [
106
+ * eb.ref('pet.name'),
107
+ * suffix,
108
+ * ])
109
+ * })
110
+ * ```
111
+ */
112
+ ref(reference) {
113
+ return this.raw('??', [reference]);
114
+ }
67
115
  }
68
116
  exports.ExpressionBuilder = ExpressionBuilder;
@@ -342,6 +342,22 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
342
342
  * values ($1, $2)
343
343
  * on conflict ("name") do nothing
344
344
  * ```
345
+ *
346
+ * You can refer to the columns of the virtual `excluded` table
347
+ * in a type-safe way using a callback and the `ref` method of
348
+ * `ExpressionBuilder`:
349
+ *
350
+ * ```ts
351
+ * db.insertInto('person')
352
+ * .values(person)
353
+ * .onConflict(oc => oc
354
+ * .column('id')
355
+ * .doUpdateSet({
356
+ * first_name: (eb) => eb.ref('excluded.first_name'),
357
+ * last_name: (eb) => eb.ref('excluded.last_name')
358
+ * })
359
+ * )
360
+ * ```
345
361
  */
346
362
  onConflict(callback: (builder: OnConflictBuilder<DB, TB>) => OnConflictDoNothingBuilder<DB, TB> | OnConflictUpdateBuilder<DB, TB>): InsertQueryBuilder<DB, TB, O>;
347
363
  /**
@@ -248,6 +248,22 @@ class InsertQueryBuilder {
248
248
  * values ($1, $2)
249
249
  * on conflict ("name") do nothing
250
250
  * ```
251
+ *
252
+ * You can refer to the columns of the virtual `excluded` table
253
+ * in a type-safe way using a callback and the `ref` method of
254
+ * `ExpressionBuilder`:
255
+ *
256
+ * ```ts
257
+ * db.insertInto('person')
258
+ * .values(person)
259
+ * .onConflict(oc => oc
260
+ * .column('id')
261
+ * .doUpdateSet({
262
+ * first_name: (eb) => eb.ref('excluded.first_name'),
263
+ * last_name: (eb) => eb.ref('excluded.last_name')
264
+ * })
265
+ * )
266
+ * ```
251
267
  */
252
268
  onConflict(callback) {
253
269
  return new InsertQueryBuilder({
@@ -80,13 +80,13 @@ export interface JoinInterface<DB, TB extends keyof DB> {
80
80
  * and "pet"."name" = $1
81
81
  * ```
82
82
  *
83
- * You can join a subquery by providing a function as the first
84
- * argument:
83
+ * You can join a subquery by providing a select query (or a callback)
84
+ * as the first argument:
85
85
  *
86
86
  * ```ts
87
87
  * await db.selectFrom('person')
88
88
  * .innerJoin(
89
- * (qb) => qb.selectFrom('pet')
89
+ * qb.selectFrom('pet')
90
90
  * .select(['owner_id', 'name'])
91
91
  * .where('name', '=', 'Doggo')
92
92
  * .as('doggos'),
@@ -377,14 +377,16 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
377
377
  * do update set "first_name" = $3
378
378
  * ```
379
379
  */
380
- doUpdateSet(updates: MutationObject<DB, TB>): OnConflictUpdateBuilder<{
381
- [K in keyof DB | 'excluded']: K extends keyof DB ? DB[K] : DB[TB];
382
- }, TB | 'excluded'>;
380
+ doUpdateSet(updates: MutationObject<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>): OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>;
383
381
  }
384
382
  export interface OnConflictBuilderProps {
385
383
  readonly onConflictNode: OnConflictNode;
386
384
  readonly parseContext: ParseContext;
387
385
  }
386
+ export declare type OnConflictDatabase<DB, TB extends keyof DB> = {
387
+ [K in keyof DB | 'excluded']: K extends keyof DB ? DB[K] : DB[TB];
388
+ };
389
+ export declare type OnConflictTables<TB> = TB | 'excluded';
388
390
  export declare class OnConflictDoNothingBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
389
391
  #private;
390
392
  constructor(props: OnConflictBuilderProps);