@warlock.js/cascade 4.0.135 → 4.0.137

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 (339) hide show
  1. package/cjs/context/database-transaction-context.d.ts +4 -0
  2. package/cjs/context/database-transaction-context.d.ts.map +1 -1
  3. package/cjs/context/database-transaction-context.js +6 -0
  4. package/cjs/context/database-transaction-context.js.map +1 -1
  5. package/cjs/contracts/database-driver.contract.d.ts +106 -4
  6. package/cjs/contracts/database-driver.contract.d.ts.map +1 -1
  7. package/cjs/contracts/migration-driver.contract.d.ts +49 -1
  8. package/cjs/contracts/migration-driver.contract.d.ts.map +1 -1
  9. package/cjs/contracts/query-builder.contract.d.ts +76 -4
  10. package/cjs/contracts/query-builder.contract.d.ts.map +1 -1
  11. package/cjs/data-source/data-source.d.ts +40 -1
  12. package/cjs/data-source/data-source.d.ts.map +1 -1
  13. package/cjs/data-source/data-source.js +6 -0
  14. package/cjs/data-source/data-source.js.map +1 -1
  15. package/cjs/database-dirty-tracker.d.ts +21 -22
  16. package/cjs/database-dirty-tracker.d.ts.map +1 -1
  17. package/cjs/database-dirty-tracker.js +14 -17
  18. package/cjs/database-dirty-tracker.js.map +1 -1
  19. package/cjs/drivers/mongodb/mongodb-driver.d.ts +29 -1
  20. package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +1 -1
  21. package/cjs/drivers/mongodb/mongodb-driver.js +116 -4
  22. package/cjs/drivers/mongodb/mongodb-driver.js.map +1 -1
  23. package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +22 -1
  24. package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -1
  25. package/cjs/drivers/mongodb/mongodb-migration-driver.js +27 -0
  26. package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +1 -1
  27. package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +41 -9
  28. package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -1
  29. package/cjs/drivers/mongodb/mongodb-query-builder.js +60 -18
  30. package/cjs/drivers/mongodb/mongodb-query-builder.js.map +1 -1
  31. package/cjs/drivers/mongodb/types.d.ts +1 -1
  32. package/cjs/drivers/mongodb/types.d.ts.map +1 -1
  33. package/cjs/drivers/postgres/postgres-dialect.d.ts +1 -0
  34. package/cjs/drivers/postgres/postgres-dialect.d.ts.map +1 -1
  35. package/cjs/drivers/postgres/postgres-dialect.js +24 -1
  36. package/cjs/drivers/postgres/postgres-dialect.js.map +1 -1
  37. package/cjs/drivers/postgres/postgres-driver.d.ts +24 -3
  38. package/cjs/drivers/postgres/postgres-driver.d.ts.map +1 -1
  39. package/cjs/drivers/postgres/postgres-driver.js +101 -8
  40. package/cjs/drivers/postgres/postgres-driver.js.map +1 -1
  41. package/cjs/drivers/postgres/postgres-migration-driver.d.ts +30 -1
  42. package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +1 -1
  43. package/cjs/drivers/postgres/postgres-migration-driver.js +61 -2
  44. package/cjs/drivers/postgres/postgres-migration-driver.js.map +1 -1
  45. package/cjs/drivers/postgres/postgres-query-builder.d.ts +152 -722
  46. package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +1 -1
  47. package/cjs/drivers/postgres/postgres-query-builder.js +592 -1459
  48. package/cjs/drivers/postgres/postgres-query-builder.js.map +1 -1
  49. package/cjs/drivers/postgres/postgres-query-parser.d.ts +34 -14
  50. package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +1 -1
  51. package/cjs/drivers/postgres/postgres-query-parser.js +197 -39
  52. package/cjs/drivers/postgres/postgres-query-parser.js.map +1 -1
  53. package/cjs/drivers/sql/sql-dialect.contract.d.ts +1 -0
  54. package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +1 -1
  55. package/cjs/errors/transaction-rollback.error.d.ts +20 -0
  56. package/cjs/errors/transaction-rollback.error.d.ts.map +1 -0
  57. package/cjs/errors/transaction-rollback.error.js +27 -0
  58. package/cjs/errors/transaction-rollback.error.js.map +1 -0
  59. package/cjs/events/model-events.d.ts +1 -1
  60. package/cjs/events/model-events.d.ts.map +1 -1
  61. package/cjs/index.d.ts +1 -0
  62. package/cjs/index.d.ts.map +1 -1
  63. package/cjs/index.js +1 -1
  64. package/cjs/migration/column-builder.d.ts +4 -0
  65. package/cjs/migration/column-builder.d.ts.map +1 -1
  66. package/cjs/migration/column-builder.js +23 -6
  67. package/cjs/migration/column-builder.js.map +1 -1
  68. package/cjs/migration/migration-runner.d.ts.map +1 -1
  69. package/cjs/migration/migration-runner.js +137 -23
  70. package/cjs/migration/migration-runner.js.map +1 -1
  71. package/cjs/migration/migration.d.ts +209 -35
  72. package/cjs/migration/migration.d.ts.map +1 -1
  73. package/cjs/migration/migration.js +192 -27
  74. package/cjs/migration/migration.js.map +1 -1
  75. package/cjs/model/methods/accessor-methods.d.ts +13 -0
  76. package/cjs/model/methods/accessor-methods.d.ts.map +1 -0
  77. package/cjs/model/methods/accessor-methods.js +51 -0
  78. package/cjs/model/methods/accessor-methods.js.map +1 -0
  79. package/cjs/model/methods/delete-methods.d.ts +10 -0
  80. package/cjs/model/methods/delete-methods.d.ts.map +1 -0
  81. package/cjs/model/methods/delete-methods.js +10 -0
  82. package/cjs/model/methods/delete-methods.js.map +1 -0
  83. package/cjs/model/methods/dirty-methods.d.ts +10 -0
  84. package/cjs/model/methods/dirty-methods.d.ts.map +1 -0
  85. package/cjs/model/methods/dirty-methods.js +15 -0
  86. package/cjs/model/methods/dirty-methods.js.map +1 -0
  87. package/cjs/model/methods/hydration-methods.d.ts +10 -0
  88. package/cjs/model/methods/hydration-methods.d.ts.map +1 -0
  89. package/cjs/model/methods/hydration-methods.js +57 -0
  90. package/cjs/model/methods/hydration-methods.js.map +1 -0
  91. package/cjs/model/methods/instance-event-methods.d.ts +7 -0
  92. package/cjs/model/methods/instance-event-methods.d.ts.map +1 -0
  93. package/cjs/model/methods/instance-event-methods.js +15 -0
  94. package/cjs/model/methods/instance-event-methods.js.map +1 -0
  95. package/cjs/model/methods/meta-methods.d.ts +7 -0
  96. package/cjs/model/methods/meta-methods.d.ts.map +1 -0
  97. package/cjs/model/methods/meta-methods.js +78 -0
  98. package/cjs/model/methods/meta-methods.js.map +1 -0
  99. package/cjs/model/methods/query-methods.d.ts +24 -0
  100. package/cjs/model/methods/query-methods.d.ts.map +1 -0
  101. package/cjs/model/methods/query-methods.js +161 -0
  102. package/cjs/model/methods/query-methods.js.map +1 -0
  103. package/cjs/model/methods/restore-methods.d.ts +10 -0
  104. package/cjs/model/methods/restore-methods.d.ts.map +1 -0
  105. package/cjs/model/methods/restore-methods.js +13 -0
  106. package/cjs/model/methods/restore-methods.js.map +1 -0
  107. package/cjs/model/methods/scope-methods.d.ts +7 -0
  108. package/cjs/model/methods/scope-methods.d.ts.map +1 -0
  109. package/cjs/model/methods/scope-methods.js +15 -0
  110. package/cjs/model/methods/scope-methods.js.map +1 -0
  111. package/cjs/model/methods/serialization-methods.d.ts +3 -0
  112. package/cjs/model/methods/serialization-methods.d.ts.map +1 -0
  113. package/cjs/model/methods/serialization-methods.js +27 -0
  114. package/cjs/model/methods/serialization-methods.js.map +1 -0
  115. package/cjs/model/methods/static-event-methods.d.ts +9 -0
  116. package/cjs/model/methods/static-event-methods.d.ts.map +1 -0
  117. package/cjs/model/methods/static-event-methods.js +29 -0
  118. package/cjs/model/methods/static-event-methods.js.map +1 -0
  119. package/cjs/model/methods/write-methods.d.ts +10 -0
  120. package/cjs/model/methods/write-methods.d.ts.map +1 -0
  121. package/cjs/model/methods/write-methods.js +52 -0
  122. package/cjs/model/methods/write-methods.js.map +1 -0
  123. package/cjs/model/model.d.ts +89 -58
  124. package/cjs/model/model.d.ts.map +1 -1
  125. package/cjs/model/model.js +166 -424
  126. package/cjs/model/model.js.map +1 -1
  127. package/cjs/model/model.types.d.ts +44 -0
  128. package/cjs/model/model.types.d.ts.map +1 -0
  129. package/cjs/model/register-model.d.ts +3 -3
  130. package/cjs/model/register-model.d.ts.map +1 -1
  131. package/cjs/query-builder/query-builder.d.ts +556 -0
  132. package/cjs/query-builder/query-builder.d.ts.map +1 -0
  133. package/cjs/query-builder/query-builder.js +1070 -0
  134. package/cjs/query-builder/query-builder.js.map +1 -0
  135. package/cjs/relations/helpers.d.ts.map +1 -1
  136. package/cjs/relations/helpers.js +4 -0
  137. package/cjs/relations/helpers.js.map +1 -1
  138. package/cjs/relations/index.d.ts +2 -0
  139. package/cjs/relations/index.d.ts.map +1 -1
  140. package/cjs/relations/relation-hydrator.d.ts +68 -0
  141. package/cjs/relations/relation-hydrator.d.ts.map +1 -0
  142. package/cjs/relations/relation-hydrator.js +81 -0
  143. package/cjs/relations/relation-hydrator.js.map +1 -0
  144. package/cjs/relations/relation-loader.js +1 -1
  145. package/cjs/relations/relation-loader.js.map +1 -1
  146. package/cjs/relations/types.d.ts +26 -0
  147. package/cjs/relations/types.d.ts.map +1 -1
  148. package/cjs/sql-database-dirty-tracker.d.ts +13 -0
  149. package/cjs/sql-database-dirty-tracker.d.ts.map +1 -0
  150. package/cjs/sql-database-dirty-tracker.js +14 -0
  151. package/cjs/sql-database-dirty-tracker.js.map +1 -0
  152. package/cjs/types.d.ts +59 -0
  153. package/cjs/types.d.ts.map +1 -1
  154. package/cjs/utils/connect-to-database.d.ts +50 -1
  155. package/cjs/utils/connect-to-database.d.ts.map +1 -1
  156. package/cjs/utils/connect-to-database.js +14 -1
  157. package/cjs/utils/connect-to-database.js.map +1 -1
  158. package/cjs/utils/database-writer.utils.d.ts +1 -1
  159. package/cjs/utils/database-writer.utils.d.ts.map +1 -1
  160. package/cjs/utils/is-valid-date-value.d.ts +5 -0
  161. package/cjs/utils/is-valid-date-value.d.ts.map +1 -0
  162. package/cjs/utils/is-valid-date-value.js +25 -0
  163. package/cjs/utils/is-valid-date-value.js.map +1 -0
  164. package/cjs/utils/once-connected.d.ts.map +1 -1
  165. package/cjs/utils/once-connected.js +4 -5
  166. package/cjs/utils/once-connected.js.map +1 -1
  167. package/cjs/writer/database-writer.d.ts.map +1 -1
  168. package/cjs/writer/database-writer.js +7 -6
  169. package/cjs/writer/database-writer.js.map +1 -1
  170. package/esm/context/database-transaction-context.d.ts +4 -0
  171. package/esm/context/database-transaction-context.d.ts.map +1 -1
  172. package/esm/context/database-transaction-context.js +6 -0
  173. package/esm/context/database-transaction-context.js.map +1 -1
  174. package/esm/contracts/database-driver.contract.d.ts +106 -4
  175. package/esm/contracts/database-driver.contract.d.ts.map +1 -1
  176. package/esm/contracts/migration-driver.contract.d.ts +49 -1
  177. package/esm/contracts/migration-driver.contract.d.ts.map +1 -1
  178. package/esm/contracts/query-builder.contract.d.ts +76 -4
  179. package/esm/contracts/query-builder.contract.d.ts.map +1 -1
  180. package/esm/data-source/data-source.d.ts +40 -1
  181. package/esm/data-source/data-source.d.ts.map +1 -1
  182. package/esm/data-source/data-source.js +6 -0
  183. package/esm/data-source/data-source.js.map +1 -1
  184. package/esm/database-dirty-tracker.d.ts +21 -22
  185. package/esm/database-dirty-tracker.d.ts.map +1 -1
  186. package/esm/database-dirty-tracker.js +14 -17
  187. package/esm/database-dirty-tracker.js.map +1 -1
  188. package/esm/drivers/mongodb/mongodb-driver.d.ts +29 -1
  189. package/esm/drivers/mongodb/mongodb-driver.d.ts.map +1 -1
  190. package/esm/drivers/mongodb/mongodb-driver.js +116 -4
  191. package/esm/drivers/mongodb/mongodb-driver.js.map +1 -1
  192. package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +22 -1
  193. package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -1
  194. package/esm/drivers/mongodb/mongodb-migration-driver.js +27 -0
  195. package/esm/drivers/mongodb/mongodb-migration-driver.js.map +1 -1
  196. package/esm/drivers/mongodb/mongodb-query-builder.d.ts +41 -9
  197. package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -1
  198. package/esm/drivers/mongodb/mongodb-query-builder.js +60 -18
  199. package/esm/drivers/mongodb/mongodb-query-builder.js.map +1 -1
  200. package/esm/drivers/mongodb/types.d.ts +1 -1
  201. package/esm/drivers/mongodb/types.d.ts.map +1 -1
  202. package/esm/drivers/postgres/postgres-dialect.d.ts +1 -0
  203. package/esm/drivers/postgres/postgres-dialect.d.ts.map +1 -1
  204. package/esm/drivers/postgres/postgres-dialect.js +24 -1
  205. package/esm/drivers/postgres/postgres-dialect.js.map +1 -1
  206. package/esm/drivers/postgres/postgres-driver.d.ts +24 -3
  207. package/esm/drivers/postgres/postgres-driver.d.ts.map +1 -1
  208. package/esm/drivers/postgres/postgres-driver.js +101 -8
  209. package/esm/drivers/postgres/postgres-driver.js.map +1 -1
  210. package/esm/drivers/postgres/postgres-migration-driver.d.ts +30 -1
  211. package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +1 -1
  212. package/esm/drivers/postgres/postgres-migration-driver.js +61 -2
  213. package/esm/drivers/postgres/postgres-migration-driver.js.map +1 -1
  214. package/esm/drivers/postgres/postgres-query-builder.d.ts +152 -722
  215. package/esm/drivers/postgres/postgres-query-builder.d.ts.map +1 -1
  216. package/esm/drivers/postgres/postgres-query-builder.js +592 -1459
  217. package/esm/drivers/postgres/postgres-query-builder.js.map +1 -1
  218. package/esm/drivers/postgres/postgres-query-parser.d.ts +34 -14
  219. package/esm/drivers/postgres/postgres-query-parser.d.ts.map +1 -1
  220. package/esm/drivers/postgres/postgres-query-parser.js +197 -39
  221. package/esm/drivers/postgres/postgres-query-parser.js.map +1 -1
  222. package/esm/drivers/sql/sql-dialect.contract.d.ts +1 -0
  223. package/esm/drivers/sql/sql-dialect.contract.d.ts.map +1 -1
  224. package/esm/errors/transaction-rollback.error.d.ts +20 -0
  225. package/esm/errors/transaction-rollback.error.d.ts.map +1 -0
  226. package/esm/errors/transaction-rollback.error.js +27 -0
  227. package/esm/errors/transaction-rollback.error.js.map +1 -0
  228. package/esm/events/model-events.d.ts +1 -1
  229. package/esm/events/model-events.d.ts.map +1 -1
  230. package/esm/index.d.ts +1 -0
  231. package/esm/index.d.ts.map +1 -1
  232. package/esm/index.js +1 -1
  233. package/esm/migration/column-builder.d.ts +4 -0
  234. package/esm/migration/column-builder.d.ts.map +1 -1
  235. package/esm/migration/column-builder.js +23 -6
  236. package/esm/migration/column-builder.js.map +1 -1
  237. package/esm/migration/migration-runner.d.ts.map +1 -1
  238. package/esm/migration/migration-runner.js +137 -23
  239. package/esm/migration/migration-runner.js.map +1 -1
  240. package/esm/migration/migration.d.ts +209 -35
  241. package/esm/migration/migration.d.ts.map +1 -1
  242. package/esm/migration/migration.js +192 -27
  243. package/esm/migration/migration.js.map +1 -1
  244. package/esm/model/methods/accessor-methods.d.ts +13 -0
  245. package/esm/model/methods/accessor-methods.d.ts.map +1 -0
  246. package/esm/model/methods/accessor-methods.js +51 -0
  247. package/esm/model/methods/accessor-methods.js.map +1 -0
  248. package/esm/model/methods/delete-methods.d.ts +10 -0
  249. package/esm/model/methods/delete-methods.d.ts.map +1 -0
  250. package/esm/model/methods/delete-methods.js +10 -0
  251. package/esm/model/methods/delete-methods.js.map +1 -0
  252. package/esm/model/methods/dirty-methods.d.ts +10 -0
  253. package/esm/model/methods/dirty-methods.d.ts.map +1 -0
  254. package/esm/model/methods/dirty-methods.js +15 -0
  255. package/esm/model/methods/dirty-methods.js.map +1 -0
  256. package/esm/model/methods/hydration-methods.d.ts +10 -0
  257. package/esm/model/methods/hydration-methods.d.ts.map +1 -0
  258. package/esm/model/methods/hydration-methods.js +57 -0
  259. package/esm/model/methods/hydration-methods.js.map +1 -0
  260. package/esm/model/methods/instance-event-methods.d.ts +7 -0
  261. package/esm/model/methods/instance-event-methods.d.ts.map +1 -0
  262. package/esm/model/methods/instance-event-methods.js +15 -0
  263. package/esm/model/methods/instance-event-methods.js.map +1 -0
  264. package/esm/model/methods/meta-methods.d.ts +7 -0
  265. package/esm/model/methods/meta-methods.d.ts.map +1 -0
  266. package/esm/model/methods/meta-methods.js +78 -0
  267. package/esm/model/methods/meta-methods.js.map +1 -0
  268. package/esm/model/methods/query-methods.d.ts +24 -0
  269. package/esm/model/methods/query-methods.d.ts.map +1 -0
  270. package/esm/model/methods/query-methods.js +161 -0
  271. package/esm/model/methods/query-methods.js.map +1 -0
  272. package/esm/model/methods/restore-methods.d.ts +10 -0
  273. package/esm/model/methods/restore-methods.d.ts.map +1 -0
  274. package/esm/model/methods/restore-methods.js +13 -0
  275. package/esm/model/methods/restore-methods.js.map +1 -0
  276. package/esm/model/methods/scope-methods.d.ts +7 -0
  277. package/esm/model/methods/scope-methods.d.ts.map +1 -0
  278. package/esm/model/methods/scope-methods.js +15 -0
  279. package/esm/model/methods/scope-methods.js.map +1 -0
  280. package/esm/model/methods/serialization-methods.d.ts +3 -0
  281. package/esm/model/methods/serialization-methods.d.ts.map +1 -0
  282. package/esm/model/methods/serialization-methods.js +27 -0
  283. package/esm/model/methods/serialization-methods.js.map +1 -0
  284. package/esm/model/methods/static-event-methods.d.ts +9 -0
  285. package/esm/model/methods/static-event-methods.d.ts.map +1 -0
  286. package/esm/model/methods/static-event-methods.js +29 -0
  287. package/esm/model/methods/static-event-methods.js.map +1 -0
  288. package/esm/model/methods/write-methods.d.ts +10 -0
  289. package/esm/model/methods/write-methods.d.ts.map +1 -0
  290. package/esm/model/methods/write-methods.js +52 -0
  291. package/esm/model/methods/write-methods.js.map +1 -0
  292. package/esm/model/model.d.ts +89 -58
  293. package/esm/model/model.d.ts.map +1 -1
  294. package/esm/model/model.js +166 -424
  295. package/esm/model/model.js.map +1 -1
  296. package/esm/model/model.types.d.ts +44 -0
  297. package/esm/model/model.types.d.ts.map +1 -0
  298. package/esm/model/register-model.d.ts +3 -3
  299. package/esm/model/register-model.d.ts.map +1 -1
  300. package/esm/query-builder/query-builder.d.ts +556 -0
  301. package/esm/query-builder/query-builder.d.ts.map +1 -0
  302. package/esm/query-builder/query-builder.js +1070 -0
  303. package/esm/query-builder/query-builder.js.map +1 -0
  304. package/esm/relations/helpers.d.ts.map +1 -1
  305. package/esm/relations/helpers.js +4 -0
  306. package/esm/relations/helpers.js.map +1 -1
  307. package/esm/relations/index.d.ts +2 -0
  308. package/esm/relations/index.d.ts.map +1 -1
  309. package/esm/relations/relation-hydrator.d.ts +68 -0
  310. package/esm/relations/relation-hydrator.d.ts.map +1 -0
  311. package/esm/relations/relation-hydrator.js +81 -0
  312. package/esm/relations/relation-hydrator.js.map +1 -0
  313. package/esm/relations/relation-loader.js +1 -1
  314. package/esm/relations/relation-loader.js.map +1 -1
  315. package/esm/relations/types.d.ts +26 -0
  316. package/esm/relations/types.d.ts.map +1 -1
  317. package/esm/sql-database-dirty-tracker.d.ts +13 -0
  318. package/esm/sql-database-dirty-tracker.d.ts.map +1 -0
  319. package/esm/sql-database-dirty-tracker.js +14 -0
  320. package/esm/sql-database-dirty-tracker.js.map +1 -0
  321. package/esm/types.d.ts +59 -0
  322. package/esm/types.d.ts.map +1 -1
  323. package/esm/utils/connect-to-database.d.ts +50 -1
  324. package/esm/utils/connect-to-database.d.ts.map +1 -1
  325. package/esm/utils/connect-to-database.js +14 -1
  326. package/esm/utils/connect-to-database.js.map +1 -1
  327. package/esm/utils/database-writer.utils.d.ts +1 -1
  328. package/esm/utils/database-writer.utils.d.ts.map +1 -1
  329. package/esm/utils/is-valid-date-value.d.ts +5 -0
  330. package/esm/utils/is-valid-date-value.d.ts.map +1 -0
  331. package/esm/utils/is-valid-date-value.js +25 -0
  332. package/esm/utils/is-valid-date-value.js.map +1 -0
  333. package/esm/utils/once-connected.d.ts.map +1 -1
  334. package/esm/utils/once-connected.js +4 -5
  335. package/esm/utils/once-connected.js.map +1 -1
  336. package/esm/writer/database-writer.d.ts.map +1 -1
  337. package/esm/writer/database-writer.js +7 -6
  338. package/esm/writer/database-writer.js.map +1 -1
  339. package/package.json +4 -4
@@ -1,824 +1,254 @@
1
1
  /**
2
2
  * PostgreSQL Query Builder
3
3
  *
4
- * Implements the QueryBuilderContract for PostgreSQL databases.
5
- * Provides a fluent API for building SQL queries with proper
6
- * parameter handling and type safety.
4
+ * Extends the pure QueryBuilder base with PostgreSQL-specific execution,
5
+ * SQL generation, relation hydration, and scope management.
7
6
  *
8
7
  * @module cascade/drivers/postgres
9
8
  */
10
9
  import type { GenericObject } from "@mongez/reinforcements";
11
- import type { ChunkCallback, CursorPaginationOptions, CursorPaginationResult, GroupByInput, HavingInput, JoinOptions, OrderDirection, PaginationOptions, PaginationResult, QueryBuilderContract, RawExpression, WhereCallback, WhereObject, WhereOperator } from "../../contracts/query-builder.contract";
10
+ import type { ChunkCallback, CursorPaginationOptions, CursorPaginationResult, DriverQuery, PaginationOptions, PaginationResult, QueryBuilderContract } from "../../contracts/query-builder.contract";
12
11
  import type { DataSource } from "../../data-source/data-source";
13
- import type { GlobalScopeDefinition, LocalScopeCallback } from "../../model/model";
14
- import { type PostgresParserOperation } from "./postgres-query-parser";
12
+ import { QueryBuilder, type Op } from "../../query-builder/query-builder";
13
+ type JoinRelationConfig = {
14
+ alias: string;
15
+ type: "belongsTo" | "hasOne" | "hasMany";
16
+ model?: unknown;
17
+ localKey?: string;
18
+ foreignKey?: string;
19
+ ownerKey?: string;
20
+ parentPath?: string | null;
21
+ relationName?: string;
22
+ parentModel?: unknown;
23
+ select?: string[];
24
+ /** Operations recorded by a joinWith constraint callback. */
25
+ constraintOps?: Op[];
26
+ };
15
27
  /**
16
28
  * PostgreSQL Query Builder.
17
29
  *
18
- * Implements the Cascade QueryBuilderContract for PostgreSQL.
19
- * Collects query operations and delegates to PostgresQueryParser
20
- * for SQL generation.
30
+ * Collects query operations (via the base class) and delegates SQL generation
31
+ * to `PostgresQueryParser`. Owns execution, hydration, and relation loading.
21
32
  *
22
33
  * @example
23
34
  * ```typescript
24
- * const users = await queryBuilder('users')
25
- * .select(['id', 'name', 'email'])
26
- * .where('status', 'active')
27
- * .where('age', '>', 18)
28
- * .orderBy('createdAt', 'desc')
35
+ * const users = await User.query()
36
+ * .select(["id", "name", "email"])
37
+ * .where("status", "active")
38
+ * .orderBy("createdAt", "desc")
29
39
  * .limit(10)
30
40
  * .get();
31
41
  * ```
32
42
  */
33
- export declare class PostgresQueryBuilder<T = unknown> implements QueryBuilderContract<T> {
43
+ export declare class PostgresQueryBuilder<T = unknown> extends QueryBuilder<T> implements QueryBuilderContract<T> {
34
44
  readonly table: string;
35
- /**
36
- * Collected operations to be parsed into SQL.
37
- */
38
- operations: PostgresParserOperation[];
39
- /**
40
- * Data source instance.
41
- */
45
+ /** Data source backing this builder. */
42
46
  readonly dataSource: DataSource;
43
- /**
44
- * Hydrate callback for transforming results.
45
- */
47
+ /** Hydration callback for transforming result rows into model instances. */
46
48
  hydrateCallback?: (data: unknown, index: number) => unknown;
47
- /**
48
- * Callback invoked before query execution.
49
- */
49
+ /** Invoked before query execution. */
50
50
  private fetchingCallback?;
51
- /**
52
- * Callback invoked after records fetched but before hydration.
53
- */
51
+ /** Invoked after fetch but before hydration. */
54
52
  private hydratingCallback?;
55
- /**
56
- * Callback invoked after records fetched and hydrated.
57
- */
53
+ /** Invoked after fetch and hydration. */
58
54
  private fetchedCallback?;
59
55
  /**
60
- * Pending global scopes.
56
+ * Map of relations registered via `joinWith()`.
57
+ * Keyed by dot-notation path (e.g. "organizationAiModel.aiModel").
61
58
  */
62
- pendingGlobalScopes?: Map<string, GlobalScopeDefinition>;
59
+ joinRelations: Map<string, JoinRelationConfig>;
63
60
  /**
64
- * Available local scopes.
65
- */
66
- availableLocalScopes?: Map<string, LocalScopeCallback>;
67
- /**
68
- * Disabled global scope names.
69
- */
70
- disabledGlobalScopes: Set<string>;
71
- /**
72
- * Whether scopes have been applied.
73
- */
74
- scopesApplied: boolean;
75
- /**
76
- * Create a new query builder.
77
- *
78
61
  * @param table - Target table name
79
- * @param dataSource - Optional data source (uses default if not provided)
62
+ * @param dataSource - Optional (uses default data source from registry if omitted)
80
63
  */
81
64
  constructor(table: string, dataSource?: DataSource);
82
- /**
83
- * Get the PostgreSQL driver instance.
84
- */
85
65
  private get driver();
66
+ clone(): this;
86
67
  /**
87
- * Add an operation to the operations list.
68
+ * Native-query escape hatch. Passes `operations[]` to the callback for
69
+ * direct manipulation. Use sparingly — only when fluent API is insufficient.
88
70
  *
89
- * @param type - Operation type
90
- * @param data - Operation data
71
+ * @example
72
+ * q.raw(ops => ops.push({ type: "whereRaw", data: { expression: "1=1" } }))
91
73
  */
92
- private addOperation;
74
+ raw(callback: (operations: Op[]) => void): this;
93
75
  /**
94
- * Clone this query builder with all current operations.
76
+ * Record a DISTINCT flag AND auto-select the field(s).
77
+ * In PostgreSQL, DISTINCT ON (col) requires the col to appear in SELECT.
95
78
  *
96
- * @returns New query builder instance
79
+ * @example
80
+ * q.distinctValues("category") // SELECT category … DISTINCT ON (category)
81
+ * q.distinctValues(["category", "status"]) // both fields in DISTINCT ON and SELECT
97
82
  */
98
- clone(): this;
83
+ distinctValues(fields?: string | string[]): this;
99
84
  /**
100
- * Set a hydration callback to transform each result row.
85
+ * Nearest-neighbour vector similarity search via pgvector cosine distance.
101
86
  *
102
- * @param callback - Transform function
103
- * @returns This builder for chaining
104
- */
105
- hydrate(callback: (data: unknown, index: number) => unknown): this;
106
- /**
107
- * Register callback invoked before query execution.
87
+ * Adds two operations atomically:
88
+ * 1. `selectRaw` `1 - (column <=> $n::vector) AS <alias>`
89
+ * Makes the similarity score available on every returned row.
90
+ * 2. `orderByRaw` `column <=> $n::vector`
91
+ * Tells the PostgreSQL query planner to use the IVFFlat/HNSW vector index.
92
+ * Using the alias in ORDER BY would bypass the index — the raw expression is required.
108
93
  *
109
- * @param callback - Callback function
110
- * @returns Unsubscribe function
111
- */
94
+ * @example
95
+ * ```typescript
96
+ * const results = await Vector.query()
97
+ * .where({ organization_id: "org-123", content_type: "summary" })
98
+ * .nearestTo("embedding", queryEmbedding)
99
+ * .limit(5)
100
+ * .get<VectorRow & { score: number }>();
101
+ * ```
102
+ */
103
+ nearestTo(column: string, embedding: number[], alias?: string): this;
104
+ /** Set a hydration callback that transforms each result row. */
105
+ hydrate(callback: (data: unknown, index: number) => unknown): this;
106
+ /** Register a callback invoked before query execution. */
112
107
  onFetching(callback: (query: this) => void | Promise<void>): () => void;
113
- /**
114
- * Register callback invoked after fetch but before hydration.
115
- *
116
- * @param callback - Callback function
117
- * @returns Unsubscribe function
118
- */
108
+ /** Register a callback invoked after fetch but before hydration. */
119
109
  onHydrating(callback: (records: unknown[], context: unknown) => void | Promise<void>): () => void;
120
- /**
121
- * Register callback invoked after fetch and hydration.
122
- *
123
- * @param callback - Callback function
124
- * @returns Unsubscribe function
125
- */
110
+ /** Register a callback invoked after fetch and hydration. */
126
111
  onFetched(callback: (records: unknown[], context: unknown) => void | Promise<void>): () => void;
127
- /**
128
- * Disable one or more global scopes for this query.
129
- *
130
- * @param scopeNames - Scope names to disable
131
- * @returns This builder for chaining
132
- */
133
- withoutGlobalScope(...scopeNames: string[]): this;
134
- /**
135
- * Disable all global scopes for this query.
136
- *
137
- * @returns This builder for chaining
138
- */
139
- withoutGlobalScopes(): this;
140
- /**
141
- * Apply a local scope to this query.
142
- *
143
- * @param scopeName - Name of the local scope
144
- * @returns This builder for chaining
145
- */
146
- scope(scopeName: string): this;
147
- /**
148
- * Apply pending global scopes before query execution.
149
- */
112
+ /** Apply pending global scopes to the operations list. */
150
113
  private applyPendingScopes;
151
- /**
152
- * Add a WHERE clause to filter records.
153
- */
154
- where(field: string, value: unknown): this;
155
- where(field: string, operator: WhereOperator, value: unknown): this;
156
- where(conditions: WhereObject): this;
157
- where(callback: WhereCallback<T>): this;
158
- /**
159
- * Add an OR WHERE clause.
160
- */
161
- orWhere(field: string, value: unknown): this;
162
- orWhere(field: string, operator: WhereOperator, value: unknown): this;
163
- orWhere(conditions: WhereObject): this;
164
- orWhere(callback: WhereCallback<T>): this;
165
- /**
166
- * Add a raw WHERE clause.
167
- */
168
- whereRaw(expression: RawExpression, bindings?: unknown[]): this;
169
- /**
170
- * Add a raw OR WHERE clause.
171
- */
172
- orWhereRaw(expression: RawExpression, bindings?: unknown[]): this;
173
- /**
174
- * Compare two columns.
175
- */
176
- whereColumn(first: string, operator: WhereOperator, second: string): this;
177
- /**
178
- * Compare two columns with OR.
179
- */
180
- orWhereColumn(first: string, operator: WhereOperator, second: string): this;
181
- /**
182
- * Compare multiple column pairs.
183
- */
184
- whereColumns(comparisons: Array<[left: string, operator: WhereOperator, right: string]>): this;
185
- /**
186
- * Check if field is between two columns.
187
- */
188
- whereBetweenColumns(field: string, lowerColumn: string, upperColumn: string): this;
189
- /**
190
- * Filter by date (ignoring time).
191
- */
192
- whereDate(field: string, value: Date | string): this;
193
- /**
194
- * Alias for whereDate.
195
- */
196
- whereDateEquals(field: string, value: Date | string): this;
197
- /**
198
- * Filter for dates before a value.
199
- */
200
- whereDateBefore(field: string, value: Date | string): this;
201
- /**
202
- * Filter for dates after a value.
203
- */
204
- whereDateAfter(field: string, value: Date | string): this;
205
- /**
206
- * Filter by time.
207
- */
208
- whereTime(field: string, value: string): this;
209
- /**
210
- * Filter by day of month.
211
- */
212
- whereDay(field: string, value: number): this;
213
- /**
214
- * Filter by month.
215
- */
216
- whereMonth(field: string, value: number): this;
217
- /**
218
- * Filter by year.
219
- */
220
- whereYear(field: string, value: number): this;
221
- /**
222
- * Check if JSON contains value.
223
- */
224
- whereJsonContains(path: string, value: unknown): this;
225
- /**
226
- * Check if JSON doesn't contain value.
227
- */
228
- whereJsonDoesntContain(path: string, value: unknown): this;
229
- /**
230
- * Check if JSON contains key.
231
- */
232
- whereJsonContainsKey(path: string): this;
233
- /**
234
- * Check JSON array/string length.
235
- */
236
- whereJsonLength(path: string, operator: WhereOperator, value: number): this;
237
- /**
238
- * Check if JSON is array.
239
- */
240
- whereJsonIsArray(path: string): this;
241
- /**
242
- * Check if JSON is object.
243
- */
244
- whereJsonIsObject(path: string): this;
245
- /**
246
- * Check array length.
247
- */
248
- whereArrayLength(field: string, operator: WhereOperator, value: number): this;
249
- /**
250
- * Filter by ID.
251
- */
252
- whereId(value: string | number): this;
253
- /**
254
- * Filter by multiple IDs.
255
- */
256
- whereIds(values: Array<string | number>): this;
257
- /**
258
- * Filter by UUID.
259
- */
260
- whereUuid(value: string): this;
261
- /**
262
- * Filter by ULID.
263
- */
264
- whereUlid(value: string): this;
265
- /**
266
- * Full-text search.
267
- */
268
- whereFullText(fields: string | string[], query: string): this;
269
- /**
270
- * Full-text search with OR.
271
- */
272
- orWhereFullText(fields: string | string[], query: string): this;
273
- /**
274
- * Alias for whereFullText.
275
- */
276
- whereSearch(field: string, query: string): this;
277
- /**
278
- * Negate conditions.
279
- */
280
- whereNot(callback: WhereCallback<T>): this;
281
- /**
282
- * Negate conditions with OR.
283
- */
284
- orWhereNot(callback: WhereCallback<T>): this;
285
- /**
286
- * Filter by value in array.
287
- */
288
- whereIn(field: string, values: unknown[]): this;
289
- /**
290
- * Filter by value not in array.
291
- */
292
- whereNotIn(field: string, values: unknown[]): this;
293
- /**
294
- * Filter by NULL value.
295
- */
296
- whereNull(field: string): this;
297
- /**
298
- * Filter by NOT NULL value.
299
- */
300
- whereNotNull(field: string): this;
301
- /**
302
- * Filter by range (inclusive).
303
- */
304
- whereBetween(field: string, range: [unknown, unknown]): this;
305
- /**
306
- * Filter by not in range.
307
- */
308
- whereNotBetween(field: string, range: [unknown, unknown]): this;
309
- /**
310
- * Filter by LIKE pattern (case-insensitive).
311
- */
312
- whereLike(field: string, pattern: RegExp | string): this;
313
- /**
314
- * Filter by NOT LIKE pattern.
315
- */
316
- whereNotLike(field: string, pattern: RegExp | string): this;
317
- /**
318
- * Filter by prefix.
319
- */
320
- whereStartsWith(field: string, value: string | number): this;
321
- /**
322
- * Filter by not starting with prefix.
323
- */
324
- whereNotStartsWith(field: string, value: string | number): this;
325
- /**
326
- * Filter by suffix.
327
- */
328
- whereEndsWith(field: string, value: string | number): this;
329
- /**
330
- * Filter by not ending with suffix.
331
- */
332
- whereNotEndsWith(field: string, value: string | number): this;
333
- /**
334
- * Filter by date range.
335
- */
336
- whereDateBetween(field: string, range: [Date, Date]): this;
337
- /**
338
- * Filter by not in date range.
339
- */
340
- whereDateNotBetween(field: string, range: [Date, Date]): this;
341
- /**
342
- * Check if field/subquery exists.
343
- */
344
- whereExists(field: string): this;
345
- whereExists(callback: WhereCallback<T>): this;
346
- /**
347
- * Check if field/subquery doesn't exist.
348
- */
349
- whereNotExists(field: string): this;
350
- whereNotExists(callback: WhereCallback<T>): this;
351
- /**
352
- * Check array size.
353
- */
354
- whereSize(field: string, size: number): this;
355
- whereSize(field: string, operator: WhereOperator, size: number): this;
356
- /**
357
- * Perform a full-text search.
358
- */
359
- textSearch(query: string, filters?: WhereObject): this;
360
- /**
361
- * Constrain an array field to contain the given value.
362
- */
114
+ /** Array field contains a value (or object with key). */
363
115
  whereArrayContains(field: string, value: unknown, key?: string): this;
364
- /**
365
- * Constrain an array field to not contain the given value.
366
- */
116
+ /** Array field does NOT contain a value (or object with key). */
367
117
  whereArrayNotContains(field: string, value: unknown, key?: string): this;
368
- /**
369
- * Constrain an array field to contain the value OR be empty.
370
- */
118
+ /** Array field contains value OR is empty. */
371
119
  whereArrayHasOrEmpty(field: string, value: unknown, key?: string): this;
372
- /**
373
- * Constrain an array field to not contain the value OR be empty.
374
- */
120
+ /** Array field does NOT contain value OR is empty. */
375
121
  whereArrayNotHaveOrEmpty(field: string, value: unknown, key?: string): this;
376
122
  /**
377
- * Add a JOIN clause.
378
- */
379
- join(table: string, localField: string, foreignField: string): this;
380
- join(options: JoinOptions): this;
381
- /**
382
- * Add a LEFT JOIN clause.
383
- */
384
- leftJoin(table: string, localField: string, foreignField: string): this;
385
- leftJoin(options: JoinOptions): this;
386
- /**
387
- * Add a RIGHT JOIN clause.
388
- */
389
- rightJoin(table: string, localField: string, foreignField: string): this;
390
- rightJoin(options: JoinOptions): this;
391
- /**
392
- * Add an INNER JOIN clause.
393
- */
394
- innerJoin(table: string, localField: string, foreignField: string): this;
395
- innerJoin(options: JoinOptions): this;
396
- /**
397
- * Add a FULL OUTER JOIN clause.
398
- */
399
- fullJoin(table: string, localField: string, foreignField: string): this;
400
- fullJoin(options: JoinOptions): this;
401
- /**
402
- * Add a CROSS JOIN clause.
403
- */
404
- crossJoin(table: string): this;
405
- /**
406
- * Add a raw JOIN clause.
407
- */
408
- joinRaw(expression: RawExpression, bindings?: unknown[]): this;
409
- /**
410
- * Select specific columns.
411
- */
412
- select(fields: string[]): this;
413
- select(fields: Record<string, 0 | 1 | boolean>): this;
414
- select(...fields: Array<string | string[]>): this;
415
- /**
416
- * Select a field with alias.
417
- */
418
- selectAs(field: string, alias: string): this;
419
- /**
420
- * Select raw expression.
421
- */
422
- selectRaw(expression: RawExpression, bindings?: unknown[]): this;
423
- /**
424
- * Select multiple raw expressions.
425
- */
426
- selectRawMany(definitions: Array<{
427
- alias: string;
428
- expression: RawExpression;
429
- bindings?: unknown[];
430
- }>): this;
431
- /**
432
- * Select subquery.
433
- */
434
- selectSub(expression: RawExpression, alias: string): this;
435
- /**
436
- * Add subquery to existing selection.
437
- */
438
- addSelectSub(expression: RawExpression, alias: string): this;
439
- /**
440
- * Select aggregate value.
441
- */
442
- selectAggregate(field: string, aggregate: "sum" | "avg" | "min" | "max" | "count" | "first" | "last", alias: string): this;
443
- /**
444
- * Select existence check.
445
- */
446
- selectExists(field: string, alias: string): this;
447
- /**
448
- * Select count.
449
- */
450
- selectCount(field: string, alias: string): this;
451
- /**
452
- * Select CASE expression.
453
- */
454
- selectCase(cases: Array<{
455
- when: RawExpression;
456
- then: RawExpression | unknown;
457
- }>, otherwise: RawExpression | unknown, alias: string): this;
458
- /**
459
- * Select conditional (IF/ELSE).
460
- */
461
- selectWhen(condition: RawExpression, thenValue: RawExpression | unknown, elseValue: RawExpression | unknown, alias: string): this;
462
- /**
463
- * Direct projection manipulation.
464
- */
465
- selectDriverProjection(callback: (projection: Record<string, unknown>) => void): this;
466
- /**
467
- * Select JSON path.
468
- */
469
- selectJson(path: string, alias?: string): this;
470
- /**
471
- * Select JSON path with raw expression.
472
- */
473
- selectJsonRaw(path: string, expression: RawExpression, alias: string): this;
474
- /**
475
- * Exclude JSON path.
476
- */
477
- deselectJson(path: string): this;
478
- /**
479
- * Concatenate fields.
480
- */
481
- selectConcat(fields: Array<string | RawExpression>, alias: string): this;
482
- /**
483
- * Coalesce values.
484
- */
485
- selectCoalesce(fields: Array<string | RawExpression>, alias: string): this;
486
- /**
487
- * Window function.
488
- */
489
- selectWindow(spec: RawExpression): this;
490
- /**
491
- * Exclude columns from projection.
492
- */
493
- deselect(fields: string[]): this;
494
- /**
495
- * Clear selection.
496
- */
497
- clearSelect(): this;
498
- /**
499
- * Select all columns.
500
- */
501
- selectAll(): this;
502
- /**
503
- * Restore default projection.
504
- */
505
- selectDefault(): this;
506
- /**
507
- * Select distinct values.
508
- */
509
- distinctValues(fields?: string | string[]): this;
510
- /**
511
- * Add additional select fields.
512
- */
513
- addSelect(fields: string[]): this;
514
- /**
515
- * Order results.
516
- */
517
- orderBy(field: string, direction?: OrderDirection): this;
518
- orderBy(fields: Record<string, OrderDirection>): this;
519
- /**
520
- * Order descending.
521
- */
522
- orderByDesc(field: string): this;
523
- /**
524
- * Order with raw expression.
525
- */
526
- orderByRaw(expression: RawExpression, bindings?: unknown[]): this;
527
- /**
528
- * Order randomly.
529
- */
530
- orderByRandom(limit: number): this;
531
- /**
532
- * Get latest records.
533
- */
534
- latest(column?: string): Promise<T[]>;
535
- /**
536
- * Get oldest records.
537
- */
538
- oldest(column?: string): this;
539
- /**
540
- * Limit results.
541
- */
542
- limit(value: number): this;
543
- /**
544
- * Skip results.
545
- */
546
- skip(value: number): this;
547
- /**
548
- * Offset results.
549
- */
550
- offset(value: number): this;
551
- /**
552
- * Take first N results.
553
- */
554
- take(value: number): this;
555
- /**
556
- * Apply cursor pagination hints.
557
- */
558
- cursor(after?: unknown, before?: unknown): this;
559
- /**
560
- * Group results.
561
- */
562
- groupBy(input: GroupByInput): this;
563
- /**
564
- * Raw GROUP BY.
565
- */
566
- groupByRaw(expression: RawExpression, bindings?: unknown[]): this;
567
- /**
568
- * HAVING clause.
569
- */
570
- having(field: string, value: unknown): this;
571
- having(field: string, operator: WhereOperator, value: unknown): this;
572
- having(condition: HavingInput): this;
573
- /**
574
- * Raw HAVING clause.
123
+ * Load relations via SQL JOINs (single query) with optional per-relation constraints.
124
+ *
125
+ * Supports:
126
+ * - `joinWith("author")` / `joinWith(["author", "category"])`
127
+ * - `joinWith({ actions: q => q.where("status", "pending").limit(5) })`
128
+ * - `joinWith({ organizationAiModel: "id,name", actions: q => q.orderBy("sort_order") })`
129
+ *
130
+ * @example
131
+ * ChatMessage.joinWith({
132
+ * actions: q => q.where("status", "pending").orderBy("sort_order", "asc").limit(5),
133
+ * organizationAiModel: "id,createdAt",
134
+ * })
575
135
  */
576
- havingRaw(expression: RawExpression, bindings?: unknown[]): this;
136
+ joinWith(...args: unknown[]): this;
137
+ /** Run a joinWith constraint callback against a sub-QB and capture its operations. */
138
+ private _resolveConstraintOps;
577
139
  /**
578
- * Execute query and get all results.
140
+ * Execute the query and return all matching rows.
579
141
  */
580
142
  get<TResult = T>(): Promise<TResult[]>;
581
- /**
582
- * Apply JOIN operations for joinWith() relations.
583
- */
584
- private applyJoinRelations;
585
- /**
586
- * Extract joined relation data from raw records.
587
- * Returns a map of record index to relation data.
588
- */
589
- private extractJoinedRelationData;
590
- /**
591
- * Attach joined relations to hydrated models.
592
- */
593
- private attachJoinedRelations;
594
- /**
595
- * Get first result.
596
- */
143
+ /** Get first result. */
597
144
  first<TResult = T>(): Promise<TResult | null>;
598
- /**
599
- * Get last result.
600
- */
145
+ /** Get last result (by id desc). */
601
146
  last<TResult = T>(): Promise<TResult | null>;
602
- /**
603
- * Get random results.
604
- */
147
+ /** Get random results. */
605
148
  random<TResult = T>(limit?: number): Promise<TResult[]>;
606
- /**
607
- * Get first or throw.
608
- */
149
+ /** Get first or throw. */
609
150
  firstOrFail<TResult = T>(): Promise<TResult>;
610
- /**
611
- * Get first or call callback.
612
- */
151
+ /** Get first or call callback. */
613
152
  firstOr<TResult = T>(callback: () => TResult | Promise<TResult>): Promise<TResult>;
614
- /**
615
- * Get first or return default.
616
- */
153
+ /** Get first or return null. */
617
154
  firstOrNull<TResult = T>(): Promise<TResult | null>;
618
- /**
619
- * Get first or create new.
620
- */
155
+ /** Get first or return default. */
621
156
  firstOrNew<TResult = T>(defaults: GenericObject): Promise<TResult>;
622
- /**
623
- * Find by ID.
624
- */
157
+ /** Find by primary key. */
625
158
  find<TResult = T>(id: number | string): Promise<TResult | null>;
626
- /**
627
- * Count results.
628
- */
159
+ /** Count matching rows. */
629
160
  count(): Promise<number>;
630
- /**
631
- * Sum of field values.
632
- */
161
+ /** SUM a numeric field. */
633
162
  sum(field: string): Promise<number>;
634
- /**
635
- * Average of field values.
636
- */
163
+ /** AVG of a numeric field. */
637
164
  avg(field: string): Promise<number>;
638
- /**
639
- * Minimum field value.
640
- */
165
+ /** MIN of a numeric field. */
641
166
  min(field: string): Promise<number>;
642
- /**
643
- * Maximum field value.
644
- */
167
+ /** MAX of a numeric field. */
645
168
  max(field: string): Promise<number>;
646
- /**
647
- * Get distinct values.
648
- */
169
+ /** Get distinct values for a field. */
649
170
  distinct<TResult = unknown>(field: string): Promise<TResult[]>;
650
- /**
651
- * Get array of values for field.
652
- */
171
+ /** Get array of all values for a single field. */
653
172
  pluck(field: string): Promise<unknown[]>;
654
- /**
655
- * Get single scalar value.
656
- */
173
+ /** Get a single scalar value. */
657
174
  value<TResult = unknown>(field: string): Promise<TResult | null>;
658
- /**
659
- * Check if records exist.
660
- */
175
+ /** Check whether any matching rows exist. */
661
176
  exists(): Promise<boolean>;
662
- /**
663
- * Check if no records exist.
664
- */
177
+ /** Check whether NO matching rows exist. */
665
178
  notExists(): Promise<boolean>;
666
- /**
667
- * Count distinct values.
668
- */
179
+ /** COUNT DISTINCT a field. */
669
180
  countDistinct(field: string): Promise<number>;
670
- /**
671
- * Increment field value.
672
- */
181
+ /** Get latest records ordered by a column. */
182
+ latest(column?: string): Promise<T[]>;
183
+ /** Increment a numeric field. Returns new value. */
673
184
  increment(field: string, amount?: number): Promise<number>;
674
- /**
675
- * Decrement field value.
676
- */
185
+ /** Decrement a numeric field. Returns new value. */
677
186
  decrement(field: string, amount?: number): Promise<number>;
678
- /**
679
- * Increment for all matching.
680
- */
187
+ /** Increment a field for all matching rows. Returns affected row count. */
681
188
  incrementMany(field: string, amount?: number): Promise<number>;
682
- /**
683
- * Decrement for all matching.
684
- */
189
+ /** Decrement a field for all matching rows. Returns affected row count. */
685
190
  decrementMany(field: string, amount?: number): Promise<number>;
686
191
  /**
687
- * Process results in chunks.
192
+ * Process results in memory-efficient chunks.
193
+ *
194
+ * @example
195
+ * await User.query().chunk(100, async (rows, idx) => { ... })
688
196
  */
689
197
  chunk(size: number, callback: ChunkCallback<T>): Promise<void>;
690
- /**
691
- * Page-based pagination.
692
- */
198
+ /** Page-based pagination. */
693
199
  paginate(options?: PaginationOptions): Promise<PaginationResult<T>>;
694
200
  /**
695
- * Cursor-based pagination.
201
+ * Set cursor pagination hints fluently.
202
+ * The recorded values are picked up by `cursorPaginate()` when no explicit
203
+ * options are passed.
204
+ *
205
+ * @example
206
+ * User.query().cursor(lastId).cursorPaginate({ limit: 20 })
696
207
  */
208
+ cursor(after?: unknown, before?: unknown): this;
209
+ /** Cursor-based pagination. */
697
210
  cursorPaginate(options?: CursorPaginationOptions): Promise<CursorPaginationResult<T>>;
698
- /**
699
- * Delete matching records.
700
- */
211
+ /** Delete matching rows. Returns deleted count. */
701
212
  delete(): Promise<number>;
702
- /**
703
- * Delete first matching record.
704
- */
213
+ /** Delete the first matching row. */
705
214
  deleteOne(): Promise<number>;
706
- /**
707
- * Update matching records.
708
- */
215
+ /** Update matching rows. */
709
216
  update(fields: Record<string, unknown>): Promise<number>;
710
- /**
711
- * Unset fields from matching records.
712
- */
217
+ /** Unset fields from matching rows. */
713
218
  unset(...fields: string[]): Promise<number>;
714
- /**
715
- * Get the raw SQL query.
716
- */
717
- parse(): {
718
- sql: string;
719
- params: unknown[];
720
- };
721
- /**
722
- * Get formatted SQL string.
723
- */
219
+ /** Return the SQL + bindings without executing. */
220
+ parse(): DriverQuery;
221
+ /** Formatted SQL string (for logging/debugging). */
724
222
  pretty(): string;
725
- /**
726
- * Get query execution plan.
727
- */
223
+ /** Run EXPLAIN ANALYZE on the query. */
728
224
  explain(): Promise<unknown>;
729
- /**
730
- * Add driver-specific raw modifications to the query.
731
- */
732
- raw(builder: (native: unknown) => unknown): this;
733
- /**
734
- * Extend the query builder with driver-specific extensions.
735
- */
225
+ /** Extend the builder with a driver-specific extension. */
736
226
  extend<R>(extension: string, ..._args: unknown[]): R;
227
+ /** Pluck scalar values for a single field (alias for pluck). */
228
+ pluckOne<TResult = unknown>(field: string): Promise<TResult[]>;
737
229
  /**
738
- * Tap into the query builder for side-effects.
739
- */
740
- tap(callback: (builder: this) => void): this;
741
- /**
742
- * Conditionally apply query modifications.
743
- */
744
- when<V>(condition: V | boolean, callback: (builder: this, value: V) => void, otherwise?: (builder: this) => void): this;
745
- /**
746
- * Build WHERE clause from current operations.
747
- */
748
- private buildFilter;
749
- /**
750
- * Relations to eagerly load.
230
+ * Before `get()` runs the parser, consume any joinWith ops recorded by the base
231
+ * class and expand them into the joinRelations Map.
751
232
  */
752
- eagerLoadRelations: Map<string, boolean | ((query: QueryBuilderContract) => void)>;
233
+ private _processJoinWithOps;
753
234
  /**
754
- * Relations to count.
235
+ * Translate each entry in `joinRelations` into actual JOIN + selectRelatedColumns operations.
755
236
  */
756
- countRelations: string[];
757
- /**
758
- * Relations to load via JOIN (single query).
759
- */
760
- joinRelations: Map<string, {
761
- alias: string;
762
- type: "belongsTo" | "hasOne" | "hasMany";
763
- }>;
764
- /**
765
- * Relation definitions from the model.
766
- */
767
- relationDefinitions?: Record<string, any>;
768
- /**
769
- * Model class reference.
770
- */
771
- modelClass?: any;
772
- /**
773
- * Load relations using database JOINs in a single query.
774
- *
775
- * Unlike `with()` which uses separate queries, `joinWith()` uses
776
- * LEFT JOIN to fetch related data in a single query.
777
- *
778
- * @param relations - Relation names to load via JOIN
779
- * @returns This builder for chaining
780
- */
781
- joinWith(...relations: string[]): this;
782
- /**
783
- * Eagerly load one or more relations.
784
- *
785
- * Supported patterns:
786
- * - `with("posts")` - Load relation
787
- * - `with("posts", "comments")` - Load multiple relations
788
- * - `with("posts", callback)` - Load relation with constraint
789
- * - `with({ posts: true, comments: callback })` - Object configuration
790
- *
791
- * @param args - Relation name(s), callbacks, or configuration object
792
- */
793
- with(...args: (string | Record<string, boolean | ((query: QueryBuilderContract) => void)> | ((query: QueryBuilderContract) => void))[]): this;
794
- /**
795
- * Add a count of related models as a virtual field.
796
- * @param relations - Relation name(s) to count
797
- */
798
- withCount(...relations: string[]): this;
799
- /**
800
- * Filter results to only those that have related models.
801
- * @param relation - Relation name
802
- * @param operator - Optional comparison operator
803
- * @param count - Optional count to compare against
804
- */
805
- has(relation: string, operator?: string, count?: number): this;
237
+ private applyJoinRelations;
806
238
  /**
807
- * Filter results that have related models matching specific conditions.
808
- * @param relation - Relation name
809
- * @param callback - Callback to define conditions
239
+ * Extract per-relation data from raw DB rows (before hydration).
240
+ * Returns a Map of row index → nested relation data tree.
810
241
  */
811
- whereHas(relation: string, callback: (query: QueryBuilderContract) => void): this;
242
+ private extractJoinedRelationData;
812
243
  /**
813
- * Filter results that don't have any related models.
814
- * @param relation - Relation name
244
+ * Attach extracted relation data to hydrated model instances.
815
245
  */
816
- doesntHave(relation: string): this;
246
+ private attachJoinedRelations;
817
247
  /**
818
- * Filter results that don't have related models matching specific conditions.
819
- * @param relation - Relation name
820
- * @param callback - Callback to define conditions
248
+ * Build a WHERE-only SQL fragment from `where*` operations on the current builder.
249
+ * Used by DELETE / UPDATE / increment paths.
821
250
  */
822
- whereDoesntHave(relation: string, callback: (query: QueryBuilderContract) => void): this;
251
+ private buildFilter;
823
252
  }
253
+ export {};
824
254
  //# sourceMappingURL=postgres-query-builder.d.ts.map