kysely 0.23.4 → 0.24.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 (314) hide show
  1. package/README.md +49 -25
  2. package/dist/cjs/dialect/database-introspector.d.ts +4 -2
  3. package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -2
  4. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +1 -1
  5. package/dist/cjs/dialect/mysql/mysql-driver.js +1 -1
  6. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-introspector.js +19 -13
  8. package/dist/cjs/dialect/postgres/postgres-adapter.js +1 -1
  9. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  10. package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -1
  11. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -0
  12. package/dist/cjs/dialect/sqlite/sqlite-dialect.js +1 -0
  13. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  14. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +6 -5
  15. package/dist/cjs/driver/runtime-driver.js +4 -2
  16. package/dist/cjs/expression/expression-builder.d.ts +386 -0
  17. package/dist/cjs/expression/expression-builder.js +92 -0
  18. package/dist/cjs/expression/expression-wrapper.d.ts +92 -0
  19. package/dist/cjs/expression/expression-wrapper.js +54 -0
  20. package/dist/cjs/expression/expression.d.ts +1 -1
  21. package/dist/cjs/helpers/postgres.d.ts +133 -0
  22. package/dist/cjs/helpers/postgres.js +141 -0
  23. package/dist/cjs/index.d.ts +4 -3
  24. package/dist/cjs/index.js +4 -2
  25. package/dist/cjs/kysely.d.ts +10 -0
  26. package/dist/cjs/kysely.js +12 -1
  27. package/dist/cjs/migration/file-migration-provider.d.ts +5 -2
  28. package/dist/cjs/migration/migrator.d.ts +5 -2
  29. package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
  30. package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
  31. package/dist/cjs/operation-node/create-index-node.d.ts +2 -0
  32. package/dist/cjs/operation-node/delete-query-node.d.ts +1 -2
  33. package/dist/cjs/operation-node/delete-query-node.js +2 -8
  34. package/dist/cjs/operation-node/function-node.d.ts +13 -0
  35. package/dist/cjs/operation-node/function-node.js +19 -0
  36. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  37. package/dist/cjs/operation-node/operation-node-transformer.js +11 -2
  38. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  39. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  40. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  41. package/dist/cjs/operation-node/operator-node.d.ts +13 -2
  42. package/dist/cjs/operation-node/operator-node.js +38 -3
  43. package/dist/cjs/operation-node/query-node.d.ts +25 -8
  44. package/dist/cjs/operation-node/query-node.js +9 -2
  45. package/dist/cjs/operation-node/select-query-node.d.ts +0 -1
  46. package/dist/cjs/operation-node/select-query-node.js +0 -6
  47. package/dist/cjs/operation-node/update-query-node.d.ts +0 -1
  48. package/dist/cjs/operation-node/update-query-node.js +0 -6
  49. package/dist/cjs/parser/binary-operation-parser.d.ts +9 -10
  50. package/dist/cjs/parser/binary-operation-parser.js +89 -39
  51. package/dist/cjs/parser/coalesce-parser.d.ts +0 -2
  52. package/dist/cjs/parser/coalesce-parser.js +0 -9
  53. package/dist/cjs/parser/expression-parser.d.ts +7 -3
  54. package/dist/cjs/parser/expression-parser.js +4 -4
  55. package/dist/cjs/parser/group-by-parser.d.ts +3 -2
  56. package/dist/cjs/parser/group-by-parser.js +3 -0
  57. package/dist/cjs/parser/insert-values-parser.d.ts +4 -1
  58. package/dist/cjs/parser/insert-values-parser.js +19 -13
  59. package/dist/cjs/parser/join-parser.js +1 -1
  60. package/dist/cjs/parser/parse-utils.d.ts +0 -2
  61. package/dist/cjs/parser/parse-utils.js +1 -8
  62. package/dist/cjs/parser/returning-parser.d.ts +2 -1
  63. package/dist/cjs/parser/select-parser.d.ts +5 -13
  64. package/dist/cjs/parser/select-parser.js +8 -4
  65. package/dist/cjs/parser/table-parser.d.ts +6 -3
  66. package/dist/cjs/parser/unary-operation-parser.d.ts +5 -2
  67. package/dist/cjs/parser/unary-operation-parser.js +9 -8
  68. package/dist/cjs/parser/update-set-parser.d.ts +4 -1
  69. package/dist/cjs/parser/update-set-parser.js +9 -4
  70. package/dist/cjs/parser/value-parser.d.ts +5 -0
  71. package/dist/cjs/parser/value-parser.js +1 -3
  72. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  73. package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
  74. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +1 -1
  75. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +1 -1
  76. package/dist/cjs/query-builder/aggregate-function-builder.d.ts +40 -113
  77. package/dist/cjs/query-builder/aggregate-function-builder.js +23 -63
  78. package/dist/cjs/query-builder/delete-query-builder.d.ts +224 -205
  79. package/dist/cjs/query-builder/delete-query-builder.js +21 -27
  80. package/dist/cjs/query-builder/delete-result.js +3 -0
  81. package/dist/cjs/query-builder/deprecated-having-expression-builder.d.ts +62 -0
  82. package/dist/cjs/query-builder/deprecated-having-expression-builder.js +2 -0
  83. package/dist/cjs/query-builder/deprecated-on-expression-builder.d.ts +62 -0
  84. package/dist/cjs/query-builder/deprecated-on-expression-builder.js +2 -0
  85. package/dist/cjs/query-builder/deprecated-where-expression-builder.d.ts +62 -0
  86. package/dist/cjs/query-builder/deprecated-where-expression-builder.js +2 -0
  87. package/dist/cjs/query-builder/function-module.d.ts +304 -42
  88. package/dist/cjs/query-builder/function-module.js +44 -208
  89. package/dist/cjs/query-builder/having-interface.d.ts +19 -16
  90. package/dist/cjs/query-builder/insert-query-builder.d.ts +78 -30
  91. package/dist/cjs/query-builder/insert-query-builder.js +21 -30
  92. package/dist/cjs/query-builder/insert-result.js +3 -0
  93. package/dist/cjs/query-builder/join-builder.d.ts +23 -26
  94. package/dist/cjs/query-builder/join-builder.js +17 -22
  95. package/dist/cjs/query-builder/no-result-error.d.ts +1 -0
  96. package/dist/cjs/query-builder/no-result-error.js +5 -1
  97. package/dist/cjs/query-builder/on-conflict-builder.d.ts +158 -276
  98. package/dist/cjs/query-builder/on-conflict-builder.js +52 -36
  99. package/dist/cjs/query-builder/over-builder.d.ts +5 -0
  100. package/dist/cjs/query-builder/over-builder.js +7 -0
  101. package/dist/cjs/query-builder/returning-interface.d.ts +2 -2
  102. package/dist/cjs/query-builder/select-query-builder.d.ts +155 -243
  103. package/dist/cjs/query-builder/select-query-builder.js +333 -78
  104. package/dist/cjs/query-builder/update-query-builder.d.ts +149 -217
  105. package/dist/cjs/query-builder/update-query-builder.js +21 -115
  106. package/dist/cjs/query-builder/update-result.js +3 -0
  107. package/dist/cjs/query-builder/where-interface.d.ts +71 -184
  108. package/dist/cjs/query-compiler/default-query-compiler.d.ts +3 -0
  109. package/dist/cjs/query-compiler/default-query-compiler.js +18 -2
  110. package/dist/cjs/query-creator.d.ts +38 -2
  111. package/dist/cjs/query-creator.js +3 -45
  112. package/dist/cjs/query-executor/query-executor.d.ts +3 -3
  113. package/dist/cjs/raw-builder/raw-builder.d.ts +5 -3
  114. package/dist/cjs/raw-builder/raw-builder.js +13 -7
  115. package/dist/cjs/raw-builder/sql.d.ts +17 -9
  116. package/dist/cjs/raw-builder/sql.js +8 -2
  117. package/dist/cjs/schema/alter-column-builder.d.ts +5 -0
  118. package/dist/cjs/schema/alter-column-builder.js +7 -0
  119. package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.d.ts +5 -0
  120. package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +7 -0
  121. package/dist/cjs/schema/alter-table-drop-constraint-builder.d.ts +5 -0
  122. package/dist/cjs/schema/alter-table-drop-constraint-builder.js +7 -0
  123. package/dist/cjs/schema/column-definition-builder.d.ts +6 -1
  124. package/dist/cjs/schema/column-definition-builder.js +8 -1
  125. package/dist/cjs/schema/create-index-builder.d.ts +51 -9
  126. package/dist/cjs/schema/create-index-builder.js +17 -0
  127. package/dist/cjs/schema/create-schema-builder.d.ts +5 -0
  128. package/dist/cjs/schema/create-schema-builder.js +7 -0
  129. package/dist/cjs/schema/create-table-builder.d.ts +3 -1
  130. package/dist/cjs/schema/create-table-builder.js +3 -1
  131. package/dist/cjs/schema/create-type-builder.d.ts +5 -0
  132. package/dist/cjs/schema/create-type-builder.js +7 -0
  133. package/dist/cjs/schema/create-view-builder.d.ts +5 -0
  134. package/dist/cjs/schema/create-view-builder.js +7 -0
  135. package/dist/cjs/schema/drop-index-builder.d.ts +5 -0
  136. package/dist/cjs/schema/drop-index-builder.js +7 -0
  137. package/dist/cjs/schema/drop-schema-builder.d.ts +5 -0
  138. package/dist/cjs/schema/drop-schema-builder.js +7 -0
  139. package/dist/cjs/schema/drop-table-builder.d.ts +5 -0
  140. package/dist/cjs/schema/drop-table-builder.js +7 -0
  141. package/dist/cjs/schema/drop-type-builder.d.ts +5 -0
  142. package/dist/cjs/schema/drop-type-builder.js +7 -0
  143. package/dist/cjs/schema/drop-view-builder.d.ts +5 -0
  144. package/dist/cjs/schema/drop-view-builder.js +7 -0
  145. package/dist/cjs/schema/foreign-key-constraint-builder.d.ts +5 -0
  146. package/dist/cjs/schema/foreign-key-constraint-builder.js +7 -0
  147. package/dist/cjs/util/compilable.d.ts +1 -0
  148. package/dist/cjs/util/compilable.js +6 -0
  149. package/dist/cjs/util/explainable.d.ts +35 -0
  150. package/dist/cjs/util/log.d.ts +2 -0
  151. package/dist/cjs/util/object-utils.js +1 -1
  152. package/dist/cjs/util/streamable.d.ts +29 -0
  153. package/dist/cjs/util/streamable.js +2 -0
  154. package/dist/cjs/util/type-utils.d.ts +6 -4
  155. package/dist/esm/dialect/database-introspector.d.ts +4 -2
  156. package/dist/esm/dialect/mysql/mysql-adapter.js +2 -2
  157. package/dist/esm/dialect/mysql/mysql-driver.d.ts +1 -1
  158. package/dist/esm/dialect/mysql/mysql-driver.js +1 -1
  159. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  160. package/dist/esm/dialect/mysql/mysql-introspector.js +19 -13
  161. package/dist/esm/dialect/postgres/postgres-adapter.js +1 -1
  162. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  163. package/dist/esm/dialect/postgres/postgres-introspector.js +3 -1
  164. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -0
  165. package/dist/esm/dialect/sqlite/sqlite-dialect.js +1 -0
  166. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  167. package/dist/esm/dialect/sqlite/sqlite-introspector.js +6 -5
  168. package/dist/esm/driver/runtime-driver.js +4 -2
  169. package/dist/esm/expression/expression-builder.d.ts +386 -0
  170. package/dist/esm/expression/expression-builder.js +88 -0
  171. package/dist/esm/expression/expression-wrapper.d.ts +92 -0
  172. package/dist/esm/expression/expression-wrapper.js +50 -0
  173. package/dist/esm/expression/expression.d.ts +1 -1
  174. package/dist/esm/helpers/postgres.d.ts +133 -0
  175. package/dist/esm/helpers/postgres.js +136 -0
  176. package/dist/esm/index.d.ts +4 -3
  177. package/dist/esm/index.js +2 -1
  178. package/dist/esm/kysely.d.ts +10 -0
  179. package/dist/esm/kysely.js +13 -2
  180. package/dist/esm/migration/file-migration-provider.d.ts +5 -2
  181. package/dist/esm/migration/migrator.d.ts +5 -2
  182. package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
  183. package/dist/esm/operation-node/aggregate-function-node.js +2 -2
  184. package/dist/esm/operation-node/create-index-node.d.ts +2 -0
  185. package/dist/esm/operation-node/delete-query-node.d.ts +1 -2
  186. package/dist/esm/operation-node/delete-query-node.js +2 -8
  187. package/dist/esm/operation-node/function-node.d.ts +13 -0
  188. package/dist/esm/operation-node/function-node.js +17 -0
  189. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  190. package/dist/esm/operation-node/operation-node-transformer.js +11 -2
  191. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  192. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  193. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  194. package/dist/esm/operation-node/operator-node.d.ts +13 -2
  195. package/dist/esm/operation-node/operator-node.js +34 -3
  196. package/dist/esm/operation-node/query-node.d.ts +25 -8
  197. package/dist/esm/operation-node/query-node.js +9 -2
  198. package/dist/esm/operation-node/select-query-node.d.ts +0 -1
  199. package/dist/esm/operation-node/select-query-node.js +0 -6
  200. package/dist/esm/operation-node/update-query-node.d.ts +0 -1
  201. package/dist/esm/operation-node/update-query-node.js +0 -6
  202. package/dist/esm/parser/binary-operation-parser.d.ts +9 -10
  203. package/dist/esm/parser/binary-operation-parser.js +85 -37
  204. package/dist/esm/parser/coalesce-parser.d.ts +0 -2
  205. package/dist/esm/parser/coalesce-parser.js +1 -7
  206. package/dist/esm/parser/expression-parser.d.ts +7 -3
  207. package/dist/esm/parser/expression-parser.js +5 -5
  208. package/dist/esm/parser/group-by-parser.d.ts +3 -2
  209. package/dist/esm/parser/group-by-parser.js +3 -0
  210. package/dist/esm/parser/insert-values-parser.d.ts +4 -1
  211. package/dist/esm/parser/insert-values-parser.js +18 -12
  212. package/dist/esm/parser/join-parser.js +2 -2
  213. package/dist/esm/parser/parse-utils.d.ts +0 -2
  214. package/dist/esm/parser/parse-utils.js +0 -6
  215. package/dist/esm/parser/returning-parser.d.ts +2 -1
  216. package/dist/esm/parser/select-parser.d.ts +5 -13
  217. package/dist/esm/parser/select-parser.js +7 -3
  218. package/dist/esm/parser/table-parser.d.ts +6 -3
  219. package/dist/esm/parser/unary-operation-parser.d.ts +5 -2
  220. package/dist/esm/parser/unary-operation-parser.js +8 -8
  221. package/dist/esm/parser/update-set-parser.d.ts +4 -1
  222. package/dist/esm/parser/update-set-parser.js +7 -2
  223. package/dist/esm/parser/value-parser.d.ts +5 -0
  224. package/dist/esm/parser/value-parser.js +1 -3
  225. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  226. package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
  227. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +1 -1
  228. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +1 -1
  229. package/dist/esm/query-builder/aggregate-function-builder.d.ts +40 -113
  230. package/dist/esm/query-builder/aggregate-function-builder.js +24 -64
  231. package/dist/esm/query-builder/delete-query-builder.d.ts +224 -205
  232. package/dist/esm/query-builder/delete-query-builder.js +24 -30
  233. package/dist/esm/query-builder/delete-result.js +3 -0
  234. package/dist/esm/query-builder/deprecated-having-expression-builder.d.ts +62 -0
  235. package/dist/esm/query-builder/deprecated-having-expression-builder.js +2 -0
  236. package/dist/esm/query-builder/deprecated-on-expression-builder.d.ts +62 -0
  237. package/dist/esm/query-builder/deprecated-on-expression-builder.js +2 -0
  238. package/dist/esm/query-builder/deprecated-where-expression-builder.d.ts +62 -0
  239. package/dist/esm/query-builder/deprecated-where-expression-builder.js +2 -0
  240. package/dist/esm/query-builder/function-module.d.ts +304 -42
  241. package/dist/esm/query-builder/function-module.js +43 -207
  242. package/dist/esm/query-builder/having-interface.d.ts +19 -16
  243. package/dist/esm/query-builder/insert-query-builder.d.ts +78 -30
  244. package/dist/esm/query-builder/insert-query-builder.js +25 -34
  245. package/dist/esm/query-builder/insert-result.js +3 -0
  246. package/dist/esm/query-builder/join-builder.d.ts +23 -26
  247. package/dist/esm/query-builder/join-builder.js +18 -23
  248. package/dist/esm/query-builder/no-result-error.d.ts +1 -0
  249. package/dist/esm/query-builder/no-result-error.js +3 -0
  250. package/dist/esm/query-builder/on-conflict-builder.d.ts +158 -276
  251. package/dist/esm/query-builder/on-conflict-builder.js +54 -38
  252. package/dist/esm/query-builder/over-builder.d.ts +5 -0
  253. package/dist/esm/query-builder/over-builder.js +7 -0
  254. package/dist/esm/query-builder/returning-interface.d.ts +2 -2
  255. package/dist/esm/query-builder/select-query-builder.d.ts +155 -243
  256. package/dist/esm/query-builder/select-query-builder.js +337 -82
  257. package/dist/esm/query-builder/update-query-builder.d.ts +149 -217
  258. package/dist/esm/query-builder/update-query-builder.js +25 -119
  259. package/dist/esm/query-builder/update-result.js +3 -0
  260. package/dist/esm/query-builder/where-interface.d.ts +71 -184
  261. package/dist/esm/query-compiler/default-query-compiler.d.ts +3 -0
  262. package/dist/esm/query-compiler/default-query-compiler.js +18 -2
  263. package/dist/esm/query-creator.d.ts +38 -2
  264. package/dist/esm/query-creator.js +3 -45
  265. package/dist/esm/query-executor/query-executor.d.ts +3 -3
  266. package/dist/esm/raw-builder/raw-builder.d.ts +5 -3
  267. package/dist/esm/raw-builder/raw-builder.js +13 -7
  268. package/dist/esm/raw-builder/sql.d.ts +17 -9
  269. package/dist/esm/raw-builder/sql.js +8 -2
  270. package/dist/esm/schema/alter-column-builder.d.ts +5 -0
  271. package/dist/esm/schema/alter-column-builder.js +7 -0
  272. package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts +5 -0
  273. package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +7 -0
  274. package/dist/esm/schema/alter-table-drop-constraint-builder.d.ts +5 -0
  275. package/dist/esm/schema/alter-table-drop-constraint-builder.js +7 -0
  276. package/dist/esm/schema/column-definition-builder.d.ts +6 -1
  277. package/dist/esm/schema/column-definition-builder.js +8 -1
  278. package/dist/esm/schema/create-index-builder.d.ts +51 -9
  279. package/dist/esm/schema/create-index-builder.js +17 -0
  280. package/dist/esm/schema/create-schema-builder.d.ts +5 -0
  281. package/dist/esm/schema/create-schema-builder.js +7 -0
  282. package/dist/esm/schema/create-table-builder.d.ts +3 -1
  283. package/dist/esm/schema/create-table-builder.js +3 -1
  284. package/dist/esm/schema/create-type-builder.d.ts +5 -0
  285. package/dist/esm/schema/create-type-builder.js +7 -0
  286. package/dist/esm/schema/create-view-builder.d.ts +5 -0
  287. package/dist/esm/schema/create-view-builder.js +7 -0
  288. package/dist/esm/schema/drop-index-builder.d.ts +5 -0
  289. package/dist/esm/schema/drop-index-builder.js +7 -0
  290. package/dist/esm/schema/drop-schema-builder.d.ts +5 -0
  291. package/dist/esm/schema/drop-schema-builder.js +7 -0
  292. package/dist/esm/schema/drop-table-builder.d.ts +5 -0
  293. package/dist/esm/schema/drop-table-builder.js +7 -0
  294. package/dist/esm/schema/drop-type-builder.d.ts +5 -0
  295. package/dist/esm/schema/drop-type-builder.js +7 -0
  296. package/dist/esm/schema/drop-view-builder.d.ts +5 -0
  297. package/dist/esm/schema/drop-view-builder.js +7 -0
  298. package/dist/esm/schema/foreign-key-constraint-builder.d.ts +5 -0
  299. package/dist/esm/schema/foreign-key-constraint-builder.js +7 -0
  300. package/dist/esm/util/compilable.d.ts +1 -0
  301. package/dist/esm/util/compilable.js +4 -1
  302. package/dist/esm/util/explainable.d.ts +35 -0
  303. package/dist/esm/util/log.d.ts +2 -0
  304. package/dist/esm/util/object-utils.js +1 -1
  305. package/dist/esm/util/streamable.d.ts +29 -0
  306. package/dist/esm/util/streamable.js +2 -0
  307. package/dist/esm/util/type-utils.d.ts +6 -4
  308. package/helpers/postgres.d.ts +1 -0
  309. package/helpers/postgres.js +1 -0
  310. package/package.json +20 -9
  311. package/dist/cjs/query-builder/expression-builder.d.ts +0 -126
  312. package/dist/cjs/query-builder/expression-builder.js +0 -107
  313. package/dist/esm/query-builder/expression-builder.d.ts +0 -126
  314. package/dist/esm/query-builder/expression-builder.js +0 -104
@@ -1,7 +1,7 @@
1
1
  import { DynamicReferenceBuilder } from '../dynamic/dynamic-reference-builder.js';
2
+ import { ExpressionWrapper } from '../expression/expression-wrapper.js';
2
3
  import { CoalesceReferenceExpressionList } from '../parser/coalesce-parser.js';
3
4
  import { ExtractTypeFromReferenceExpression, SimpleReferenceExpression, ReferenceExpression, StringReference } from '../parser/reference-parser.js';
4
- import { RawBuilder } from '../raw-builder/raw-builder.js';
5
5
  import { Equals, IsNever } from '../util/type-utils.js';
6
6
  import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
7
7
  /**
@@ -36,13 +36,70 @@ import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
36
36
  * having count("pet"."id") > $1
37
37
  * ```
38
38
  */
39
- export declare class FunctionModule<DB, TB extends keyof DB> {
40
- constructor();
39
+ export interface FunctionModule<DB, TB extends keyof DB> {
40
+ /**
41
+ * Creates a function call.
42
+ *
43
+ * ### Examples
44
+ *
45
+ * ```ts
46
+ * db.selectFrom('person')
47
+ * .selectAll('person')
48
+ * .where(db.fn('upper', ['first_name']), '=', 'JENNIFER')
49
+ * ```
50
+ *
51
+ * The generated SQL (PostgreSQL):
52
+ *
53
+ * ```sql
54
+ * select "person".*
55
+ * from "person"
56
+ * where upper("first_name") = $1
57
+ * ```
58
+ *
59
+ * If you prefer readability over type-safety, you can always use raw `sql`:
60
+ *
61
+ * ```ts
62
+ * db.selectFrom('person')
63
+ * .selectAll('person')
64
+ * .where(sql`upper(first_name)`, '=', 'JENNIFER')
65
+ * ```
66
+ */
67
+ <T>(name: string, args: ReadonlyArray<ReferenceExpression<DB, TB>>): ExpressionWrapper<T>;
41
68
  /**
42
69
  * Calls the `avg` function for the column given as the argument.
43
70
  *
44
- * If this is used in a `select` statement the type of the selected expression
45
- * will be `number | string` by default. This is because Kysely can't know the
71
+ * This sql function calculates the average value for a given column.
72
+ *
73
+ * For additional functionality such as distinct, filtering and window functions,
74
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
75
+ * returned when calling this function.
76
+ *
77
+ * ### Examples
78
+ *
79
+ * ```ts
80
+ * const { avg } = db.fn
81
+ *
82
+ * db.selectFrom('toy')
83
+ * .select(avg('price').as('avg_price'))
84
+ * .execute()
85
+ * ```
86
+ *
87
+ * The generated SQL (PostgreSQL):
88
+ *
89
+ * ```sql
90
+ * select avg("price") as "avg_price" from "toy"
91
+ * ```
92
+ *
93
+ * You can limit column range to only columns participating in current query:
94
+ *
95
+ * ```ts
96
+ * db.selectFrom('toy')
97
+ * .select((eb) => eb.fn.avg('price').as('avg_price'))
98
+ * .execute()
99
+ * ```
100
+ *
101
+ * If this function is used in a `select` statement, the type of the selected
102
+ * expression will be `number | string` by default. This is because Kysely can't know the
46
103
  * type the db driver outputs. Sometimes the output can be larger than the largest
47
104
  * javascript number and a string is returned instead. Most drivers allow you
48
105
  * to configure the output type of large numbers and Kysely can't know if you've
@@ -61,7 +118,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
61
118
  *
62
119
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
63
120
  * was used. It is highly recommended to include null in the output type union
64
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
121
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
65
122
  * function.
66
123
  *
67
124
  * ```ts
@@ -76,42 +133,153 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
76
133
  /**
77
134
  * Calls the `coalesce` function for given arguments.
78
135
  *
79
- * This function returns the first non-null value from left to right, commonly
136
+ * This sql function returns the first non-null value from left to right, commonly
80
137
  * used to provide a default scalar for nullable columns or functions.
81
138
  *
139
+ * If this function is used in a `select` statement, the type of the selected
140
+ * expression is inferred in the same manner that the sql function computes.
141
+ * A union of arguments' types - if a non-nullable argument exists, it stops
142
+ * there (ignoring any further arguments' types) and exludes null from the final
143
+ * union type.
144
+ *
145
+ * `(string | null, number | null)` is inferred as `string | number | null`.
146
+ *
147
+ * `(string | null, number, Date | null)` is inferred as `string | number`.
148
+ *
149
+ * `(number, string | null)` is inferred as `number`.
150
+ *
151
+ * ### Examples
152
+ *
82
153
  * ```ts
83
- * const { coalesce, max } = db.fn
154
+ * const { coalesce } = db.fn
155
+ *
156
+ * db.selectFrom('participant')
157
+ * .select(coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname'))
158
+ * .where('room_id', '=', roomId)
159
+ * .execute()
160
+ * ```
161
+ *
162
+ * The generated SQL (PostgreSQL):
163
+ *
164
+ * ```sql
165
+ * select coalesce("nickname", '<anonymous>') as "nickname"
166
+ * from "participant" where "room_id" = $1
167
+ * ```
168
+ *
169
+ * You can limit column range to only columns participating in current query:
170
+ *
171
+ * ```ts
172
+ * db.selectFrom('participant')
173
+ * .select((eb) =>
174
+ * eb.fn.coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname')
175
+ * )
176
+ * .where('room_id', '=', roomId)
177
+ * .execute()
178
+ * ```
179
+ *
180
+ * You can combine this function with other helpers in this module:
181
+ *
182
+ * ```ts
183
+ * const { avg, coalesce } = db.fn
84
184
  *
85
185
  * db.selectFrom('person')
86
- * .select(coalesce(max('age'), sql<number>`0`).as('max_age'))
186
+ * .select(coalesce(avg<number | null>('age'), sql<number>`0`).as('avg_age'))
87
187
  * .where('first_name', '=', 'Jennifer')
88
188
  * .execute()
89
189
  * ```
90
190
  *
91
- * The generated SQL (postgres):
191
+ * The generated SQL (PostgreSQL):
92
192
  *
93
193
  * ```sql
94
- * select coalesce(max("age"), 0) as "max_age" from "person" where "first_name" = $1
194
+ * select coalesce(avg("age"), 0) as "avg_age" from "person" where "first_name" = $1
95
195
  * ```
196
+ */
197
+ coalesce<V extends ReferenceExpression<DB, TB>, OV extends ReferenceExpression<DB, TB>[]>(value: V, ...otherValues: OV): ExpressionWrapper<CoalesceReferenceExpressionList<DB, TB, [V, ...OV]>>;
198
+ /**
199
+ * Calls the `count` function for the column given as the argument.
96
200
  *
97
- * If this is used in a `select` statement the type of the selected expression
98
- * is inferred in the same manner that the function computes. A union of arguments'
99
- * types - if a non-nullable argument exists, it stops there (ignoring any further
100
- * arguments' types) and exludes null from the final union type.
201
+ * When called with a column as argument, this sql function counts the number of rows where there
202
+ * is a non-null value in that column.
101
203
  *
102
- * Examples:
204
+ * For counting all rows nulls included (`count(*)`), see {@link countAll}.
103
205
  *
104
- * `(string | null, number | null)` is inferred as `string | number | null`.
206
+ * For additional functionality such as distinct, filtering and window functions,
207
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
208
+ * returned when calling this function.
105
209
  *
106
- * `(string | null, number, Date | null)` is inferred as `string | number`.
210
+ * ### Examples
107
211
  *
108
- * `(number, string | null)` is inferred as `number`.
212
+ * ```ts
213
+ * const { count } = db.fn
214
+ *
215
+ * db.selectFrom('toy')
216
+ * .select(count('id').as('num_toys'))
217
+ * .execute()
218
+ * ```
219
+ *
220
+ * The generated SQL (PostgreSQL):
221
+ *
222
+ * ```sql
223
+ * select count("id") as "num_toys" from "toy"
224
+ * ```
225
+ *
226
+ * If this function is used in a `select` statement, the type of the selected
227
+ * expression will be `number | string | bigint` by default. This is because
228
+ * Kysely can't know the type the db driver outputs. Sometimes the output can
229
+ * be larger than the largest javascript number and a string is returned instead.
230
+ * Most drivers allow you to configure the output type of large numbers and Kysely
231
+ * can't know if you've done so.
232
+ *
233
+ * You can specify the output type of the expression by providing
234
+ * the type as the first type argument:
235
+ *
236
+ * ```ts
237
+ * const { count } = db.fn
238
+ *
239
+ * db.selectFrom('toy')
240
+ * .select(count<number>('id').as('num_toys'))
241
+ * .execute()
242
+ * ```
243
+ *
244
+ * You can limit column range to only columns participating in current query:
245
+ *
246
+ * ```ts
247
+ * db.selectFrom('toy')
248
+ * .select((eb) => eb.fn.count('id').as('num_toys'))
249
+ * .execute()
250
+ * ```
109
251
  */
110
- coalesce<V extends ReferenceExpression<DB, TB>, OV extends ReferenceExpression<DB, TB>[]>(value: V, ...otherValues: OV): RawBuilder<CoalesceReferenceExpressionList<DB, TB, [V, ...OV]>>;
252
+ count<O extends number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
111
253
  /**
112
- * Calls the `count` function for the column given as the argument.
254
+ * Calls the `count` function with `*` or `table.*` as argument.
255
+ *
256
+ * When called with `*` as argument, this sql function counts the number of rows,
257
+ * nulls included.
258
+ *
259
+ * For counting rows with non-null values in a given column (`count(column)`),
260
+ * see {@link count}.
261
+ *
262
+ * For additional functionality such as filtering and window functions, refer
263
+ * to {@link AggregateFunctionBuilder}. An instance of this builder is returned
264
+ * when calling this function.
265
+ *
266
+ * ### Examples
267
+ *
268
+ * ```ts
269
+ * const { countAll } = db.fn
270
+ *
271
+ * db.selectFrom('toy')
272
+ * .select(countAll().as('num_toys'))
273
+ * .execute()
274
+ * ```
275
+ *
276
+ * The generated SQL (PostgreSQL):
113
277
  *
114
- * If this is used in a `select` statement the type of the selected expression
278
+ * ```sql
279
+ * select count(*) as "num_toys" from "toy"
280
+ * ```
281
+ *
282
+ * If this is used in a `select` statement, the type of the selected expression
115
283
  * will be `number | string | bigint` by default. This is because Kysely
116
284
  * can't know the type the db driver outputs. Sometimes the output can be larger
117
285
  * than the largest javascript number and a string is returned instead. Most
@@ -122,27 +290,55 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
122
290
  * the type as the first type argument:
123
291
  *
124
292
  * ```ts
125
- * const { count } = db.fn
293
+ * const { countAll } = db.fn
126
294
  *
127
295
  * db.selectFrom('toy')
128
- * .select(count<number>('id').as('num_toys'))
296
+ * .select(countAll<number>().as('num_toys'))
129
297
  * .execute()
130
298
  * ```
131
299
  *
132
- * You can limit column range:
300
+ * Some databases, such as PostgreSQL, support scoping the function to a specific
301
+ * table:
133
302
  *
134
303
  * ```ts
304
+ * const { countAll } = db.fn
305
+ *
135
306
  * db.selectFrom('toy')
136
- * .select(qb => qb.fn.count<number>('id').as('num_toys'))
307
+ * .innerJoin('pet', 'pet.id', 'toy.pet_id')
308
+ * .select(countAll('toy').as('num_toys'))
309
+ * .execute()
310
+ * ```
311
+ *
312
+ * The generated SQL (PostgreSQL):
313
+ *
314
+ * ```sql
315
+ * select count("toy".*) as "num_toys"
316
+ * from "toy" inner join "pet" on "pet"."id" = "toy"."pet_id"
317
+ * ```
318
+ *
319
+ * You can limit table range to only tables participating in current query:
320
+ *
321
+ * ```ts
322
+ * db.selectFrom('toy')
323
+ * .innerJoin('pet', 'pet.id', 'toy.pet_id')
324
+ * .select((eb) => eb.fn.countAll('toy').as('num_toys'))
137
325
  * .execute()
138
326
  * ```
139
327
  */
140
- count<O extends number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
328
+ countAll<O extends number | string | bigint, T extends TB = TB>(table: T): AggregateFunctionBuilder<DB, TB, O>;
329
+ countAll<O extends number | string | bigint>(): AggregateFunctionBuilder<DB, TB, O>;
141
330
  /**
142
331
  * Calls the `max` function for the column given as the argument.
143
332
  *
144
- * If this is used in a `select` statement the type of the selected expression
145
- * will be the referenced column's type.
333
+ * This sql function calculates the maximum value for a given column.
334
+ *
335
+ * For additional functionality such as distinct, filtering and window functions,
336
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
337
+ * returned when calling this function.
338
+ *
339
+ * If this function is used in a `select` statement, the type of the selected
340
+ * expression will be the referenced column's type. This is because the result
341
+ * is within the column's value range.
146
342
  *
147
343
  * ### Examples
148
344
  *
@@ -154,9 +350,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
154
350
  * .execute()
155
351
  * ```
156
352
  *
353
+ * The generated SQL (PostgreSQL):
354
+ *
355
+ * ```sql
356
+ * select max("price") as "max_price" from "toy"
357
+ * ```
358
+ *
359
+ * You can limit column range to only columns participating in current query:
360
+ *
361
+ * ```ts
362
+ * db.selectFrom('toy')
363
+ * .select((eb) => eb.fn.max('price').as('max_price'))
364
+ * .execute()
365
+ * ```
366
+ *
157
367
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
158
368
  * was used. It is highly recommended to include null in the output type union
159
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
369
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
160
370
  * function.
161
371
  *
162
372
  * ```ts
@@ -172,8 +382,15 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
172
382
  /**
173
383
  * Calls the `min` function for the column given as the argument.
174
384
  *
175
- * If this is used in a `select` statement the type of the selected expression
176
- * will be the referenced column's type.
385
+ * This sql function calculates the minimum value for a given column.
386
+ *
387
+ * For additional functionality such as distinct, filtering and window functions,
388
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
389
+ * returned when calling this function.
390
+ *
391
+ * If this function is used in a `select` statement, the type of the selected
392
+ * expression will be the referenced column's type. This is because the result
393
+ * is within the column's value range.
177
394
  *
178
395
  * ### Examples
179
396
  *
@@ -185,9 +402,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
185
402
  * .execute()
186
403
  * ```
187
404
  *
405
+ * The generated SQL (PostgreSQL):
406
+ *
407
+ * ```sql
408
+ * select min("price") as "min_price" from "toy"
409
+ * ```
410
+ *
411
+ * You can limit column range to only columns participating in current query:
412
+ *
413
+ * ```ts
414
+ * db.selectFrom('toy')
415
+ * .select((eb) => eb.fn.min('price').as('min_price'))
416
+ * .execute()
417
+ * ```
418
+ *
188
419
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
189
420
  * was used. It is highly recommended to include null in the output type union
190
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
421
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
191
422
  * function.
192
423
  *
193
424
  * ```ts
@@ -203,15 +434,45 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
203
434
  /**
204
435
  * Calls the `sum` function for the column given as the argument.
205
436
  *
206
- * If this is used in a `select` statement the type of the selected expression
207
- * will be `number | string | bigint` by default. This is because Kysely
208
- * can't know the type the db driver outputs. Sometimes the output can be larger
209
- * than the largest javascript number and a string is returned instead. Most
210
- * drivers allow you to configure the output type of large numbers and Kysely
211
- * can't know if you've done so.
437
+ * This sql function sums the values of a given column.
212
438
  *
213
- * You can specify the output type of the expression by providing
214
- * the type as the first type argument:
439
+ * For additional functionality such as distinct, filtering and window functions,
440
+ * refer to {@link AggregateFunctionBuilder}. An instance of this builder is
441
+ * returned when calling this function.
442
+ *
443
+ * ### Examples
444
+ *
445
+ * ```ts
446
+ * const { sum } = db.fn
447
+ *
448
+ * db.selectFrom('toy')
449
+ * .select(sum('price').as('total_price'))
450
+ * .execute()
451
+ * ```
452
+ *
453
+ * The generated SQL (PostgreSQL):
454
+ *
455
+ * ```sql
456
+ * select sum("price") as "total_price" from "toy"
457
+ * ```
458
+ *
459
+ * You can limit column range to only columns participating in current query:
460
+ *
461
+ * ```ts
462
+ * db.selectFrom('toy')
463
+ * .select((eb) => eb.fn.sum('price').as('total_price'))
464
+ * .execute()
465
+ * ```
466
+ *
467
+ * If this function is used in a `select` statement, the type of the selected
468
+ * expression will be `number | string` by default. This is because Kysely can't know the
469
+ * type the db driver outputs. Sometimes the output can be larger than the largest
470
+ * javascript number and a string is returned instead. Most drivers allow you
471
+ * to configure the output type of large numbers and Kysely can't know if you've
472
+ * done so.
473
+ *
474
+ * You can specify the output type of the expression by providing the type as
475
+ * the first type argument:
215
476
  *
216
477
  * ```ts
217
478
  * const { sum } = db.fn
@@ -223,7 +484,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
223
484
  *
224
485
  * Sometimes a null is returned, e.g. when row count is 0, and no `group by`
225
486
  * was used. It is highly recommended to include null in the output type union
226
- * and handle null values in post-execute code, or wrap the function with a `coalesce`
487
+ * and handle null values in post-execute code, or wrap the function with a {@link coalesce}
227
488
  * function.
228
489
  *
229
490
  * ```ts
@@ -236,6 +497,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
236
497
  */
237
498
  sum<O extends number | string | bigint | null = number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
238
499
  }
500
+ export declare function createFunctionModule<DB, TB extends keyof DB>(): FunctionModule<DB, TB>;
239
501
  declare type OutputBoundStringReference<DB, TB extends keyof DB, C extends StringReference<DB, TB>, O> = IsNever<O> extends true ? C : Equals<ExtractTypeFromReferenceExpression<DB, TB, C> | null, O | null> extends true ? C : never;
240
502
  declare type StringReferenceBoundAggregateFunctionBuilder<DB, TB extends keyof DB, C extends StringReference<DB, TB>, O> = AggregateFunctionBuilder<DB, TB, ExtractTypeFromReferenceExpression<DB, TB, C> | (null extends O ? null : never)>;
241
503
  export {};