kysely 0.11.4 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +35 -11
  2. package/dist/cjs/dialect/dialect-adapter-base.d.ts +36 -0
  3. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +38 -2
  4. package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -1
  5. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +16 -0
  6. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
  7. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +3 -0
  8. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +38 -2
  9. package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -1
  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/sqlite/sqlite-adapter.d.ts +38 -2
  14. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  15. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
  16. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  17. package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
  18. package/dist/cjs/driver/runtime-driver.d.ts +29 -0
  19. package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
  20. package/dist/cjs/dynamic/dynamic-reference-builder.d.ts +1 -0
  21. package/dist/cjs/dynamic/dynamic-reference-builder.js +9 -1
  22. package/dist/cjs/dynamic/dynamic.d.ts +6 -7
  23. package/dist/cjs/dynamic/dynamic.js +6 -7
  24. package/dist/cjs/index.d.ts +15 -4
  25. package/dist/cjs/index.js +12 -1
  26. package/dist/cjs/kysely.d.ts +170 -11
  27. package/dist/cjs/kysely.js +69 -9
  28. package/dist/cjs/migration/migration.d.ts +156 -13
  29. package/dist/cjs/migration/migration.js +256 -135
  30. package/dist/cjs/operation-node/column-definition-node.d.ts +6 -5
  31. package/dist/cjs/operation-node/column-definition-node.js +0 -4
  32. package/dist/cjs/operation-node/common-table-expression-name-node.d.ts +15 -0
  33. package/dist/cjs/operation-node/common-table-expression-name-node.js +23 -0
  34. package/dist/cjs/operation-node/common-table-expression-node.d.ts +3 -3
  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 +4 -0
  40. package/dist/cjs/operation-node/operation-node-transformer.js +22 -2
  41. package/dist/cjs/operation-node/operation-node-visitor.d.ts +4 -0
  42. package/dist/cjs/operation-node/operation-node-visitor.js +2 -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/operation-node/with-node.d.ts +3 -1
  49. package/dist/cjs/operation-node/with-node.js +2 -1
  50. package/dist/cjs/package.json +1 -3
  51. package/dist/cjs/parser/complex-expression-parser.d.ts +9 -0
  52. package/dist/cjs/parser/complex-expression-parser.js +25 -0
  53. package/dist/cjs/parser/filter-parser.d.ts +13 -4
  54. package/dist/cjs/parser/filter-parser.js +21 -24
  55. package/dist/cjs/parser/insert-values-parser.d.ts +5 -9
  56. package/dist/cjs/parser/insert-values-parser.js +27 -41
  57. package/dist/cjs/parser/order-by-parser.d.ts +1 -1
  58. package/dist/cjs/parser/parse-context.d.ts +22 -8
  59. package/dist/cjs/parser/parse-context.js +10 -10
  60. package/dist/cjs/parser/reference-parser.d.ts +8 -7
  61. package/dist/cjs/parser/reference-parser.js +8 -17
  62. package/dist/cjs/parser/returning-parser.d.ts +1 -5
  63. package/dist/cjs/parser/select-parser.d.ts +12 -14
  64. package/dist/cjs/parser/select-parser.js +5 -9
  65. package/dist/cjs/parser/table-parser.d.ts +9 -11
  66. package/dist/cjs/parser/table-parser.js +2 -8
  67. package/dist/cjs/parser/union-parser.d.ts +2 -2
  68. package/dist/cjs/parser/union-parser.js +1 -6
  69. package/dist/cjs/parser/update-set-parser.d.ts +2 -8
  70. package/dist/cjs/parser/update-set-parser.js +6 -26
  71. package/dist/cjs/parser/value-parser.d.ts +9 -6
  72. package/dist/cjs/parser/value-parser.js +7 -30
  73. package/dist/cjs/parser/with-parser.d.ts +36 -6
  74. package/dist/cjs/parser/with-parser.js +13 -2
  75. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +36 -2
  76. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  77. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  78. package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  79. package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
  80. package/dist/cjs/query-builder/delete-query-builder.d.ts +647 -0
  81. package/dist/cjs/query-builder/delete-query-builder.js +185 -0
  82. package/dist/cjs/query-builder/expression-builder.d.ts +8 -6
  83. package/dist/cjs/query-builder/expression-builder.js +3 -3
  84. package/dist/cjs/query-builder/function-builder.d.ts +2 -1
  85. package/dist/cjs/query-builder/function-builder.js +2 -1
  86. package/dist/cjs/query-builder/having-interface.d.ts +49 -0
  87. package/dist/cjs/query-builder/having-interface.js +2 -0
  88. package/dist/cjs/query-builder/insert-query-builder.d.ts +504 -0
  89. package/dist/cjs/query-builder/insert-query-builder.js +256 -0
  90. package/dist/cjs/query-builder/insert-result.d.ts +3 -2
  91. package/dist/cjs/query-builder/insert-result.js +3 -2
  92. package/dist/cjs/query-builder/join-builder.d.ts +19 -20
  93. package/dist/cjs/query-builder/join-builder.js +12 -12
  94. package/dist/cjs/query-builder/join-interface.d.ts +130 -0
  95. package/dist/cjs/query-builder/join-interface.js +2 -0
  96. package/dist/cjs/query-builder/no-result-error.d.ts +9 -0
  97. package/dist/cjs/query-builder/no-result-error.js +14 -0
  98. package/dist/cjs/query-builder/returning-interface.d.ts +73 -0
  99. package/dist/cjs/query-builder/returning-interface.js +2 -0
  100. package/dist/cjs/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -651
  101. package/dist/cjs/query-builder/select-query-builder.js +571 -0
  102. package/dist/cjs/query-builder/update-query-builder.d.ts +735 -0
  103. package/dist/cjs/query-builder/update-query-builder.js +279 -0
  104. package/dist/cjs/query-builder/where-interface.d.ts +378 -0
  105. package/dist/cjs/query-builder/where-interface.js +2 -0
  106. package/dist/cjs/query-compiler/default-query-compiler.d.ts +4 -0
  107. package/dist/cjs/query-compiler/default-query-compiler.js +37 -6
  108. package/dist/cjs/query-creator.d.ts +69 -43
  109. package/dist/cjs/query-creator.js +66 -29
  110. package/dist/cjs/query-executor/default-query-executor.d.ts +19 -0
  111. package/dist/cjs/query-executor/noop-query-executor.d.ts +19 -0
  112. package/dist/cjs/query-executor/query-executor.d.ts +1 -1
  113. package/dist/cjs/query-executor/query-executor.js +1 -1
  114. package/dist/cjs/raw-builder/raw-builder.d.ts +2 -0
  115. package/dist/cjs/raw-builder/raw-builder.js +7 -1
  116. package/dist/cjs/schema/alter-table-builder.d.ts +230 -2
  117. package/dist/cjs/schema/alter-table-builder.js +12 -0
  118. package/dist/cjs/schema/column-definition-builder.d.ts +147 -20
  119. package/dist/cjs/schema/column-definition-builder.js +4 -1
  120. package/dist/cjs/schema/create-index-builder.d.ts +2 -1
  121. package/dist/cjs/schema/create-index-builder.js +2 -1
  122. package/dist/cjs/schema/create-table-builder.d.ts +26 -9
  123. package/dist/cjs/schema/create-table-builder.js +42 -9
  124. package/dist/cjs/schema/create-view-builder.d.ts +17 -3
  125. package/dist/cjs/schema/create-view-builder.js +25 -16
  126. package/dist/cjs/schema/schema.d.ts +18 -11
  127. package/dist/cjs/schema/schema.js +18 -11
  128. package/dist/cjs/util/log.d.ts +3 -2
  129. package/dist/cjs/util/log.js +8 -15
  130. package/dist/cjs/util/type-utils.d.ts +7 -7
  131. package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
  132. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +38 -2
  133. package/dist/esm/dialect/mysql/mysql-adapter.js +2 -1
  134. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +16 -0
  135. package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
  136. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
  137. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +38 -2
  138. package/dist/esm/dialect/postgres/postgres-adapter.js +2 -1
  139. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +16 -0
  140. package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
  141. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +3 -0
  142. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +38 -2
  143. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
  144. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
  145. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
  146. package/dist/esm/driver/default-connection-provider.d.ts +4 -0
  147. package/dist/esm/driver/runtime-driver.d.ts +29 -0
  148. package/dist/esm/driver/single-connection-provider.d.ts +4 -0
  149. package/dist/esm/dynamic/dynamic-reference-builder.d.ts +1 -0
  150. package/dist/esm/dynamic/dynamic-reference-builder.js +7 -0
  151. package/dist/esm/dynamic/dynamic.d.ts +6 -7
  152. package/dist/esm/dynamic/dynamic.js +6 -7
  153. package/dist/esm/index.d.ts +15 -4
  154. package/dist/esm/index.js +12 -1
  155. package/dist/esm/kysely.d.ts +170 -11
  156. package/dist/esm/kysely.js +69 -9
  157. package/dist/esm/migration/migration.d.ts +156 -13
  158. package/dist/esm/migration/migration.js +255 -134
  159. package/dist/esm/operation-node/column-definition-node.d.ts +6 -5
  160. package/dist/esm/operation-node/column-definition-node.js +0 -4
  161. package/dist/esm/operation-node/common-table-expression-name-node.d.ts +15 -0
  162. package/dist/esm/operation-node/common-table-expression-name-node.js +20 -0
  163. package/dist/esm/operation-node/common-table-expression-node.d.ts +3 -3
  164. package/dist/esm/operation-node/create-table-node.d.ts +6 -2
  165. package/dist/esm/operation-node/create-table-node.js +6 -6
  166. package/dist/esm/operation-node/create-view-node.d.ts +1 -0
  167. package/dist/esm/operation-node/insert-query-node.d.ts +4 -4
  168. package/dist/esm/operation-node/operation-node-transformer.d.ts +4 -0
  169. package/dist/esm/operation-node/operation-node-transformer.js +22 -2
  170. package/dist/esm/operation-node/operation-node-visitor.d.ts +4 -0
  171. package/dist/esm/operation-node/operation-node-visitor.js +2 -0
  172. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  173. package/dist/esm/operation-node/query-node.d.ts +0 -2
  174. package/dist/esm/operation-node/query-node.js +0 -10
  175. package/dist/esm/operation-node/values-node.d.ts +15 -0
  176. package/dist/esm/operation-node/values-node.js +15 -0
  177. package/dist/esm/operation-node/with-node.d.ts +3 -1
  178. package/dist/esm/operation-node/with-node.js +2 -1
  179. package/dist/esm/package.json +1 -3
  180. package/dist/esm/parser/complex-expression-parser.d.ts +9 -0
  181. package/dist/esm/parser/complex-expression-parser.js +20 -0
  182. package/dist/esm/parser/filter-parser.d.ts +13 -4
  183. package/dist/esm/parser/filter-parser.js +21 -24
  184. package/dist/esm/parser/insert-values-parser.d.ts +5 -9
  185. package/dist/esm/parser/insert-values-parser.js +27 -40
  186. package/dist/esm/parser/order-by-parser.d.ts +1 -1
  187. package/dist/esm/parser/parse-context.d.ts +22 -8
  188. package/dist/esm/parser/parse-context.js +10 -10
  189. package/dist/esm/parser/reference-parser.d.ts +8 -7
  190. package/dist/esm/parser/reference-parser.js +9 -18
  191. package/dist/esm/parser/returning-parser.d.ts +1 -5
  192. package/dist/esm/parser/select-parser.d.ts +12 -14
  193. package/dist/esm/parser/select-parser.js +6 -10
  194. package/dist/esm/parser/table-parser.d.ts +9 -11
  195. package/dist/esm/parser/table-parser.js +3 -9
  196. package/dist/esm/parser/union-parser.d.ts +2 -2
  197. package/dist/esm/parser/union-parser.js +1 -6
  198. package/dist/esm/parser/update-set-parser.d.ts +2 -8
  199. package/dist/esm/parser/update-set-parser.js +5 -24
  200. package/dist/esm/parser/value-parser.d.ts +9 -6
  201. package/dist/esm/parser/value-parser.js +8 -31
  202. package/dist/esm/parser/with-parser.d.ts +36 -6
  203. package/dist/esm/parser/with-parser.js +13 -2
  204. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +36 -2
  205. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
  206. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.js +2 -2
  207. package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
  208. package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
  209. package/dist/esm/query-builder/delete-query-builder.d.ts +647 -0
  210. package/dist/esm/query-builder/delete-query-builder.js +181 -0
  211. package/dist/esm/query-builder/expression-builder.d.ts +8 -6
  212. package/dist/esm/query-builder/expression-builder.js +3 -3
  213. package/dist/esm/query-builder/function-builder.d.ts +2 -1
  214. package/dist/esm/query-builder/function-builder.js +2 -1
  215. package/dist/esm/query-builder/having-interface.d.ts +49 -0
  216. package/dist/esm/query-builder/having-interface.js +1 -0
  217. package/dist/esm/query-builder/insert-query-builder.d.ts +504 -0
  218. package/dist/esm/query-builder/insert-query-builder.js +252 -0
  219. package/dist/esm/query-builder/insert-result.d.ts +3 -2
  220. package/dist/esm/query-builder/insert-result.js +3 -2
  221. package/dist/esm/query-builder/join-builder.d.ts +19 -20
  222. package/dist/esm/query-builder/join-builder.js +12 -12
  223. package/dist/esm/query-builder/join-interface.d.ts +130 -0
  224. package/dist/esm/query-builder/join-interface.js +1 -0
  225. package/dist/esm/query-builder/no-result-error.d.ts +9 -0
  226. package/dist/esm/query-builder/no-result-error.js +10 -0
  227. package/dist/esm/query-builder/returning-interface.d.ts +73 -0
  228. package/dist/esm/query-builder/returning-interface.js +1 -0
  229. package/dist/esm/query-builder/{query-builder.d.ts → select-query-builder.d.ts} +145 -651
  230. package/dist/esm/query-builder/select-query-builder.js +566 -0
  231. package/dist/esm/query-builder/update-query-builder.d.ts +735 -0
  232. package/dist/esm/query-builder/update-query-builder.js +275 -0
  233. package/dist/esm/query-builder/where-interface.d.ts +378 -0
  234. package/dist/esm/query-builder/where-interface.js +1 -0
  235. package/dist/esm/query-compiler/default-query-compiler.d.ts +4 -0
  236. package/dist/esm/query-compiler/default-query-compiler.js +37 -6
  237. package/dist/esm/query-creator.d.ts +69 -43
  238. package/dist/esm/query-creator.js +66 -29
  239. package/dist/esm/query-executor/default-query-executor.d.ts +19 -0
  240. package/dist/esm/query-executor/noop-query-executor.d.ts +19 -0
  241. package/dist/esm/query-executor/query-executor.d.ts +1 -1
  242. package/dist/esm/query-executor/query-executor.js +1 -1
  243. package/dist/esm/raw-builder/raw-builder.d.ts +2 -0
  244. package/dist/esm/raw-builder/raw-builder.js +7 -1
  245. package/dist/esm/schema/alter-table-builder.d.ts +230 -2
  246. package/dist/esm/schema/alter-table-builder.js +12 -0
  247. package/dist/esm/schema/column-definition-builder.d.ts +147 -20
  248. package/dist/esm/schema/column-definition-builder.js +4 -1
  249. package/dist/esm/schema/create-index-builder.d.ts +2 -1
  250. package/dist/esm/schema/create-index-builder.js +2 -1
  251. package/dist/esm/schema/create-table-builder.d.ts +26 -9
  252. package/dist/esm/schema/create-table-builder.js +43 -10
  253. package/dist/esm/schema/create-view-builder.d.ts +17 -3
  254. package/dist/esm/schema/create-view-builder.js +25 -16
  255. package/dist/esm/schema/schema.d.ts +18 -11
  256. package/dist/esm/schema/schema.js +18 -11
  257. package/dist/esm/util/log.d.ts +3 -2
  258. package/dist/esm/util/log.js +7 -14
  259. package/dist/esm/util/type-utils.d.ts +7 -7
  260. package/package.json +10 -8
  261. package/dist/cjs/query-builder/query-builder.js +0 -1067
  262. package/dist/esm/query-builder/query-builder.js +0 -1061
@@ -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
@@ -1,8 +1,17 @@
1
1
  export * from './kysely.js';
2
2
  export * from './query-creator.js';
3
- export * from './query-builder/query-builder.js';
3
+ export * from './query-builder/where-interface.js';
4
+ export * from './query-builder/join-interface.js';
5
+ export * from './query-builder/returning-interface.js';
6
+ export * from './query-builder/having-interface.js';
7
+ export * from './query-builder/select-query-builder.js';
8
+ export * from './query-builder/insert-query-builder.js';
9
+ export * from './query-builder/update-query-builder.js';
10
+ export * from './query-builder/delete-query-builder.js';
11
+ export * from './query-builder/no-result-error.js';
4
12
  export * from './query-builder/join-builder.js';
5
13
  export * from './query-builder/expression-builder.js';
14
+ export * from './query-builder/function-builder.js';
6
15
  export * from './query-builder/insert-result.js';
7
16
  export * from './query-builder/delete-result.js';
8
17
  export * from './query-builder/update-result.js';
@@ -64,6 +73,7 @@ export * from './operation-node/column-definition-node.js';
64
73
  export * from './operation-node/column-node.js';
65
74
  export * from './operation-node/column-update-node.js';
66
75
  export * from './operation-node/common-table-expression-node.js';
76
+ export * from './operation-node/common-table-expression-name-node.js';
67
77
  export * from './operation-node/constraint-node.js';
68
78
  export * from './operation-node/create-index-node.js';
69
79
  export * from './operation-node/create-schema-node.js';
@@ -123,16 +133,17 @@ export * from './operation-node/unique-constraint-node.js';
123
133
  export * from './operation-node/update-query-node.js';
124
134
  export * from './operation-node/value-list-node.js';
125
135
  export * from './operation-node/value-node.js';
136
+ export * from './operation-node/values-node.js';
126
137
  export * from './operation-node/where-node.js';
127
138
  export * from './operation-node/with-node.js';
128
139
  export * from './introspection/database-introspector.js';
129
140
  export * from './util/compilable.js';
130
141
  export * from './util/log.js';
131
- export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
132
- export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
142
+ export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
143
+ export { SelectExpression, SelectExpressionOrList, Selection, } from './parser/select-parser.js';
133
144
  export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
134
145
  export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
135
- export { ExistsExpression, FilterOperator } from './parser/filter-parser.js';
146
+ export { FilterValueExpression, FilterValueExpressionOrList, ExistsExpression, FilterOperator, } from './parser/filter-parser.js';
136
147
  export { TableExpression, TableExpressionOrList, } from './parser/table-parser.js';
137
148
  export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-parser.js';
138
149
  export { InsertObject } from './parser/insert-values-parser.js';
package/dist/cjs/index.js CHANGED
@@ -12,9 +12,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./kysely.js"), exports);
14
14
  __exportStar(require("./query-creator.js"), exports);
15
- __exportStar(require("./query-builder/query-builder.js"), exports);
15
+ __exportStar(require("./query-builder/where-interface.js"), exports);
16
+ __exportStar(require("./query-builder/join-interface.js"), exports);
17
+ __exportStar(require("./query-builder/returning-interface.js"), exports);
18
+ __exportStar(require("./query-builder/having-interface.js"), exports);
19
+ __exportStar(require("./query-builder/select-query-builder.js"), exports);
20
+ __exportStar(require("./query-builder/insert-query-builder.js"), exports);
21
+ __exportStar(require("./query-builder/update-query-builder.js"), exports);
22
+ __exportStar(require("./query-builder/delete-query-builder.js"), exports);
23
+ __exportStar(require("./query-builder/no-result-error.js"), exports);
16
24
  __exportStar(require("./query-builder/join-builder.js"), exports);
17
25
  __exportStar(require("./query-builder/expression-builder.js"), exports);
26
+ __exportStar(require("./query-builder/function-builder.js"), exports);
18
27
  __exportStar(require("./query-builder/insert-result.js"), exports);
19
28
  __exportStar(require("./query-builder/delete-result.js"), exports);
20
29
  __exportStar(require("./query-builder/update-result.js"), exports);
@@ -76,6 +85,7 @@ __exportStar(require("./operation-node/column-definition-node.js"), exports);
76
85
  __exportStar(require("./operation-node/column-node.js"), exports);
77
86
  __exportStar(require("./operation-node/column-update-node.js"), exports);
78
87
  __exportStar(require("./operation-node/common-table-expression-node.js"), exports);
88
+ __exportStar(require("./operation-node/common-table-expression-name-node.js"), exports);
79
89
  __exportStar(require("./operation-node/constraint-node.js"), exports);
80
90
  __exportStar(require("./operation-node/create-index-node.js"), exports);
81
91
  __exportStar(require("./operation-node/create-schema-node.js"), exports);
@@ -135,6 +145,7 @@ __exportStar(require("./operation-node/unique-constraint-node.js"), exports);
135
145
  __exportStar(require("./operation-node/update-query-node.js"), exports);
136
146
  __exportStar(require("./operation-node/value-list-node.js"), exports);
137
147
  __exportStar(require("./operation-node/value-node.js"), exports);
148
+ __exportStar(require("./operation-node/values-node.js"), exports);
138
149
  __exportStar(require("./operation-node/where-node.js"), exports);
139
150
  __exportStar(require("./operation-node/with-node.js"), exports);
140
151
  __exportStar(require("./introspection/database-introspector.js"), exports);
@@ -17,7 +17,8 @@ import { LogConfig } from './util/log.js';
17
17
  * You should create one instance of `Kysely` per database using the {@link Kysely}
18
18
  * constructor. Each `Kysely` instance maintains it's own connection pool.
19
19
  *
20
- * @example
20
+ * ### Examples
21
+ *
21
22
  * This example assumes your database has tables `person` and `pet`:
22
23
  *
23
24
  * ```ts
@@ -31,7 +32,7 @@ import { LogConfig } from './util/log.js';
31
32
  * id: number
32
33
  * owner_id: number
33
34
  * name: string
34
- * species 'cat' | 'dog'
35
+ * species 'cat' | 'dog'
35
36
  * }
36
37
  *
37
38
  * interface Database {
@@ -78,10 +79,11 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
78
79
  * A value to be used in place of columns that are generated in the database
79
80
  * when inserting rows.
80
81
  *
81
- * @example
82
+ * ### Examples
83
+ *
82
84
  * In this example the `Person` table has non-null properties `id` and `created_at`
83
85
  * which are both automatically genereted by the database. Since their types are
84
- * `number` and `string` respectively instead of `number | null` and `string | null`
86
+ * `number` and `string` respectively instead of `number | null` and `string | null`
85
87
  * the `values` method requires you to give a value for them. the `generated`
86
88
  * placeholder can be used in these cases.
87
89
  *
@@ -136,12 +138,13 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
136
138
  * transaction. If the function throws, the transaction is rolled back. Otherwise
137
139
  * the transaction is committed.
138
140
  *
139
- * The callback function passed to the {@link TransactionBuilder.execute | execute}
141
+ * The callback function passed to the {@link TransactionBuilder.execute | execute}
140
142
  * method gets the transaction object as its only argument. The transaction is
141
143
  * of type {@link Transaction} which inherits {@link Kysely}. Any query
142
144
  * started through the transaction object is executed inside the transaction.
143
145
  *
144
- * @example
146
+ * ### Examples
147
+ *
145
148
  * ```ts
146
149
  * const catto = await db.transaction().execute(async (trx) => {
147
150
  * const jennifer = await trx.insertInto('person')
@@ -167,8 +170,7 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
167
170
  * })
168
171
  * ```
169
172
  *
170
- * @example
171
- * Setting the isolation level.
173
+ * Setting the isolation level:
172
174
  *
173
175
  * ```ts
174
176
  * await db
@@ -183,7 +185,8 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
183
185
  /**
184
186
  * Provides a kysely instance bound to a single database connection.
185
187
  *
186
- * @example
188
+ * ### Examples
189
+ *
187
190
  * ```ts
188
191
  * await db
189
192
  * .connection()
@@ -204,6 +207,38 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
204
207
  * Returns a copy of this Kysely instance without any plugins.
205
208
  */
206
209
  withoutPlugins(): Kysely<DB>;
210
+ /**
211
+ * Returns a copy of this Kysely instance with tables added to its
212
+ * database type.
213
+ *
214
+ * This method only modifies the types and doesn't affect any of the
215
+ * executed queries in any way.
216
+ *
217
+ * ### Examples
218
+ *
219
+ * The following example adds and uses a temporary table:
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * await db.schema
224
+ * .createTable('temp_table')
225
+ * .temporary()
226
+ * .addColumn('some_column', 'integer')
227
+ * .execute()
228
+ *
229
+ * const tempDb = db.withTables<{
230
+ * temp_table: {
231
+ * some_column: number
232
+ * }
233
+ * }>()
234
+ *
235
+ * await tempDb
236
+ * .insertInto('temp_table')
237
+ * .values({ some_column: 100 })
238
+ * .execute()
239
+ * ```
240
+ */
241
+ withTables<T extends Record<string, Record<string, any>>>(): Kysely<DB & T>;
207
242
  /**
208
243
  * Releases all resources and disconnects from the database.
209
244
  *
@@ -218,10 +253,134 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
218
253
  get isTransaction(): boolean;
219
254
  }
220
255
  export declare class Transaction<DB> extends Kysely<DB> {
256
+ #private;
257
+ constructor(props: KyselyProps);
258
+ /**
259
+ * Returns true if this `Kysely` instance is a transaction.
260
+ *
261
+ * You can also use `db instanceof Transaction`.
262
+ */
221
263
  get isTransaction(): true;
264
+ /**
265
+ * Returns the {@link MigrationModule} module for managing and running migrations.
266
+ */
222
267
  get migration(): MigrationModule;
268
+ /**
269
+ * Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
270
+ *
271
+ * The returned {@link TransactionBuilder} can be used to configure the transaction. The
272
+ * {@link TransactionBuilder.execute} method can then be called to run the transaction.
273
+ * {@link TransactionBuilder.execute} takes a function that is run inside the
274
+ * transaction. If the function throws, the transaction is rolled back. Otherwise
275
+ * the transaction is committed.
276
+ *
277
+ * The callback function passed to the {@link TransactionBuilder.execute | execute}
278
+ * method gets the transaction object as its only argument. The transaction is
279
+ * of type {@link Transaction} which inherits {@link Kysely}. Any query
280
+ * started through the transaction object is executed inside the transaction.
281
+ *
282
+ * ### Examples
283
+ *
284
+ * ```ts
285
+ * const catto = await db.transaction().execute(async (trx) => {
286
+ * const jennifer = await trx.insertInto('person')
287
+ * .values({
288
+ * id: db.generated,
289
+ * first_name: 'Jennifer',
290
+ * last_name: 'Aniston',
291
+ * })
292
+ * .returning('id')
293
+ * .executeTakeFirstOrThrow()
294
+ *
295
+ * await someFunction(trx, jennifer)
296
+ *
297
+ * return await trx.insertInto('pet')
298
+ * .values({
299
+ * id: db.generated,
300
+ * user_id: jennifer.id,
301
+ * name: 'Catto',
302
+ * species: 'cat'
303
+ * })
304
+ * .returning('*')
305
+ * .executeTakeFirst()
306
+ * })
307
+ * ```
308
+ *
309
+ * Setting the isolation level:
310
+ *
311
+ * ```ts
312
+ * await db
313
+ * .transaction()
314
+ * .setIsolationLevel('serializable')
315
+ * .execute(async (trx) => {
316
+ * await doStuff(trx)
317
+ * })
318
+ * ```
319
+ */
223
320
  transaction(): TransactionBuilder<DB>;
321
+ /**
322
+ * Provides a kysely instance bound to a single database connection.
323
+ *
324
+ * ### Examples
325
+ *
326
+ * ```ts
327
+ * await db
328
+ * .connection()
329
+ * .execute(async (db) => {
330
+ * // `db` is an instance of `Kysely` that's bound to a single
331
+ * // database connection. All queries executed through `db` use
332
+ * // the same connection.
333
+ * await doStuff(db)
334
+ * })
335
+ * ```
336
+ */
337
+ connection(): ConnectionBuilder<DB>;
338
+ /**
339
+ * Releases all resources and disconnects from the database.
340
+ *
341
+ * You need to call this when you are done using the `Kysely` instance.
342
+ */
224
343
  destroy(): Promise<void>;
344
+ /**
345
+ * Returns a copy of this Kysely instance with the given plugin installed.
346
+ */
347
+ withPlugin(plugin: KyselyPlugin): Transaction<DB>;
348
+ /**
349
+ * Returns a copy of this Kysely instance without any plugins.
350
+ */
351
+ withoutPlugins(): Transaction<DB>;
352
+ /**
353
+ * Returns a copy of this Kysely instance with tables added to its
354
+ * database type.
355
+ *
356
+ * This method only modifies the types and doesn't affect any of the
357
+ * executed queries in any way.
358
+ *
359
+ * ### Examples
360
+ *
361
+ * The following example adds and uses a temporary table:
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * await db.schema
366
+ * .createTable('temp_table')
367
+ * .temporary()
368
+ * .addColumn('some_column', 'integer')
369
+ * .execute()
370
+ *
371
+ * const tempDb = db.withTables<{
372
+ * temp_table: {
373
+ * some_column: number
374
+ * }
375
+ * }>()
376
+ *
377
+ * await tempDb
378
+ * .insertInto('temp_table')
379
+ * .values({ some_column: 100 })
380
+ * .execute()
381
+ * ```
382
+ */
383
+ withTables<T extends Record<string, Record<string, any>>>(): Transaction<DB & T>;
225
384
  }
226
385
  export interface KyselyProps {
227
386
  readonly config: KyselyConfig;
@@ -240,7 +399,8 @@ export interface KyselyConfig {
240
399
  * Currently there's only two levels: `query` and `error`.
241
400
  * This will be expanded based on user feedback later.
242
401
  *
243
- * @example
402
+ * ### Examples
403
+ *
244
404
  * ```ts
245
405
  * const db = new Kysely<Database>({
246
406
  * dialect: new PostgresDialect(postgresConfig),
@@ -248,7 +408,6 @@ export interface KyselyConfig {
248
408
  * })
249
409
  * ```
250
410
  *
251
- * @example
252
411
  * ```ts
253
412
  * const db = new Kysely<Database>({
254
413
  * dialect: new PostgresDialect(postgresConfig),
@@ -22,7 +22,8 @@ const log_js_1 = require("./util/log.js");
22
22
  * You should create one instance of `Kysely` per database using the {@link Kysely}
23
23
  * constructor. Each `Kysely` instance maintains it's own connection pool.
24
24
  *
25
- * @example
25
+ * ### Examples
26
+ *
26
27
  * This example assumes your database has tables `person` and `pet`:
27
28
  *
28
29
  * ```ts
@@ -36,7 +37,7 @@ const log_js_1 = require("./util/log.js");
36
37
  * id: number
37
38
  * owner_id: number
38
39
  * name: string
39
- * species 'cat' | 'dog'
40
+ * species 'cat' | 'dog'
40
41
  * }
41
42
  *
42
43
  * interface Database {
@@ -114,10 +115,11 @@ class Kysely extends query_creator_js_1.QueryCreator {
114
115
  * A value to be used in place of columns that are generated in the database
115
116
  * when inserting rows.
116
117
  *
117
- * @example
118
+ * ### Examples
119
+ *
118
120
  * In this example the `Person` table has non-null properties `id` and `created_at`
119
121
  * which are both automatically genereted by the database. Since their types are
120
- * `number` and `string` respectively instead of `number | null` and `string | null`
122
+ * `number` and `string` respectively instead of `number | null` and `string | null`
121
123
  * the `values` method requires you to give a value for them. the `generated`
122
124
  * placeholder can be used in these cases.
123
125
  *
@@ -176,12 +178,13 @@ class Kysely extends query_creator_js_1.QueryCreator {
176
178
  * transaction. If the function throws, the transaction is rolled back. Otherwise
177
179
  * the transaction is committed.
178
180
  *
179
- * The callback function passed to the {@link TransactionBuilder.execute | execute}
181
+ * The callback function passed to the {@link TransactionBuilder.execute | execute}
180
182
  * method gets the transaction object as its only argument. The transaction is
181
183
  * of type {@link Transaction} which inherits {@link Kysely}. Any query
182
184
  * started through the transaction object is executed inside the transaction.
183
185
  *
184
- * @example
186
+ * ### Examples
187
+ *
185
188
  * ```ts
186
189
  * const catto = await db.transaction().execute(async (trx) => {
187
190
  * const jennifer = await trx.insertInto('person')
@@ -207,8 +210,7 @@ class Kysely extends query_creator_js_1.QueryCreator {
207
210
  * })
208
211
  * ```
209
212
  *
210
- * @example
211
- * Setting the isolation level.
213
+ * Setting the isolation level:
212
214
  *
213
215
  * ```ts
214
216
  * await db
@@ -225,7 +227,8 @@ class Kysely extends query_creator_js_1.QueryCreator {
225
227
  /**
226
228
  * Provides a kysely instance bound to a single database connection.
227
229
  *
228
- * @example
230
+ * ### Examples
231
+ *
229
232
  * ```ts
230
233
  * await db
231
234
  * .connection()
@@ -258,6 +261,40 @@ class Kysely extends query_creator_js_1.QueryCreator {
258
261
  executor: this.#props.executor.withoutPlugins(),
259
262
  });
260
263
  }
264
+ /**
265
+ * Returns a copy of this Kysely instance with tables added to its
266
+ * database type.
267
+ *
268
+ * This method only modifies the types and doesn't affect any of the
269
+ * executed queries in any way.
270
+ *
271
+ * ### Examples
272
+ *
273
+ * The following example adds and uses a temporary table:
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * await db.schema
278
+ * .createTable('temp_table')
279
+ * .temporary()
280
+ * .addColumn('some_column', 'integer')
281
+ * .execute()
282
+ *
283
+ * const tempDb = db.withTables<{
284
+ * temp_table: {
285
+ * some_column: number
286
+ * }
287
+ * }>()
288
+ *
289
+ * await tempDb
290
+ * .insertInto('temp_table')
291
+ * .values({ some_column: 100 })
292
+ * .execute()
293
+ * ```
294
+ */
295
+ withTables() {
296
+ return new Kysely({ ...this.#props });
297
+ }
261
298
  /**
262
299
  * Releases all resources and disconnects from the database.
263
300
  *
@@ -277,6 +314,11 @@ class Kysely extends query_creator_js_1.QueryCreator {
277
314
  }
278
315
  exports.Kysely = Kysely;
279
316
  class Transaction extends Kysely {
317
+ #props;
318
+ constructor(props) {
319
+ super(props);
320
+ this.#props = props;
321
+ }
280
322
  // The return type is `true` instead of `boolean` to make Kysely<DB>
281
323
  // unassignable to Transaction<DB> while allowing assignment the
282
324
  // other way around.
@@ -289,9 +331,27 @@ class Transaction extends Kysely {
289
331
  transaction() {
290
332
  throw new Error('calling the transaction method for a Transaction is not supported');
291
333
  }
334
+ connection() {
335
+ throw new Error('calling the connection method for a Transaction is not supported');
336
+ }
292
337
  async destroy() {
293
338
  throw new Error('calling the destroy method for a Transaction is not supported');
294
339
  }
340
+ withPlugin(plugin) {
341
+ return new Transaction({
342
+ ...this.#props,
343
+ executor: this.#props.executor.withPlugin(plugin),
344
+ });
345
+ }
346
+ withoutPlugins() {
347
+ return new Transaction({
348
+ ...this.#props,
349
+ executor: this.#props.executor.withoutPlugins(),
350
+ });
351
+ }
352
+ withTables() {
353
+ return new Transaction({ ...this.#props });
354
+ }
295
355
  }
296
356
  exports.Transaction = Transaction;
297
357
  function isKyselyProps(obj) {