kysely 0.11.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) 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/mysql/mysql-query-compiler.d.ts +0 -2
  8. package/dist/cjs/dialect/mysql/mysql-query-compiler.js +0 -6
  9. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +36 -0
  10. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +16 -0
  11. package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
  12. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +3 -0
  13. package/dist/cjs/dialect/postgres/postgres-query-compiler.d.ts +3 -0
  14. package/dist/cjs/dialect/postgres/postgres-query-compiler.js +9 -1
  15. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  16. package/dist/cjs/dialect/sqlite/sqlite-adapter.js +6 -2
  17. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  18. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
  19. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  20. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +2 -2
  21. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +6 -6
  22. package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
  23. package/dist/cjs/driver/runtime-driver.d.ts +29 -0
  24. package/dist/cjs/driver/runtime-driver.js +1 -1
  25. package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
  26. package/dist/cjs/dynamic/dynamic-reference-builder.d.ts +1 -0
  27. package/dist/cjs/dynamic/dynamic-reference-builder.js +9 -1
  28. package/dist/cjs/dynamic/dynamic.d.ts +6 -7
  29. package/dist/cjs/dynamic/dynamic.js +6 -7
  30. package/dist/cjs/index.d.ts +14 -3
  31. package/dist/cjs/index.js +12 -1
  32. package/dist/cjs/kysely.d.ts +39 -15
  33. package/dist/cjs/kysely.js +32 -9
  34. package/dist/cjs/migration/migration.d.ts +2 -2
  35. package/dist/cjs/operation-node/create-table-node.d.ts +6 -2
  36. package/dist/cjs/operation-node/create-table-node.js +6 -6
  37. package/dist/cjs/operation-node/create-view-node.d.ts +1 -0
  38. package/dist/cjs/operation-node/insert-query-node.d.ts +4 -4
  39. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  40. package/dist/cjs/operation-node/operation-node-transformer.js +11 -1
  41. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  42. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  43. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  44. package/dist/cjs/operation-node/query-node.d.ts +0 -2
  45. package/dist/cjs/operation-node/query-node.js +0 -10
  46. package/dist/cjs/operation-node/values-node.d.ts +15 -0
  47. package/dist/cjs/operation-node/values-node.js +18 -0
  48. package/dist/cjs/package.json +1 -3
  49. package/dist/cjs/parser/complex-expression-parser.d.ts +9 -0
  50. package/dist/cjs/parser/complex-expression-parser.js +25 -0
  51. package/dist/cjs/parser/filter-parser.d.ts +13 -4
  52. package/dist/cjs/parser/filter-parser.js +21 -24
  53. package/dist/cjs/parser/insert-values-parser.d.ts +7 -10
  54. package/dist/cjs/parser/insert-values-parser.js +31 -39
  55. package/dist/cjs/parser/order-by-parser.d.ts +1 -1
  56. package/dist/cjs/parser/parse-context.d.ts +22 -8
  57. package/dist/cjs/parser/parse-context.js +10 -10
  58. package/dist/cjs/parser/reference-parser.d.ts +8 -7
  59. package/dist/cjs/parser/reference-parser.js +8 -17
  60. package/dist/cjs/parser/returning-parser.d.ts +1 -5
  61. package/dist/cjs/parser/select-parser.d.ts +12 -14
  62. package/dist/cjs/parser/select-parser.js +5 -9
  63. package/dist/cjs/parser/table-parser.d.ts +9 -11
  64. package/dist/cjs/parser/table-parser.js +2 -8
  65. package/dist/cjs/parser/union-parser.d.ts +2 -2
  66. package/dist/cjs/parser/union-parser.js +1 -6
  67. package/dist/cjs/parser/update-set-parser.d.ts +2 -8
  68. package/dist/cjs/parser/update-set-parser.js +6 -26
  69. package/dist/cjs/parser/value-parser.d.ts +9 -6
  70. package/dist/cjs/parser/value-parser.js +7 -30
  71. package/dist/cjs/parser/with-parser.d.ts +6 -3
  72. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  73. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  74. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  75. package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -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 +2 -0
  103. package/dist/cjs/query-compiler/default-query-compiler.js +22 -5
  104. package/dist/cjs/query-creator.d.ts +42 -40
  105. package/dist/cjs/query-creator.js +33 -28
  106. package/dist/cjs/query-executor/query-executor.d.ts +1 -1
  107. package/dist/cjs/query-executor/query-executor.js +1 -1
  108. package/dist/cjs/raw-builder/raw-builder.d.ts +2 -0
  109. package/dist/cjs/raw-builder/raw-builder.js +6 -0
  110. package/dist/cjs/schema/alter-table-builder.d.ts +218 -2
  111. package/dist/cjs/schema/column-definition-builder.d.ts +135 -20
  112. package/dist/cjs/schema/create-index-builder.d.ts +2 -1
  113. package/dist/cjs/schema/create-index-builder.js +2 -1
  114. package/dist/cjs/schema/create-table-builder.d.ts +26 -9
  115. package/dist/cjs/schema/create-table-builder.js +42 -9
  116. package/dist/cjs/schema/create-view-builder.d.ts +17 -3
  117. package/dist/cjs/schema/create-view-builder.js +25 -16
  118. package/dist/cjs/schema/schema.d.ts +18 -11
  119. package/dist/cjs/schema/schema.js +18 -11
  120. package/dist/cjs/util/log.d.ts +11 -8
  121. package/dist/cjs/util/log.js +25 -12
  122. package/dist/cjs/util/type-utils.d.ts +7 -7
  123. package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
  124. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +36 -0
  125. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +16 -0
  126. package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
  127. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
  128. package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +0 -2
  129. package/dist/esm/dialect/mysql/mysql-query-compiler.js +0 -6
  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/postgres/postgres-query-compiler.d.ts +3 -0
  135. package/dist/esm/dialect/postgres/postgres-query-compiler.js +9 -1
  136. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +36 -0
  137. package/dist/esm/dialect/sqlite/sqlite-adapter.js +6 -2
  138. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  139. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
  140. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  141. package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +2 -2
  142. package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +6 -6
  143. package/dist/esm/driver/default-connection-provider.d.ts +4 -0
  144. package/dist/esm/driver/runtime-driver.d.ts +29 -0
  145. package/dist/esm/driver/runtime-driver.js +1 -1
  146. package/dist/esm/driver/single-connection-provider.d.ts +4 -0
  147. package/dist/esm/dynamic/dynamic-reference-builder.d.ts +1 -0
  148. package/dist/esm/dynamic/dynamic-reference-builder.js +7 -0
  149. package/dist/esm/dynamic/dynamic.d.ts +6 -7
  150. package/dist/esm/dynamic/dynamic.js +6 -7
  151. package/dist/esm/index.d.ts +14 -3
  152. package/dist/esm/index.js +12 -1
  153. package/dist/esm/kysely.d.ts +39 -15
  154. package/dist/esm/kysely.js +32 -9
  155. package/dist/esm/migration/migration.d.ts +2 -2
  156. package/dist/esm/operation-node/create-table-node.d.ts +6 -2
  157. package/dist/esm/operation-node/create-table-node.js +6 -6
  158. package/dist/esm/operation-node/create-view-node.d.ts +1 -0
  159. package/dist/esm/operation-node/insert-query-node.d.ts +4 -4
  160. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  161. package/dist/esm/operation-node/operation-node-transformer.js +11 -1
  162. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  163. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  164. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  165. package/dist/esm/operation-node/query-node.d.ts +0 -2
  166. package/dist/esm/operation-node/query-node.js +0 -10
  167. package/dist/esm/operation-node/values-node.d.ts +15 -0
  168. package/dist/esm/operation-node/values-node.js +15 -0
  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 +6 -3
  193. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +34 -0
  194. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  195. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  196. package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  197. package/dist/esm/query-builder/delete-query-builder.d.ts +647 -0
  198. package/dist/esm/query-builder/delete-query-builder.js +181 -0
  199. package/dist/esm/query-builder/expression-builder.d.ts +8 -6
  200. package/dist/esm/query-builder/expression-builder.js +3 -3
  201. package/dist/esm/query-builder/function-builder.d.ts +2 -1
  202. package/dist/esm/query-builder/function-builder.js +2 -1
  203. package/dist/esm/query-builder/having-interface.d.ts +49 -0
  204. package/dist/esm/query-builder/having-interface.js +1 -0
  205. package/dist/esm/query-builder/insert-query-builder.d.ts +504 -0
  206. package/dist/esm/query-builder/insert-query-builder.js +252 -0
  207. package/dist/esm/query-builder/insert-result.d.ts +3 -2
  208. package/dist/esm/query-builder/insert-result.js +3 -2
  209. package/dist/esm/query-builder/join-builder.d.ts +19 -20
  210. package/dist/esm/query-builder/join-builder.js +12 -12
  211. package/dist/esm/query-builder/join-interface.d.ts +130 -0
  212. package/dist/esm/query-builder/join-interface.js +1 -0
  213. package/dist/esm/query-builder/no-result-error.d.ts +9 -0
  214. package/dist/esm/query-builder/no-result-error.js +10 -0
  215. package/dist/esm/query-builder/returning-interface.d.ts +73 -0
  216. package/dist/esm/query-builder/returning-interface.js +1 -0
  217. package/dist/esm/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -634
  218. package/dist/esm/query-builder/select-query-builder.js +566 -0
  219. package/dist/esm/query-builder/update-query-builder.d.ts +735 -0
  220. package/dist/esm/query-builder/update-query-builder.js +275 -0
  221. package/dist/esm/query-builder/where-interface.d.ts +378 -0
  222. package/dist/esm/query-builder/where-interface.js +1 -0
  223. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
  224. package/dist/esm/query-compiler/default-query-compiler.js +22 -5
  225. package/dist/esm/query-creator.d.ts +42 -40
  226. package/dist/esm/query-creator.js +33 -28
  227. package/dist/esm/query-executor/query-executor.d.ts +1 -1
  228. package/dist/esm/query-executor/query-executor.js +1 -1
  229. package/dist/esm/raw-builder/raw-builder.d.ts +2 -0
  230. package/dist/esm/raw-builder/raw-builder.js +6 -0
  231. package/dist/esm/schema/alter-table-builder.d.ts +218 -2
  232. package/dist/esm/schema/column-definition-builder.d.ts +135 -20
  233. package/dist/esm/schema/create-index-builder.d.ts +2 -1
  234. package/dist/esm/schema/create-index-builder.js +2 -1
  235. package/dist/esm/schema/create-table-builder.d.ts +26 -9
  236. package/dist/esm/schema/create-table-builder.js +43 -10
  237. package/dist/esm/schema/create-view-builder.d.ts +17 -3
  238. package/dist/esm/schema/create-view-builder.js +25 -16
  239. package/dist/esm/schema/schema.d.ts +18 -11
  240. package/dist/esm/schema/schema.js +18 -11
  241. package/dist/esm/util/log.d.ts +11 -8
  242. package/dist/esm/util/log.js +25 -12
  243. package/dist/esm/util/type-utils.d.ts +7 -7
  244. package/package.json +9 -7
  245. package/dist/cjs/query-builder/query-builder.js +0 -1067
  246. 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,7 +1,5 @@
1
1
  import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
2
2
  export declare class MysqlQueryCompiler extends DefaultQueryCompiler {
3
- protected visitReturning(): void;
4
- protected getSql(): string;
5
3
  protected getCurrentParameterPlaceholder(): string;
6
4
  protected getLeftIdentifierWrapper(): string;
7
5
  protected getRightIdentifierWrapper(): string;
@@ -3,12 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MysqlQueryCompiler = void 0;
4
4
  const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
5
5
  class MysqlQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
6
- visitReturning() {
7
- // Do nothing.
8
- }
9
- getSql() {
10
- return super.getSql().trimEnd();
11
- }
12
6
  getCurrentParameterPlaceholder() {
13
7
  return '?';
14
8
  }
@@ -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,3 +1,6 @@
1
1
  import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
2
2
  export declare class PostgresQueryCompiler extends DefaultQueryCompiler {
3
+ protected getCurrentParameterPlaceholder(): string;
4
+ protected getLeftIdentifierWrapper(): string;
5
+ protected getRightIdentifierWrapper(): string;
3
6
  }
@@ -2,7 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresQueryCompiler = void 0;
4
4
  const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
5
- // The default query compiler is for PostgreSQL.
6
5
  class PostgresQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
6
+ getCurrentParameterPlaceholder() {
7
+ return '$' + this.numParameters;
8
+ }
9
+ getLeftIdentifierWrapper() {
10
+ return '"';
11
+ }
12
+ getRightIdentifierWrapper() {
13
+ return '"';
14
+ }
7
15
  }
8
16
  exports.PostgresQueryCompiler = PostgresQueryCompiler;
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
2
2
  export declare class SqliteQueryCompiler extends DefaultQueryCompiler {
3
- protected visitReturning(): void;
4
- protected getSql(): string;
5
3
  protected getCurrentParameterPlaceholder(): string;
4
+ protected getLeftIdentifierWrapper(): string;
5
+ protected getRightIdentifierWrapper(): string;
6
6
  protected getAutoIncrement(): string;
7
7
  }
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteQueryCompiler = void 0;
4
4
  const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
5
5
  class SqliteQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
6
- visitReturning() {
7
- // Do nothing.
8
- }
9
- getSql() {
10
- return super.getSql().trimEnd();
11
- }
12
6
  getCurrentParameterPlaceholder() {
13
7
  return '?';
14
8
  }
9
+ getLeftIdentifierWrapper() {
10
+ return '"';
11
+ }
12
+ getRightIdentifierWrapper() {
13
+ return '"';
14
+ }
15
15
  getAutoIncrement() {
16
16
  return 'autoincrement';
17
17
  }
@@ -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
  }
@@ -97,7 +97,7 @@ class RuntimeConnection {
97
97
  #logQuery(compiledQuery, startTime) {
98
98
  this.#log.query(() => ({
99
99
  level: 'query',
100
- sql: compiledQuery.sql,
100
+ query: compiledQuery,
101
101
  queryDurationMillis: this.#calculateDurationMillis(startTime),
102
102
  }));
103
103
  }
@@ -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;