kysely 0.11.3 → 0.12.2

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 (250) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/dialect/dialect-adapter-base.d.ts +36 -0
  3. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +36 -0
  4. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +16 -0
  5. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
  6. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +3 -0
  7. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +36 -0
  8. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +16 -0
  9. package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
  10. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +3 -0
  11. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  12. package/dist/cjs/dialect/sqlite/sqlite-adapter.js +6 -2
  13. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  14. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
  15. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  16. package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
  17. package/dist/cjs/driver/runtime-driver.d.ts +29 -0
  18. package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
  19. package/dist/cjs/dynamic/dynamic-reference-builder.d.ts +1 -0
  20. package/dist/cjs/dynamic/dynamic-reference-builder.js +9 -1
  21. package/dist/cjs/dynamic/dynamic.d.ts +6 -7
  22. package/dist/cjs/dynamic/dynamic.js +6 -7
  23. package/dist/cjs/index.d.ts +14 -3
  24. package/dist/cjs/index.js +12 -1
  25. package/dist/cjs/kysely.d.ts +170 -11
  26. package/dist/cjs/kysely.js +69 -9
  27. package/dist/cjs/migration/migration.d.ts +2 -2
  28. package/dist/cjs/operation-node/common-table-expression-name-node.d.ts +15 -0
  29. package/dist/cjs/operation-node/common-table-expression-name-node.js +23 -0
  30. package/dist/cjs/operation-node/common-table-expression-node.d.ts +3 -3
  31. package/dist/cjs/operation-node/create-table-node.d.ts +6 -2
  32. package/dist/cjs/operation-node/create-table-node.js +6 -6
  33. package/dist/cjs/operation-node/create-view-node.d.ts +1 -0
  34. package/dist/cjs/operation-node/insert-query-node.d.ts +4 -4
  35. package/dist/cjs/operation-node/operation-node-transformer.d.ts +4 -0
  36. package/dist/cjs/operation-node/operation-node-transformer.js +20 -1
  37. package/dist/cjs/operation-node/operation-node-visitor.d.ts +4 -0
  38. package/dist/cjs/operation-node/operation-node-visitor.js +2 -0
  39. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  40. package/dist/cjs/operation-node/query-node.d.ts +0 -2
  41. package/dist/cjs/operation-node/query-node.js +0 -10
  42. package/dist/cjs/operation-node/values-node.d.ts +15 -0
  43. package/dist/cjs/operation-node/values-node.js +18 -0
  44. package/dist/cjs/operation-node/with-node.d.ts +3 -1
  45. package/dist/cjs/operation-node/with-node.js +2 -1
  46. package/dist/cjs/package.json +1 -3
  47. package/dist/cjs/parser/complex-expression-parser.d.ts +9 -0
  48. package/dist/cjs/parser/complex-expression-parser.js +25 -0
  49. package/dist/cjs/parser/filter-parser.d.ts +13 -4
  50. package/dist/cjs/parser/filter-parser.js +21 -24
  51. package/dist/cjs/parser/insert-values-parser.d.ts +7 -10
  52. package/dist/cjs/parser/insert-values-parser.js +31 -39
  53. package/dist/cjs/parser/order-by-parser.d.ts +1 -1
  54. package/dist/cjs/parser/parse-context.d.ts +22 -8
  55. package/dist/cjs/parser/parse-context.js +10 -10
  56. package/dist/cjs/parser/reference-parser.d.ts +8 -7
  57. package/dist/cjs/parser/reference-parser.js +8 -17
  58. package/dist/cjs/parser/returning-parser.d.ts +1 -5
  59. package/dist/cjs/parser/select-parser.d.ts +12 -14
  60. package/dist/cjs/parser/select-parser.js +5 -9
  61. package/dist/cjs/parser/table-parser.d.ts +9 -11
  62. package/dist/cjs/parser/table-parser.js +2 -8
  63. package/dist/cjs/parser/union-parser.d.ts +2 -2
  64. package/dist/cjs/parser/union-parser.js +1 -6
  65. package/dist/cjs/parser/update-set-parser.d.ts +2 -8
  66. package/dist/cjs/parser/update-set-parser.js +6 -26
  67. package/dist/cjs/parser/value-parser.d.ts +9 -6
  68. package/dist/cjs/parser/value-parser.js +7 -30
  69. package/dist/cjs/parser/with-parser.d.ts +36 -6
  70. package/dist/cjs/parser/with-parser.js +13 -2
  71. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  72. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  73. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  74. package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  75. package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
  76. package/dist/cjs/query-builder/delete-query-builder.d.ts +647 -0
  77. package/dist/cjs/query-builder/delete-query-builder.js +185 -0
  78. package/dist/cjs/query-builder/expression-builder.d.ts +8 -6
  79. package/dist/cjs/query-builder/expression-builder.js +3 -3
  80. package/dist/cjs/query-builder/function-builder.d.ts +2 -1
  81. package/dist/cjs/query-builder/function-builder.js +2 -1
  82. package/dist/cjs/query-builder/having-interface.d.ts +49 -0
  83. package/dist/cjs/query-builder/having-interface.js +2 -0
  84. package/dist/cjs/query-builder/insert-query-builder.d.ts +504 -0
  85. package/dist/cjs/query-builder/insert-query-builder.js +256 -0
  86. package/dist/cjs/query-builder/insert-result.d.ts +3 -2
  87. package/dist/cjs/query-builder/insert-result.js +3 -2
  88. package/dist/cjs/query-builder/join-builder.d.ts +19 -20
  89. package/dist/cjs/query-builder/join-builder.js +12 -12
  90. package/dist/cjs/query-builder/join-interface.d.ts +130 -0
  91. package/dist/cjs/query-builder/join-interface.js +2 -0
  92. package/dist/cjs/query-builder/no-result-error.d.ts +9 -0
  93. package/dist/cjs/query-builder/no-result-error.js +14 -0
  94. package/dist/cjs/query-builder/returning-interface.d.ts +73 -0
  95. package/dist/cjs/query-builder/returning-interface.js +2 -0
  96. package/dist/cjs/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -634
  97. package/dist/cjs/query-builder/select-query-builder.js +571 -0
  98. package/dist/cjs/query-builder/update-query-builder.d.ts +735 -0
  99. package/dist/cjs/query-builder/update-query-builder.js +279 -0
  100. package/dist/cjs/query-builder/where-interface.d.ts +378 -0
  101. package/dist/cjs/query-builder/where-interface.js +2 -0
  102. package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -0
  103. package/dist/cjs/query-compiler/default-query-compiler.js +33 -5
  104. package/dist/cjs/query-creator.d.ts +69 -43
  105. package/dist/cjs/query-creator.js +66 -29
  106. package/dist/cjs/query-executor/default-query-executor.d.ts +19 -0
  107. package/dist/cjs/query-executor/noop-query-executor.d.ts +19 -0
  108. package/dist/cjs/query-executor/query-executor.d.ts +1 -1
  109. package/dist/cjs/query-executor/query-executor.js +1 -1
  110. package/dist/cjs/raw-builder/raw-builder.d.ts +2 -0
  111. package/dist/cjs/raw-builder/raw-builder.js +7 -1
  112. package/dist/cjs/schema/alter-table-builder.d.ts +218 -2
  113. package/dist/cjs/schema/column-definition-builder.d.ts +135 -20
  114. package/dist/cjs/schema/create-index-builder.d.ts +2 -1
  115. package/dist/cjs/schema/create-index-builder.js +2 -1
  116. package/dist/cjs/schema/create-table-builder.d.ts +26 -9
  117. package/dist/cjs/schema/create-table-builder.js +42 -9
  118. package/dist/cjs/schema/create-view-builder.d.ts +17 -3
  119. package/dist/cjs/schema/create-view-builder.js +25 -16
  120. package/dist/cjs/schema/schema.d.ts +18 -11
  121. package/dist/cjs/schema/schema.js +18 -11
  122. package/dist/cjs/util/log.d.ts +3 -2
  123. package/dist/cjs/util/log.js +8 -15
  124. package/dist/cjs/util/type-utils.d.ts +7 -7
  125. package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
  126. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +36 -0
  127. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +16 -0
  128. package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
  129. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
  130. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +36 -0
  131. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +16 -0
  132. package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
  133. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +3 -0
  134. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  135. package/dist/esm/dialect/sqlite/sqlite-adapter.js +6 -2
  136. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  137. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
  138. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  139. package/dist/esm/driver/default-connection-provider.d.ts +4 -0
  140. package/dist/esm/driver/runtime-driver.d.ts +29 -0
  141. package/dist/esm/driver/single-connection-provider.d.ts +4 -0
  142. package/dist/esm/dynamic/dynamic-reference-builder.d.ts +1 -0
  143. package/dist/esm/dynamic/dynamic-reference-builder.js +7 -0
  144. package/dist/esm/dynamic/dynamic.d.ts +6 -7
  145. package/dist/esm/dynamic/dynamic.js +6 -7
  146. package/dist/esm/index.d.ts +14 -3
  147. package/dist/esm/index.js +12 -1
  148. package/dist/esm/kysely.d.ts +170 -11
  149. package/dist/esm/kysely.js +69 -9
  150. package/dist/esm/migration/migration.d.ts +2 -2
  151. package/dist/esm/operation-node/common-table-expression-name-node.d.ts +15 -0
  152. package/dist/esm/operation-node/common-table-expression-name-node.js +20 -0
  153. package/dist/esm/operation-node/common-table-expression-node.d.ts +3 -3
  154. package/dist/esm/operation-node/create-table-node.d.ts +6 -2
  155. package/dist/esm/operation-node/create-table-node.js +6 -6
  156. package/dist/esm/operation-node/create-view-node.d.ts +1 -0
  157. package/dist/esm/operation-node/insert-query-node.d.ts +4 -4
  158. package/dist/esm/operation-node/operation-node-transformer.d.ts +4 -0
  159. package/dist/esm/operation-node/operation-node-transformer.js +20 -1
  160. package/dist/esm/operation-node/operation-node-visitor.d.ts +4 -0
  161. package/dist/esm/operation-node/operation-node-visitor.js +2 -0
  162. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  163. package/dist/esm/operation-node/query-node.d.ts +0 -2
  164. package/dist/esm/operation-node/query-node.js +0 -10
  165. package/dist/esm/operation-node/values-node.d.ts +15 -0
  166. package/dist/esm/operation-node/values-node.js +15 -0
  167. package/dist/esm/operation-node/with-node.d.ts +3 -1
  168. package/dist/esm/operation-node/with-node.js +2 -1
  169. package/dist/esm/package.json +1 -3
  170. package/dist/esm/parser/complex-expression-parser.d.ts +9 -0
  171. package/dist/esm/parser/complex-expression-parser.js +20 -0
  172. package/dist/esm/parser/filter-parser.d.ts +13 -4
  173. package/dist/esm/parser/filter-parser.js +21 -24
  174. package/dist/esm/parser/insert-values-parser.d.ts +7 -10
  175. package/dist/esm/parser/insert-values-parser.js +31 -38
  176. package/dist/esm/parser/order-by-parser.d.ts +1 -1
  177. package/dist/esm/parser/parse-context.d.ts +22 -8
  178. package/dist/esm/parser/parse-context.js +10 -10
  179. package/dist/esm/parser/reference-parser.d.ts +8 -7
  180. package/dist/esm/parser/reference-parser.js +9 -18
  181. package/dist/esm/parser/returning-parser.d.ts +1 -5
  182. package/dist/esm/parser/select-parser.d.ts +12 -14
  183. package/dist/esm/parser/select-parser.js +6 -10
  184. package/dist/esm/parser/table-parser.d.ts +9 -11
  185. package/dist/esm/parser/table-parser.js +3 -9
  186. package/dist/esm/parser/union-parser.d.ts +2 -2
  187. package/dist/esm/parser/union-parser.js +1 -6
  188. package/dist/esm/parser/update-set-parser.d.ts +2 -8
  189. package/dist/esm/parser/update-set-parser.js +5 -24
  190. package/dist/esm/parser/value-parser.d.ts +9 -6
  191. package/dist/esm/parser/value-parser.js +8 -31
  192. package/dist/esm/parser/with-parser.d.ts +36 -6
  193. package/dist/esm/parser/with-parser.js +13 -2
  194. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  195. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  196. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  197. package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  198. package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
  199. package/dist/esm/query-builder/delete-query-builder.d.ts +647 -0
  200. package/dist/esm/query-builder/delete-query-builder.js +181 -0
  201. package/dist/esm/query-builder/expression-builder.d.ts +8 -6
  202. package/dist/esm/query-builder/expression-builder.js +3 -3
  203. package/dist/esm/query-builder/function-builder.d.ts +2 -1
  204. package/dist/esm/query-builder/function-builder.js +2 -1
  205. package/dist/esm/query-builder/having-interface.d.ts +49 -0
  206. package/dist/esm/query-builder/having-interface.js +1 -0
  207. package/dist/esm/query-builder/insert-query-builder.d.ts +504 -0
  208. package/dist/esm/query-builder/insert-query-builder.js +252 -0
  209. package/dist/esm/query-builder/insert-result.d.ts +3 -2
  210. package/dist/esm/query-builder/insert-result.js +3 -2
  211. package/dist/esm/query-builder/join-builder.d.ts +19 -20
  212. package/dist/esm/query-builder/join-builder.js +12 -12
  213. package/dist/esm/query-builder/join-interface.d.ts +130 -0
  214. package/dist/esm/query-builder/join-interface.js +1 -0
  215. package/dist/esm/query-builder/no-result-error.d.ts +9 -0
  216. package/dist/esm/query-builder/no-result-error.js +10 -0
  217. package/dist/esm/query-builder/returning-interface.d.ts +73 -0
  218. package/dist/esm/query-builder/returning-interface.js +1 -0
  219. package/dist/esm/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -634
  220. package/dist/esm/query-builder/select-query-builder.js +566 -0
  221. package/dist/esm/query-builder/update-query-builder.d.ts +735 -0
  222. package/dist/esm/query-builder/update-query-builder.js +275 -0
  223. package/dist/esm/query-builder/where-interface.d.ts +378 -0
  224. package/dist/esm/query-builder/where-interface.js +1 -0
  225. package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -0
  226. package/dist/esm/query-compiler/default-query-compiler.js +33 -5
  227. package/dist/esm/query-creator.d.ts +69 -43
  228. package/dist/esm/query-creator.js +66 -29
  229. package/dist/esm/query-executor/default-query-executor.d.ts +19 -0
  230. package/dist/esm/query-executor/noop-query-executor.d.ts +19 -0
  231. package/dist/esm/query-executor/query-executor.d.ts +1 -1
  232. package/dist/esm/query-executor/query-executor.js +1 -1
  233. package/dist/esm/raw-builder/raw-builder.d.ts +2 -0
  234. package/dist/esm/raw-builder/raw-builder.js +7 -1
  235. package/dist/esm/schema/alter-table-builder.d.ts +218 -2
  236. package/dist/esm/schema/column-definition-builder.d.ts +135 -20
  237. package/dist/esm/schema/create-index-builder.d.ts +2 -1
  238. package/dist/esm/schema/create-index-builder.js +2 -1
  239. package/dist/esm/schema/create-table-builder.d.ts +26 -9
  240. package/dist/esm/schema/create-table-builder.js +43 -10
  241. package/dist/esm/schema/create-view-builder.d.ts +17 -3
  242. package/dist/esm/schema/create-view-builder.js +25 -16
  243. package/dist/esm/schema/schema.d.ts +18 -11
  244. package/dist/esm/schema/schema.js +18 -11
  245. package/dist/esm/util/log.d.ts +3 -2
  246. package/dist/esm/util/log.js +7 -14
  247. package/dist/esm/util/type-utils.d.ts +7 -7
  248. package/package.json +10 -8
  249. package/dist/cjs/query-builder/query-builder.js +0 -1067
  250. package/dist/esm/query-builder/query-builder.js +0 -1061
package/README.md CHANGED
@@ -72,7 +72,7 @@ interface Person {
72
72
  first_name: string
73
73
  // If the column is nullable in the db, make its type nullable.
74
74
  // Don't use optional properties.
75
- last_name: string | null
75
+ last_name: string | null
76
76
  gender: 'male' | 'female' | 'other'
77
77
  }
78
78
 
@@ -7,8 +7,44 @@ import { DialectAdapter } from './dialect-adapter.js';
7
7
  * they are added and there will be less breaking changes.
8
8
  */
9
9
  export declare abstract class DialectAdapterBase implements DialectAdapter {
10
+ /**
11
+ * Whether or not this dialect supports transactional DDL.
12
+ *
13
+ * If this is true, migrations are executed inside a transaction.
14
+ */
10
15
  get supportsTransactionalDdl(): boolean;
16
+ /**
17
+ * Whether or not this dialect supports the `returning` in inserts
18
+ * updates and deletes.
19
+ */
11
20
  get supportsReturning(): boolean;
21
+ /**
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.
24
+ *
25
+ * Most dialects have explicit locks that can be used, like advisory locks
26
+ * in PostgreSQL and the get_lock function in MySQL.
27
+ *
28
+ * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
29
+ * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
30
+ * has two columns `id` and `is_locked` and there's only one row in the
31
+ * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
32
+ * Kysely takes care of creating the lock table and inserting the one single
33
+ * row to it before this method is executed.
34
+ *
35
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
36
+ * is a transaction inside which the migrations will be executed. Otherwise
37
+ * `db` is a single connection (session) that will be used to execute the
38
+ * migrations.
39
+ */
12
40
  abstract acquireMigrationLock(db: Kysely<any>): Promise<void>;
41
+ /**
42
+ * Releases the migration lock. See {@link acquireMigrationLock}.
43
+ *
44
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
45
+ * is a transaction inside which the migrations were executed. Otherwise `db`
46
+ * is a single connection (session) that was used to execute the migrations
47
+ * and the `acquireMigrationLock` call.
48
+ */
13
49
  abstract releaseMigrationLock(db: Kysely<any>): Promise<void>;
14
50
  }
@@ -1,8 +1,44 @@
1
1
  import { Kysely } from '../../kysely.js';
2
2
  import { DialectAdapter } from '../dialect-adapter.js';
3
3
  export declare class MysqlAdapter implements DialectAdapter {
4
+ /**
5
+ * Whether or not this dialect supports transactional DDL.
6
+ *
7
+ * If this is true, migrations are executed inside a transaction.
8
+ */
4
9
  get supportsTransactionalDdl(): boolean;
10
+ /**
11
+ * Whether or not this dialect supports the `returning` in inserts
12
+ * updates and deletes.
13
+ */
5
14
  get supportsReturning(): boolean;
15
+ /**
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.
18
+ *
19
+ * Most dialects have explicit locks that can be used, like advisory locks
20
+ * in PostgreSQL and the get_lock function in MySQL.
21
+ *
22
+ * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
23
+ * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
24
+ * has two columns `id` and `is_locked` and there's only one row in the
25
+ * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
26
+ * Kysely takes care of creating the lock table and inserting the one single
27
+ * row to it before this method is executed.
28
+ *
29
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
30
+ * is a transaction inside which the migrations will be executed. Otherwise
31
+ * `db` is a single connection (session) that will be used to execute the
32
+ * migrations.
33
+ */
6
34
  acquireMigrationLock(db: Kysely<any>): Promise<void>;
35
+ /**
36
+ * Releases the migration lock. See {@link acquireMigrationLock}.
37
+ *
38
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
39
+ * is a transaction inside which the migrations were executed. Otherwise `db`
40
+ * is a single connection (session) that was used to execute the migrations
41
+ * and the `acquireMigrationLock` call.
42
+ */
7
43
  releaseMigrationLock(db: Kysely<any>): Promise<void>;
8
44
  }
@@ -15,9 +15,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
15
15
  export declare class MysqlDialect implements Dialect {
16
16
  #private;
17
17
  constructor(config: MysqlDialectConfig);
18
+ /**
19
+ * Creates a driver for the dialect.
20
+ */
18
21
  createDriver(): Driver;
22
+ /**
23
+ * Creates a query compiler for the dialect.
24
+ */
19
25
  createQueryCompiler(): QueryCompiler;
26
+ /**
27
+ * Creates an adapter for the dialect.
28
+ */
20
29
  createAdapter(): DialectAdapter;
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.
33
+ *
34
+ * `db` never has any plugins installed. It's created using
35
+ * {@link Kysely.withoutPlugins}.
36
+ */
21
37
  createIntrospector(db: Kysely<any>): DatabaseIntrospector;
22
38
  }
23
39
  /**
@@ -4,11 +4,40 @@ import { MysqlDialectConfig } from './mysql-dialect.js';
4
4
  export declare class MysqlDriver implements Driver {
5
5
  #private;
6
6
  constructor(config: MysqlDialectConfig);
7
+ /**
8
+ * Initializes the driver.
9
+ *
10
+ * After calling this method the driver should be usable and `acquireConnection` etc.
11
+ * methods should be callable.
12
+ *
13
+ * IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
14
+ * should be imported inside this function, not at the top of the driver file! This is
15
+ * important so that Kysely is usable without installing all database driver libraries
16
+ * it supports.
17
+ */
7
18
  init(): Promise<void>;
19
+ /**
20
+ * Acquires a new connection from the pool.
21
+ */
8
22
  acquireConnection(): Promise<DatabaseConnection>;
23
+ /**
24
+ * Begins a transaction.
25
+ */
9
26
  beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
27
+ /**
28
+ * Commits a transaction.
29
+ */
10
30
  commitTransaction(connection: DatabaseConnection): Promise<void>;
31
+ /**
32
+ * Rolls back a transaction.
33
+ */
11
34
  rollbackTransaction(connection: DatabaseConnection): Promise<void>;
35
+ /**
36
+ * Releases a connection back to the pool.
37
+ */
12
38
  releaseConnection(connection: DatabaseConnection): Promise<void>;
39
+ /**
40
+ * Destroys the driver and releases all resources.
41
+ */
13
42
  destroy(): Promise<void>;
14
43
  }
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
3
3
  export declare class MysqlIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
+ /**
7
+ * Get the database metadata such as the names of the tables and columns.
8
+ */
6
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
7
10
  }
@@ -1,8 +1,44 @@
1
1
  import { Kysely } from '../../kysely.js';
2
2
  import { DialectAdapter } from '../dialect-adapter.js';
3
3
  export declare class PostgresAdapter implements DialectAdapter {
4
+ /**
5
+ * Whether or not this dialect supports transactional DDL.
6
+ *
7
+ * If this is true, migrations are executed inside a transaction.
8
+ */
4
9
  get supportsTransactionalDdl(): boolean;
10
+ /**
11
+ * Whether or not this dialect supports the `returning` in inserts
12
+ * updates and deletes.
13
+ */
5
14
  get supportsReturning(): boolean;
15
+ /**
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.
18
+ *
19
+ * Most dialects have explicit locks that can be used, like advisory locks
20
+ * in PostgreSQL and the get_lock function in MySQL.
21
+ *
22
+ * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
23
+ * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
24
+ * has two columns `id` and `is_locked` and there's only one row in the
25
+ * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
26
+ * Kysely takes care of creating the lock table and inserting the one single
27
+ * row to it before this method is executed.
28
+ *
29
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
30
+ * is a transaction inside which the migrations will be executed. Otherwise
31
+ * `db` is a single connection (session) that will be used to execute the
32
+ * migrations.
33
+ */
6
34
  acquireMigrationLock(db: Kysely<any>): Promise<void>;
35
+ /**
36
+ * Releases the migration lock. See {@link acquireMigrationLock}.
37
+ *
38
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
39
+ * is a transaction inside which the migrations were executed. Otherwise `db`
40
+ * is a single connection (session) that was used to execute the migrations
41
+ * and the `acquireMigrationLock` call.
42
+ */
7
43
  releaseMigrationLock(): Promise<void>;
8
44
  }
@@ -21,9 +21,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
21
21
  export declare class PostgresDialect implements Dialect {
22
22
  #private;
23
23
  constructor(config: PostgresDialectConfig);
24
+ /**
25
+ * Creates a driver for the dialect.
26
+ */
24
27
  createDriver(): Driver;
28
+ /**
29
+ * Creates a query compiler for the dialect.
30
+ */
25
31
  createQueryCompiler(): QueryCompiler;
32
+ /**
33
+ * Creates an adapter for the dialect.
34
+ */
26
35
  createAdapter(): DialectAdapter;
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.
39
+ *
40
+ * `db` never has any plugins installed. It's created using
41
+ * {@link Kysely.withoutPlugins}.
42
+ */
27
43
  createIntrospector(db: Kysely<any>): DatabaseIntrospector;
28
44
  }
29
45
  /**
@@ -4,11 +4,40 @@ import { PostgresDialectConfig } from './postgres-dialect.js';
4
4
  export declare class PostgresDriver implements Driver {
5
5
  #private;
6
6
  constructor(config: PostgresDialectConfig);
7
+ /**
8
+ * Initializes the driver.
9
+ *
10
+ * After calling this method the driver should be usable and `acquireConnection` etc.
11
+ * methods should be callable.
12
+ *
13
+ * IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
14
+ * should be imported inside this function, not at the top of the driver file! This is
15
+ * important so that Kysely is usable without installing all database driver libraries
16
+ * it supports.
17
+ */
7
18
  init(): Promise<void>;
19
+ /**
20
+ * Acquires a new connection from the pool.
21
+ */
8
22
  acquireConnection(): Promise<DatabaseConnection>;
23
+ /**
24
+ * Begins a transaction.
25
+ */
9
26
  beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
27
+ /**
28
+ * Commits a transaction.
29
+ */
10
30
  commitTransaction(connection: DatabaseConnection): Promise<void>;
31
+ /**
32
+ * Rolls back a transaction.
33
+ */
11
34
  rollbackTransaction(connection: DatabaseConnection): Promise<void>;
35
+ /**
36
+ * Releases a connection back to the pool.
37
+ */
12
38
  releaseConnection(connection: DatabaseConnection): Promise<void>;
39
+ /**
40
+ * Destroys the driver and releases all resources.
41
+ */
13
42
  destroy(): Promise<void>;
14
43
  }
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
3
3
  export declare class PostgresIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
+ /**
7
+ * Get the database metadata such as the names of the tables and columns.
8
+ */
6
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
7
10
  }
@@ -1,7 +1,43 @@
1
1
  import { DialectAdapter } from '../dialect-adapter.js';
2
2
  export declare class SqliteAdapter implements DialectAdapter {
3
+ /**
4
+ * Whether or not this dialect supports transactional DDL.
5
+ *
6
+ * If this is true, migrations are executed inside a transaction.
7
+ */
3
8
  get supportsTransactionalDdl(): boolean;
9
+ /**
10
+ * Whether or not this dialect supports the `returning` in inserts
11
+ * updates and deletes.
12
+ */
4
13
  get supportsReturning(): boolean;
14
+ /**
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.
17
+ *
18
+ * Most dialects have explicit locks that can be used, like advisory locks
19
+ * in PostgreSQL and the get_lock function in MySQL.
20
+ *
21
+ * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
22
+ * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
23
+ * has two columns `id` and `is_locked` and there's only one row in the
24
+ * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
25
+ * Kysely takes care of creating the lock table and inserting the one single
26
+ * row to it before this method is executed.
27
+ *
28
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
29
+ * is a transaction inside which the migrations will be executed. Otherwise
30
+ * `db` is a single connection (session) that will be used to execute the
31
+ * migrations.
32
+ */
5
33
  acquireMigrationLock(): Promise<void>;
34
+ /**
35
+ * Releases the migration lock. See {@link acquireMigrationLock}.
36
+ *
37
+ * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
38
+ * is a transaction inside which the migrations were executed. Otherwise `db`
39
+ * is a single connection (session) that was used to execute the migrations
40
+ * and the `acquireMigrationLock` call.
41
+ */
6
42
  releaseMigrationLock(): Promise<void>;
7
43
  }
@@ -9,10 +9,14 @@ class SqliteAdapter {
9
9
  return false;
10
10
  }
11
11
  async acquireMigrationLock() {
12
- // Nothing to do here.
12
+ // SQLite only has one connection that's reserved by the migration system
13
+ // for the whole time between acquireMigrationLock and releaseMigrationLock.
14
+ // We don't need to do anything here.
13
15
  }
14
16
  async releaseMigrationLock() {
15
- // Nothing to do here.
17
+ // SQLite only has one connection that's reserved by the migration system
18
+ // for the whole time between acquireMigrationLock and releaseMigrationLock.
19
+ // We don't need to do anything here.
16
20
  }
17
21
  }
18
22
  exports.SqliteAdapter = SqliteAdapter;
@@ -15,9 +15,25 @@ import { DatabaseConnection } from '../../driver/database-connection.js';
15
15
  export declare class SqliteDialect implements Dialect {
16
16
  #private;
17
17
  constructor(config: SqliteDialectConfig);
18
+ /**
19
+ * Creates a driver for the dialect.
20
+ */
18
21
  createDriver(): Driver;
22
+ /**
23
+ * Creates a query compiler for the dialect.
24
+ */
19
25
  createQueryCompiler(): QueryCompiler;
26
+ /**
27
+ * Creates an adapter for the dialect.
28
+ */
20
29
  createAdapter(): DialectAdapter;
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.
33
+ *
34
+ * `db` never has any plugins installed. It's created using
35
+ * {@link Kysely.withoutPlugins}.
36
+ */
21
37
  createIntrospector(db: Kysely<any>): DatabaseIntrospector;
22
38
  }
23
39
  /**
@@ -4,11 +4,40 @@ import { SqliteDialectConfig } from './sqlite-dialect.js';
4
4
  export declare class SqliteDriver implements Driver {
5
5
  #private;
6
6
  constructor(config: SqliteDialectConfig);
7
+ /**
8
+ * Initializes the driver.
9
+ *
10
+ * After calling this method the driver should be usable and `acquireConnection` etc.
11
+ * methods should be callable.
12
+ *
13
+ * IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
14
+ * should be imported inside this function, not at the top of the driver file! This is
15
+ * important so that Kysely is usable without installing all database driver libraries
16
+ * it supports.
17
+ */
7
18
  init(): Promise<void>;
19
+ /**
20
+ * Acquires a new connection from the pool.
21
+ */
8
22
  acquireConnection(): Promise<DatabaseConnection>;
23
+ /**
24
+ * Begins a transaction.
25
+ */
9
26
  beginTransaction(connection: DatabaseConnection): Promise<void>;
27
+ /**
28
+ * Commits a transaction.
29
+ */
10
30
  commitTransaction(connection: DatabaseConnection): Promise<void>;
31
+ /**
32
+ * Rolls back a transaction.
33
+ */
11
34
  rollbackTransaction(connection: DatabaseConnection): Promise<void>;
35
+ /**
36
+ * Releases a connection back to the pool.
37
+ */
12
38
  releaseConnection(): Promise<void>;
39
+ /**
40
+ * Destroys the driver and releases all resources.
41
+ */
13
42
  destroy(): Promise<void>;
14
43
  }
@@ -3,5 +3,8 @@ import { Kysely } from '../../kysely.js';
3
3
  export declare class SqliteIntrospector implements DatabaseIntrospector {
4
4
  #private;
5
5
  constructor(db: Kysely<any>);
6
+ /**
7
+ * Get the database metadata such as the names of the tables and columns.
8
+ */
6
9
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
7
10
  }
@@ -4,5 +4,9 @@ import { Driver } from './driver.js';
4
4
  export declare class DefaultConnectionProvider implements ConnectionProvider {
5
5
  #private;
6
6
  constructor(driver: Driver);
7
+ /**
8
+ * Provides a connection for the callback and takes care of disposing
9
+ * the connection after the callback has been run.
10
+ */
7
11
  withConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
8
12
  }
@@ -9,11 +9,40 @@ import { Driver, TransactionSettings } from './driver.js';
9
9
  export declare class RuntimeDriver implements Driver {
10
10
  #private;
11
11
  constructor(driver: Driver, log: Log);
12
+ /**
13
+ * Initializes the driver.
14
+ *
15
+ * After calling this method the driver should be usable and `acquireConnection` etc.
16
+ * methods should be callable.
17
+ *
18
+ * IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
19
+ * should be imported inside this function, not at the top of the driver file! This is
20
+ * important so that Kysely is usable without installing all database driver libraries
21
+ * it supports.
22
+ */
12
23
  init(): Promise<void>;
24
+ /**
25
+ * Acquires a new connection from the pool.
26
+ */
13
27
  acquireConnection(): Promise<DatabaseConnection>;
28
+ /**
29
+ * Releases a connection back to the pool.
30
+ */
14
31
  releaseConnection(runtimeConnection: DatabaseConnection): Promise<void>;
32
+ /**
33
+ * Begins a transaction.
34
+ */
15
35
  beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
36
+ /**
37
+ * Commits a transaction.
38
+ */
16
39
  commitTransaction(connection: DatabaseConnection): Promise<void>;
40
+ /**
41
+ * Rolls back a transaction.
42
+ */
17
43
  rollbackTransaction(connection: DatabaseConnection): Promise<void>;
44
+ /**
45
+ * Destroys the driver and releases all resources.
46
+ */
18
47
  destroy(): Promise<void>;
19
48
  }
@@ -3,5 +3,9 @@ import { ConnectionProvider } from './connection-provider.js';
3
3
  export declare class SingleConnectionProvider implements ConnectionProvider {
4
4
  #private;
5
5
  constructor(connection: DatabaseConnection);
6
+ /**
7
+ * Provides a connection for the callback and takes care of disposing
8
+ * the connection after the callback has been run.
9
+ */
6
10
  withConnection<T>(runner: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
7
11
  }
@@ -16,3 +16,4 @@ export declare class DynamicReferenceBuilder<R extends string = never> implement
16
16
  constructor(reference: string);
17
17
  toOperationNode(): ReferenceNode | ColumnNode;
18
18
  }
19
+ export declare function isDynamicReferenceBuilder(obj: unknown): obj is DynamicReferenceBuilder<any>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DynamicReferenceBuilder = void 0;
3
+ exports.isDynamicReferenceBuilder = exports.DynamicReferenceBuilder = void 0;
4
+ const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
4
5
  const reference_parser_js_1 = require("../parser/reference-parser.js");
6
+ const object_utils_js_1 = require("../util/object-utils.js");
5
7
  class DynamicReferenceBuilder {
6
8
  #dynamicReference;
7
9
  get dynamicReference() {
@@ -26,3 +28,9 @@ class DynamicReferenceBuilder {
26
28
  }
27
29
  }
28
30
  exports.DynamicReferenceBuilder = DynamicReferenceBuilder;
31
+ function isDynamicReferenceBuilder(obj) {
32
+ return ((0, object_utils_js_1.isObject)(obj) &&
33
+ (0, operation_node_source_js_1.isOperationNodeSource)(obj) &&
34
+ (0, object_utils_js_1.isString)(obj.dynamicReference));
35
+ }
36
+ exports.isDynamicReferenceBuilder = isDynamicReferenceBuilder;
@@ -20,7 +20,8 @@ export declare class DynamicModule {
20
20
  * `ref` to other methods as well. If the types allow you to pass a `ref`
21
21
  * value to some place, it should work.
22
22
  *
23
- * @example
23
+ * ### Examples
24
+ *
24
25
  * Filter by a column not know at compile time:
25
26
  *
26
27
  * ```ts
@@ -38,7 +39,6 @@ export declare class DynamicModule {
38
39
  * someQuery('person.last_name', 'Aniston')
39
40
  * ```
40
41
  *
41
- * @example
42
42
  * Order by a column not know at compile time:
43
43
  *
44
44
  * ```ts
@@ -55,7 +55,6 @@ export declare class DynamicModule {
55
55
  * someQuery('fn')
56
56
  * ```
57
57
  *
58
- * @example
59
58
  * In this example we add selections dynamically:
60
59
  *
61
60
  * ```ts
@@ -66,7 +65,7 @@ export declare class DynamicModule {
66
65
  *
67
66
  * // A type that lists all possible values `columnFromUserInput` can have.
68
67
  * // You can use `keyof Person` if any column of an interface is allowed.
69
- * type PossibleColumns = 'last_name' | 'first_name' | 'birth_date'
68
+ * type PossibleColumns = 'last_name' | 'first_name' | 'birth_date'
70
69
  *
71
70
  * const [person] = await db.selectFrom('person')
72
71
  * .select([
@@ -78,9 +77,9 @@ export declare class DynamicModule {
78
77
  * // The resulting type contains all `PossibleColumns` as optional fields
79
78
  * // because we cannot know which field was actually selected before
80
79
  * // running the code.
81
- * const lastName: string | undefined = person.last_name
82
- * const firstName: string | undefined = person.first_name
83
- * const birthDate: string | undefined = person.birth_date
80
+ * const lastName: string | undefined = person.last_name
81
+ * const firstName: string | undefined = person.first_name
82
+ * const birthDate: string | undefined = person.birth_date
84
83
  *
85
84
  * // The result type also contains the compile time selection `id`.
86
85
  * person.id
@@ -23,7 +23,8 @@ class DynamicModule {
23
23
  * `ref` to other methods as well. If the types allow you to pass a `ref`
24
24
  * value to some place, it should work.
25
25
  *
26
- * @example
26
+ * ### Examples
27
+ *
27
28
  * Filter by a column not know at compile time:
28
29
  *
29
30
  * ```ts
@@ -41,7 +42,6 @@ class DynamicModule {
41
42
  * someQuery('person.last_name', 'Aniston')
42
43
  * ```
43
44
  *
44
- * @example
45
45
  * Order by a column not know at compile time:
46
46
  *
47
47
  * ```ts
@@ -58,7 +58,6 @@ class DynamicModule {
58
58
  * someQuery('fn')
59
59
  * ```
60
60
  *
61
- * @example
62
61
  * In this example we add selections dynamically:
63
62
  *
64
63
  * ```ts
@@ -69,7 +68,7 @@ class DynamicModule {
69
68
  *
70
69
  * // A type that lists all possible values `columnFromUserInput` can have.
71
70
  * // You can use `keyof Person` if any column of an interface is allowed.
72
- * type PossibleColumns = 'last_name' | 'first_name' | 'birth_date'
71
+ * type PossibleColumns = 'last_name' | 'first_name' | 'birth_date'
73
72
  *
74
73
  * const [person] = await db.selectFrom('person')
75
74
  * .select([
@@ -81,9 +80,9 @@ class DynamicModule {
81
80
  * // The resulting type contains all `PossibleColumns` as optional fields
82
81
  * // because we cannot know which field was actually selected before
83
82
  * // running the code.
84
- * const lastName: string | undefined = person.last_name
85
- * const firstName: string | undefined = person.first_name
86
- * const birthDate: string | undefined = person.birth_date
83
+ * const lastName: string | undefined = person.last_name
84
+ * const firstName: string | undefined = person.first_name
85
+ * const birthDate: string | undefined = person.birth_date
87
86
  *
88
87
  * // The result type also contains the compile time selection `id`.
89
88
  * person.id