drizzle-orm 0.40.0 → 1.0.0-beta.1-e30ede4

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 (735) hide show
  1. package/_relations.cjs +328 -0
  2. package/_relations.cjs.map +1 -0
  3. package/_relations.d.cts +215 -0
  4. package/_relations.d.ts +215 -0
  5. package/_relations.js +316 -0
  6. package/_relations.js.map +1 -0
  7. package/alias.cjs.map +1 -1
  8. package/alias.d.cts +3 -3
  9. package/alias.d.ts +3 -3
  10. package/alias.js.map +1 -1
  11. package/aws-data-api/pg/driver.cjs +19 -5
  12. package/aws-data-api/pg/driver.cjs.map +1 -1
  13. package/aws-data-api/pg/driver.d.cts +9 -8
  14. package/aws-data-api/pg/driver.d.ts +9 -8
  15. package/aws-data-api/pg/driver.js +9 -8
  16. package/aws-data-api/pg/driver.js.map +1 -1
  17. package/aws-data-api/pg/migrator.cjs.map +1 -1
  18. package/aws-data-api/pg/migrator.d.cts +2 -1
  19. package/aws-data-api/pg/migrator.d.ts +2 -1
  20. package/aws-data-api/pg/migrator.js.map +1 -1
  21. package/aws-data-api/pg/session.cjs +67 -4
  22. package/aws-data-api/pg/session.cjs.map +1 -1
  23. package/aws-data-api/pg/session.d.cts +13 -8
  24. package/aws-data-api/pg/session.d.ts +13 -8
  25. package/aws-data-api/pg/session.js +67 -4
  26. package/aws-data-api/pg/session.js.map +1 -1
  27. package/better-sqlite3/driver.cjs +12 -5
  28. package/better-sqlite3/driver.cjs.map +1 -1
  29. package/better-sqlite3/driver.d.cts +7 -6
  30. package/better-sqlite3/driver.d.ts +7 -6
  31. package/better-sqlite3/driver.js +12 -8
  32. package/better-sqlite3/driver.js.map +1 -1
  33. package/better-sqlite3/migrator.cjs.map +1 -1
  34. package/better-sqlite3/migrator.d.cts +2 -1
  35. package/better-sqlite3/migrator.d.ts +2 -1
  36. package/better-sqlite3/migrator.js.map +1 -1
  37. package/better-sqlite3/session.cjs +49 -4
  38. package/better-sqlite3/session.cjs.map +1 -1
  39. package/better-sqlite3/session.d.cts +14 -8
  40. package/better-sqlite3/session.d.ts +14 -8
  41. package/better-sqlite3/session.js +49 -4
  42. package/better-sqlite3/session.js.map +1 -1
  43. package/bun-sql/driver.cjs +16 -5
  44. package/bun-sql/driver.cjs.map +1 -1
  45. package/bun-sql/driver.d.cts +7 -6
  46. package/bun-sql/driver.d.ts +7 -6
  47. package/bun-sql/driver.js +6 -8
  48. package/bun-sql/driver.js.map +1 -1
  49. package/bun-sql/migrator.cjs.map +1 -1
  50. package/bun-sql/migrator.d.cts +2 -1
  51. package/bun-sql/migrator.d.ts +2 -1
  52. package/bun-sql/migrator.js.map +1 -1
  53. package/bun-sql/session.cjs +50 -6
  54. package/bun-sql/session.cjs.map +1 -1
  55. package/bun-sql/session.d.cts +14 -9
  56. package/bun-sql/session.d.ts +14 -9
  57. package/bun-sql/session.js +50 -6
  58. package/bun-sql/session.js.map +1 -1
  59. package/bun-sqlite/driver.cjs +22 -5
  60. package/bun-sqlite/driver.cjs.map +1 -1
  61. package/bun-sqlite/driver.d.cts +7 -6
  62. package/bun-sqlite/driver.d.ts +7 -6
  63. package/bun-sqlite/driver.js +12 -8
  64. package/bun-sqlite/driver.js.map +1 -1
  65. package/bun-sqlite/migrator.cjs.map +1 -1
  66. package/bun-sqlite/migrator.d.cts +2 -1
  67. package/bun-sqlite/migrator.d.ts +2 -1
  68. package/bun-sqlite/migrator.js.map +1 -1
  69. package/bun-sqlite/session.cjs +49 -4
  70. package/bun-sqlite/session.cjs.map +1 -1
  71. package/bun-sqlite/session.d.cts +14 -8
  72. package/bun-sqlite/session.d.ts +14 -8
  73. package/bun-sqlite/session.js +49 -4
  74. package/bun-sqlite/session.js.map +1 -1
  75. package/casing.cjs +3 -0
  76. package/casing.cjs.map +1 -1
  77. package/casing.d.cts +1 -1
  78. package/casing.d.ts +1 -1
  79. package/casing.js +4 -1
  80. package/casing.js.map +1 -1
  81. package/d1/driver.cjs +22 -5
  82. package/d1/driver.cjs.map +1 -1
  83. package/d1/driver.d.cts +3 -2
  84. package/d1/driver.d.ts +3 -2
  85. package/d1/driver.js +12 -8
  86. package/d1/driver.js.map +1 -1
  87. package/d1/migrator.cjs.map +1 -1
  88. package/d1/migrator.d.cts +2 -1
  89. package/d1/migrator.d.ts +2 -1
  90. package/d1/migrator.js.map +1 -1
  91. package/d1/session.cjs +50 -8
  92. package/d1/session.cjs.map +1 -1
  93. package/d1/session.d.cts +15 -8
  94. package/d1/session.d.ts +15 -8
  95. package/d1/session.js +50 -8
  96. package/d1/session.js.map +1 -1
  97. package/durable-sqlite/driver.cjs +16 -5
  98. package/durable-sqlite/driver.cjs.map +1 -1
  99. package/durable-sqlite/driver.d.cts +3 -2
  100. package/durable-sqlite/driver.d.ts +3 -2
  101. package/durable-sqlite/driver.js +6 -8
  102. package/durable-sqlite/driver.js.map +1 -1
  103. package/durable-sqlite/migrator.cjs.map +1 -1
  104. package/durable-sqlite/migrator.d.cts +2 -1
  105. package/durable-sqlite/migrator.d.ts +2 -1
  106. package/durable-sqlite/migrator.js.map +1 -1
  107. package/durable-sqlite/session.cjs +46 -4
  108. package/durable-sqlite/session.cjs.map +1 -1
  109. package/durable-sqlite/session.d.cts +14 -8
  110. package/durable-sqlite/session.d.ts +14 -8
  111. package/durable-sqlite/session.js +46 -4
  112. package/durable-sqlite/session.js.map +1 -1
  113. package/expo-sqlite/driver.cjs +22 -5
  114. package/expo-sqlite/driver.cjs.map +1 -1
  115. package/expo-sqlite/driver.d.cts +3 -2
  116. package/expo-sqlite/driver.d.ts +3 -2
  117. package/expo-sqlite/driver.js +12 -8
  118. package/expo-sqlite/driver.js.map +1 -1
  119. package/expo-sqlite/migrator.cjs.map +1 -1
  120. package/expo-sqlite/migrator.d.cts +3 -2
  121. package/expo-sqlite/migrator.d.ts +3 -2
  122. package/expo-sqlite/migrator.js.map +1 -1
  123. package/expo-sqlite/query.cjs +13 -2
  124. package/expo-sqlite/query.cjs.map +1 -1
  125. package/expo-sqlite/query.d.cts +2 -1
  126. package/expo-sqlite/query.d.ts +2 -1
  127. package/expo-sqlite/query.js +3 -2
  128. package/expo-sqlite/query.js.map +1 -1
  129. package/expo-sqlite/session.cjs +47 -4
  130. package/expo-sqlite/session.cjs.map +1 -1
  131. package/expo-sqlite/session.d.cts +14 -8
  132. package/expo-sqlite/session.d.ts +14 -8
  133. package/expo-sqlite/session.js +47 -4
  134. package/expo-sqlite/session.js.map +1 -1
  135. package/gel/driver.cjs +17 -6
  136. package/gel/driver.cjs.map +1 -1
  137. package/gel/driver.d.cts +8 -7
  138. package/gel/driver.d.ts +8 -7
  139. package/gel/driver.js +7 -9
  140. package/gel/driver.js.map +1 -1
  141. package/gel/migrator.cjs.map +1 -1
  142. package/gel/migrator.d.cts +1 -1
  143. package/gel/migrator.d.ts +1 -1
  144. package/gel/migrator.js.map +1 -1
  145. package/gel/session.cjs +46 -4
  146. package/gel/session.cjs.map +1 -1
  147. package/gel/session.d.cts +13 -8
  148. package/gel/session.d.ts +13 -8
  149. package/gel/session.js +46 -4
  150. package/gel/session.js.map +1 -1
  151. package/gel-core/columns/timestamptz.cjs +5 -0
  152. package/gel-core/columns/timestamptz.cjs.map +1 -1
  153. package/gel-core/columns/timestamptz.d.cts +1 -0
  154. package/gel-core/columns/timestamptz.d.ts +1 -0
  155. package/gel-core/columns/timestamptz.js +5 -0
  156. package/gel-core/columns/timestamptz.js.map +1 -1
  157. package/gel-core/db.cjs +28 -4
  158. package/gel-core/db.cjs.map +1 -1
  159. package/gel-core/db.d.cts +16 -9
  160. package/gel-core/db.d.ts +16 -9
  161. package/gel-core/db.js +27 -3
  162. package/gel-core/db.js.map +1 -1
  163. package/gel-core/dialect.cjs +172 -488
  164. package/gel-core/dialect.cjs.map +1 -1
  165. package/gel-core/dialect.d.cts +26 -8
  166. package/gel-core/dialect.d.ts +26 -8
  167. package/gel-core/dialect.js +170 -495
  168. package/gel-core/dialect.js.map +1 -1
  169. package/gel-core/query-builders/_query.cjs +149 -0
  170. package/gel-core/query-builders/_query.cjs.map +1 -0
  171. package/gel-core/query-builders/_query.d.cts +46 -0
  172. package/gel-core/query-builders/_query.d.ts +46 -0
  173. package/gel-core/query-builders/_query.js +114 -0
  174. package/gel-core/query-builders/_query.js.map +1 -0
  175. package/gel-core/query-builders/query.cjs +27 -24
  176. package/gel-core/query-builders/query.cjs.map +1 -1
  177. package/gel-core/query-builders/query.d.cts +9 -8
  178. package/gel-core/query-builders/query.d.ts +9 -8
  179. package/gel-core/query-builders/query.js +26 -23
  180. package/gel-core/query-builders/query.js.map +1 -1
  181. package/gel-core/session.cjs +3 -2
  182. package/gel-core/session.cjs.map +1 -1
  183. package/gel-core/session.d.cts +9 -6
  184. package/gel-core/session.d.ts +9 -6
  185. package/gel-core/session.js +3 -2
  186. package/gel-core/session.js.map +1 -1
  187. package/libsql/driver-core.cjs +22 -5
  188. package/libsql/driver-core.cjs.map +1 -1
  189. package/libsql/driver-core.d.cts +2 -1
  190. package/libsql/driver-core.d.ts +2 -1
  191. package/libsql/driver-core.js +12 -8
  192. package/libsql/driver-core.js.map +1 -1
  193. package/libsql/driver.cjs.map +1 -1
  194. package/libsql/driver.d.cts +6 -5
  195. package/libsql/driver.d.ts +6 -5
  196. package/libsql/driver.js.map +1 -1
  197. package/libsql/http/index.cjs.map +1 -1
  198. package/libsql/http/index.d.cts +6 -5
  199. package/libsql/http/index.d.ts +6 -5
  200. package/libsql/http/index.js.map +1 -1
  201. package/libsql/migrator.cjs.map +1 -1
  202. package/libsql/migrator.d.cts +2 -1
  203. package/libsql/migrator.d.ts +2 -1
  204. package/libsql/migrator.js.map +1 -1
  205. package/libsql/node/index.cjs.map +1 -1
  206. package/libsql/node/index.d.cts +6 -5
  207. package/libsql/node/index.d.ts +6 -5
  208. package/libsql/node/index.js.map +1 -1
  209. package/libsql/session.cjs +56 -4
  210. package/libsql/session.cjs.map +1 -1
  211. package/libsql/session.d.cts +15 -9
  212. package/libsql/session.d.ts +15 -9
  213. package/libsql/session.js +56 -4
  214. package/libsql/session.js.map +1 -1
  215. package/libsql/sqlite3/index.cjs.map +1 -1
  216. package/libsql/sqlite3/index.d.cts +6 -5
  217. package/libsql/sqlite3/index.d.ts +6 -5
  218. package/libsql/sqlite3/index.js.map +1 -1
  219. package/libsql/wasm/index.cjs.map +1 -1
  220. package/libsql/wasm/index.d.cts +6 -5
  221. package/libsql/wasm/index.d.ts +6 -5
  222. package/libsql/wasm/index.js.map +1 -1
  223. package/libsql/web/index.cjs.map +1 -1
  224. package/libsql/web/index.d.cts +6 -5
  225. package/libsql/web/index.d.ts +6 -5
  226. package/libsql/web/index.js.map +1 -1
  227. package/libsql/ws/index.cjs.map +1 -1
  228. package/libsql/ws/index.d.cts +6 -5
  229. package/libsql/ws/index.d.ts +6 -5
  230. package/libsql/ws/index.js.map +1 -1
  231. package/mysql-core/columns/binary.cjs +11 -0
  232. package/mysql-core/columns/binary.cjs.map +1 -1
  233. package/mysql-core/columns/binary.d.cts +1 -0
  234. package/mysql-core/columns/binary.d.ts +1 -0
  235. package/mysql-core/columns/binary.js +11 -0
  236. package/mysql-core/columns/binary.js.map +1 -1
  237. package/mysql-core/columns/decimal.cjs +5 -0
  238. package/mysql-core/columns/decimal.cjs.map +1 -1
  239. package/mysql-core/columns/decimal.d.cts +1 -0
  240. package/mysql-core/columns/decimal.d.ts +1 -0
  241. package/mysql-core/columns/decimal.js +5 -0
  242. package/mysql-core/columns/decimal.js.map +1 -1
  243. package/mysql-core/columns/float.cjs +6 -0
  244. package/mysql-core/columns/float.cjs.map +1 -1
  245. package/mysql-core/columns/float.d.cts +1 -0
  246. package/mysql-core/columns/float.d.ts +1 -0
  247. package/mysql-core/columns/float.js +6 -0
  248. package/mysql-core/columns/float.js.map +1 -1
  249. package/mysql-core/columns/varbinary.cjs +11 -0
  250. package/mysql-core/columns/varbinary.cjs.map +1 -1
  251. package/mysql-core/columns/varbinary.d.cts +1 -0
  252. package/mysql-core/columns/varbinary.d.ts +1 -0
  253. package/mysql-core/columns/varbinary.js +11 -0
  254. package/mysql-core/columns/varbinary.js.map +1 -1
  255. package/mysql-core/columns/varchar.cjs.map +1 -1
  256. package/mysql-core/columns/varchar.d.cts +1 -1
  257. package/mysql-core/columns/varchar.d.ts +1 -1
  258. package/mysql-core/columns/varchar.js.map +1 -1
  259. package/mysql-core/db.cjs +30 -6
  260. package/mysql-core/db.cjs.map +1 -1
  261. package/mysql-core/db.d.cts +15 -8
  262. package/mysql-core/db.d.ts +15 -8
  263. package/mysql-core/db.js +29 -5
  264. package/mysql-core/db.js.map +1 -1
  265. package/mysql-core/dialect.cjs +208 -15
  266. package/mysql-core/dialect.cjs.map +1 -1
  267. package/mysql-core/dialect.d.cts +36 -13
  268. package/mysql-core/dialect.d.ts +36 -13
  269. package/mysql-core/dialect.js +206 -22
  270. package/mysql-core/dialect.js.map +1 -1
  271. package/mysql-core/query-builders/_query.cjs +149 -0
  272. package/mysql-core/query-builders/_query.cjs.map +1 -0
  273. package/mysql-core/query-builders/_query.d.cts +44 -0
  274. package/mysql-core/query-builders/_query.d.ts +44 -0
  275. package/mysql-core/query-builders/_query.js +114 -0
  276. package/mysql-core/query-builders/_query.js.map +1 -0
  277. package/mysql-core/query-builders/count.cjs.map +1 -1
  278. package/mysql-core/query-builders/count.d.cts +1 -1
  279. package/mysql-core/query-builders/count.d.ts +1 -1
  280. package/mysql-core/query-builders/count.js.map +1 -1
  281. package/mysql-core/query-builders/query.cjs +18 -31
  282. package/mysql-core/query-builders/query.cjs.map +1 -1
  283. package/mysql-core/query-builders/query.d.cts +8 -10
  284. package/mysql-core/query-builders/query.d.ts +8 -10
  285. package/mysql-core/query-builders/query.js +18 -31
  286. package/mysql-core/query-builders/query.js.map +1 -1
  287. package/mysql-core/session.cjs +3 -2
  288. package/mysql-core/session.cjs.map +1 -1
  289. package/mysql-core/session.d.cts +10 -7
  290. package/mysql-core/session.d.ts +10 -7
  291. package/mysql-core/session.js +3 -2
  292. package/mysql-core/session.js.map +1 -1
  293. package/mysql-proxy/driver.cjs +22 -5
  294. package/mysql-proxy/driver.cjs.map +1 -1
  295. package/mysql-proxy/driver.d.cts +3 -2
  296. package/mysql-proxy/driver.d.ts +3 -2
  297. package/mysql-proxy/driver.js +12 -8
  298. package/mysql-proxy/driver.js.map +1 -1
  299. package/mysql-proxy/migrator.cjs.map +1 -1
  300. package/mysql-proxy/migrator.d.cts +2 -1
  301. package/mysql-proxy/migrator.d.ts +2 -1
  302. package/mysql-proxy/migrator.js.map +1 -1
  303. package/mysql-proxy/session.cjs +27 -2
  304. package/mysql-proxy/session.cjs.map +1 -1
  305. package/mysql-proxy/session.d.cts +13 -8
  306. package/mysql-proxy/session.d.ts +13 -8
  307. package/mysql-proxy/session.js +27 -2
  308. package/mysql-proxy/session.js.map +1 -1
  309. package/mysql2/driver.cjs +24 -7
  310. package/mysql2/driver.cjs.map +1 -1
  311. package/mysql2/driver.d.cts +10 -9
  312. package/mysql2/driver.d.ts +10 -9
  313. package/mysql2/driver.js +14 -10
  314. package/mysql2/driver.js.map +1 -1
  315. package/mysql2/migrator.cjs.map +1 -1
  316. package/mysql2/migrator.d.cts +2 -1
  317. package/mysql2/migrator.d.ts +2 -1
  318. package/mysql2/migrator.js.map +1 -1
  319. package/mysql2/session.cjs +30 -2
  320. package/mysql2/session.cjs.map +1 -1
  321. package/mysql2/session.d.cts +13 -8
  322. package/mysql2/session.d.ts +13 -8
  323. package/mysql2/session.js +30 -2
  324. package/mysql2/session.js.map +1 -1
  325. package/neon-http/driver.cjs +21 -7
  326. package/neon-http/driver.cjs.map +1 -1
  327. package/neon-http/driver.d.cts +10 -9
  328. package/neon-http/driver.d.ts +10 -9
  329. package/neon-http/driver.js +11 -7
  330. package/neon-http/driver.js.map +1 -1
  331. package/neon-http/migrator.cjs.map +1 -1
  332. package/neon-http/migrator.d.cts +2 -1
  333. package/neon-http/migrator.d.ts +2 -1
  334. package/neon-http/migrator.js.map +1 -1
  335. package/neon-http/session.cjs +32 -2
  336. package/neon-http/session.cjs.map +1 -1
  337. package/neon-http/session.d.cts +13 -8
  338. package/neon-http/session.d.ts +13 -8
  339. package/neon-http/session.js +32 -2
  340. package/neon-http/session.js.map +1 -1
  341. package/neon-serverless/driver.cjs +18 -7
  342. package/neon-serverless/driver.cjs.map +1 -1
  343. package/neon-serverless/driver.d.cts +9 -8
  344. package/neon-serverless/driver.d.ts +9 -8
  345. package/neon-serverless/driver.js +8 -10
  346. package/neon-serverless/driver.js.map +1 -1
  347. package/neon-serverless/migrator.cjs.map +1 -1
  348. package/neon-serverless/migrator.d.cts +2 -1
  349. package/neon-serverless/migrator.d.ts +2 -1
  350. package/neon-serverless/migrator.js.map +1 -1
  351. package/neon-serverless/session.cjs +64 -5
  352. package/neon-serverless/session.cjs.map +1 -1
  353. package/neon-serverless/session.d.cts +13 -8
  354. package/neon-serverless/session.d.ts +13 -8
  355. package/neon-serverless/session.js +64 -5
  356. package/neon-serverless/session.js.map +1 -1
  357. package/node-postgres/driver.cjs +13 -7
  358. package/node-postgres/driver.cjs.map +1 -1
  359. package/node-postgres/driver.d.cts +9 -8
  360. package/node-postgres/driver.d.ts +9 -8
  361. package/node-postgres/driver.js +13 -10
  362. package/node-postgres/driver.js.map +1 -1
  363. package/node-postgres/migrator.cjs.map +1 -1
  364. package/node-postgres/migrator.d.cts +2 -1
  365. package/node-postgres/migrator.d.ts +2 -1
  366. package/node-postgres/migrator.js.map +1 -1
  367. package/node-postgres/session.cjs +69 -4
  368. package/node-postgres/session.cjs.map +1 -1
  369. package/node-postgres/session.d.cts +13 -8
  370. package/node-postgres/session.d.ts +13 -8
  371. package/node-postgres/session.js +69 -4
  372. package/node-postgres/session.js.map +1 -1
  373. package/op-sqlite/driver.cjs +22 -5
  374. package/op-sqlite/driver.cjs.map +1 -1
  375. package/op-sqlite/driver.d.cts +3 -2
  376. package/op-sqlite/driver.d.ts +3 -2
  377. package/op-sqlite/driver.js +12 -8
  378. package/op-sqlite/driver.js.map +1 -1
  379. package/op-sqlite/migrator.cjs.map +1 -1
  380. package/op-sqlite/migrator.d.cts +3 -2
  381. package/op-sqlite/migrator.d.ts +3 -2
  382. package/op-sqlite/migrator.js.map +1 -1
  383. package/op-sqlite/session.cjs +47 -4
  384. package/op-sqlite/session.cjs.map +1 -1
  385. package/op-sqlite/session.d.cts +14 -8
  386. package/op-sqlite/session.d.ts +14 -8
  387. package/op-sqlite/session.js +47 -4
  388. package/op-sqlite/session.js.map +1 -1
  389. package/package.json +63 -3
  390. package/pg-core/columns/numeric.cjs +5 -0
  391. package/pg-core/columns/numeric.cjs.map +1 -1
  392. package/pg-core/columns/numeric.d.cts +1 -0
  393. package/pg-core/columns/numeric.d.ts +1 -0
  394. package/pg-core/columns/numeric.js +5 -0
  395. package/pg-core/columns/numeric.js.map +1 -1
  396. package/pg-core/columns/postgis_extension/geometry.cjs +2 -0
  397. package/pg-core/columns/postgis_extension/geometry.cjs.map +1 -1
  398. package/pg-core/columns/postgis_extension/geometry.d.cts +1 -1
  399. package/pg-core/columns/postgis_extension/geometry.d.ts +1 -1
  400. package/pg-core/columns/postgis_extension/geometry.js +2 -0
  401. package/pg-core/columns/postgis_extension/geometry.js.map +1 -1
  402. package/pg-core/db.cjs +32 -5
  403. package/pg-core/db.cjs.map +1 -1
  404. package/pg-core/db.d.cts +16 -9
  405. package/pg-core/db.d.ts +16 -9
  406. package/pg-core/db.js +31 -4
  407. package/pg-core/db.js.map +1 -1
  408. package/pg-core/dialect.cjs +190 -488
  409. package/pg-core/dialect.cjs.map +1 -1
  410. package/pg-core/dialect.d.cts +27 -8
  411. package/pg-core/dialect.d.ts +27 -8
  412. package/pg-core/dialect.js +189 -495
  413. package/pg-core/dialect.js.map +1 -1
  414. package/pg-core/query-builders/_query.cjs +155 -0
  415. package/pg-core/query-builders/_query.cjs.map +1 -0
  416. package/pg-core/query-builders/_query.d.cts +47 -0
  417. package/pg-core/query-builders/_query.d.ts +47 -0
  418. package/pg-core/query-builders/_query.js +120 -0
  419. package/pg-core/query-builders/_query.js.map +1 -0
  420. package/pg-core/query-builders/count.cjs.map +1 -1
  421. package/pg-core/query-builders/count.d.cts +1 -1
  422. package/pg-core/query-builders/count.d.ts +1 -1
  423. package/pg-core/query-builders/count.js.map +1 -1
  424. package/pg-core/query-builders/query.cjs +15 -18
  425. package/pg-core/query-builders/query.cjs.map +1 -1
  426. package/pg-core/query-builders/query.d.cts +6 -6
  427. package/pg-core/query-builders/query.d.ts +6 -6
  428. package/pg-core/query-builders/query.js +15 -18
  429. package/pg-core/query-builders/query.js.map +1 -1
  430. package/pg-core/session.cjs +3 -2
  431. package/pg-core/session.cjs.map +1 -1
  432. package/pg-core/session.d.cts +9 -6
  433. package/pg-core/session.d.ts +9 -6
  434. package/pg-core/session.js +3 -2
  435. package/pg-core/session.js.map +1 -1
  436. package/pg-proxy/driver.cjs +21 -5
  437. package/pg-proxy/driver.cjs.map +1 -1
  438. package/pg-proxy/driver.d.cts +3 -2
  439. package/pg-proxy/driver.d.ts +3 -2
  440. package/pg-proxy/driver.js +11 -8
  441. package/pg-proxy/driver.js.map +1 -1
  442. package/pg-proxy/migrator.cjs.map +1 -1
  443. package/pg-proxy/migrator.d.cts +2 -1
  444. package/pg-proxy/migrator.d.ts +2 -1
  445. package/pg-proxy/migrator.js.map +1 -1
  446. package/pg-proxy/session.cjs +37 -2
  447. package/pg-proxy/session.cjs.map +1 -1
  448. package/pg-proxy/session.d.cts +13 -8
  449. package/pg-proxy/session.d.ts +13 -8
  450. package/pg-proxy/session.js +37 -2
  451. package/pg-proxy/session.js.map +1 -1
  452. package/pglite/driver.cjs +23 -7
  453. package/pglite/driver.cjs.map +1 -1
  454. package/pglite/driver.d.cts +9 -8
  455. package/pglite/driver.d.ts +9 -8
  456. package/pglite/driver.js +13 -10
  457. package/pglite/driver.js.map +1 -1
  458. package/pglite/migrator.cjs.map +1 -1
  459. package/pglite/migrator.d.cts +2 -1
  460. package/pglite/migrator.d.ts +2 -1
  461. package/pglite/migrator.js.map +1 -1
  462. package/pglite/session.cjs +48 -5
  463. package/pglite/session.cjs.map +1 -1
  464. package/pglite/session.d.cts +13 -8
  465. package/pglite/session.d.ts +13 -8
  466. package/pglite/session.js +48 -5
  467. package/pglite/session.js.map +1 -1
  468. package/planetscale-serverless/driver.cjs +22 -5
  469. package/planetscale-serverless/driver.cjs.map +1 -1
  470. package/planetscale-serverless/driver.d.cts +7 -6
  471. package/planetscale-serverless/driver.d.ts +7 -6
  472. package/planetscale-serverless/driver.js +12 -8
  473. package/planetscale-serverless/driver.js.map +1 -1
  474. package/planetscale-serverless/migrator.cjs.map +1 -1
  475. package/planetscale-serverless/migrator.d.cts +2 -1
  476. package/planetscale-serverless/migrator.d.ts +2 -1
  477. package/planetscale-serverless/migrator.js.map +1 -1
  478. package/planetscale-serverless/session.cjs +45 -5
  479. package/planetscale-serverless/session.cjs.map +1 -1
  480. package/planetscale-serverless/session.d.cts +14 -9
  481. package/planetscale-serverless/session.d.ts +14 -9
  482. package/planetscale-serverless/session.js +45 -5
  483. package/planetscale-serverless/session.js.map +1 -1
  484. package/postgres-js/driver.cjs +7 -6
  485. package/postgres-js/driver.cjs.map +1 -1
  486. package/postgres-js/driver.d.cts +7 -6
  487. package/postgres-js/driver.d.ts +7 -6
  488. package/postgres-js/driver.js +7 -9
  489. package/postgres-js/driver.js.map +1 -1
  490. package/postgres-js/migrator.cjs.map +1 -1
  491. package/postgres-js/migrator.d.cts +2 -1
  492. package/postgres-js/migrator.d.ts +2 -1
  493. package/postgres-js/migrator.js.map +1 -1
  494. package/postgres-js/session.cjs +51 -6
  495. package/postgres-js/session.cjs.map +1 -1
  496. package/postgres-js/session.d.cts +15 -9
  497. package/postgres-js/session.d.ts +15 -9
  498. package/postgres-js/session.js +51 -6
  499. package/postgres-js/session.js.map +1 -1
  500. package/prisma/mysql/driver.cjs +1 -1
  501. package/prisma/mysql/driver.cjs.map +1 -1
  502. package/prisma/mysql/driver.js +1 -1
  503. package/prisma/mysql/driver.js.map +1 -1
  504. package/prisma/mysql/session.cjs +3 -0
  505. package/prisma/mysql/session.cjs.map +1 -1
  506. package/prisma/mysql/session.d.cts +3 -1
  507. package/prisma/mysql/session.d.ts +3 -1
  508. package/prisma/mysql/session.js +3 -0
  509. package/prisma/mysql/session.js.map +1 -1
  510. package/prisma/pg/driver.cjs +1 -1
  511. package/prisma/pg/driver.cjs.map +1 -1
  512. package/prisma/pg/driver.js +1 -1
  513. package/prisma/pg/driver.js.map +1 -1
  514. package/prisma/pg/session.cjs +3 -0
  515. package/prisma/pg/session.cjs.map +1 -1
  516. package/prisma/pg/session.d.cts +3 -1
  517. package/prisma/pg/session.d.ts +3 -1
  518. package/prisma/pg/session.js +3 -0
  519. package/prisma/pg/session.js.map +1 -1
  520. package/prisma/sqlite/driver.cjs +1 -1
  521. package/prisma/sqlite/driver.cjs.map +1 -1
  522. package/prisma/sqlite/driver.js +1 -1
  523. package/prisma/sqlite/driver.js.map +1 -1
  524. package/prisma/sqlite/session.cjs +3 -0
  525. package/prisma/sqlite/session.cjs.map +1 -1
  526. package/prisma/sqlite/session.d.cts +4 -2
  527. package/prisma/sqlite/session.d.ts +4 -2
  528. package/prisma/sqlite/session.js +3 -0
  529. package/prisma/sqlite/session.js.map +1 -1
  530. package/relations.cjs +657 -245
  531. package/relations.cjs.map +1 -1
  532. package/relations.d.cts +339 -140
  533. package/relations.d.ts +339 -140
  534. package/relations.js +643 -240
  535. package/relations.js.map +1 -1
  536. package/singlestore/driver.cjs +1 -1
  537. package/singlestore/driver.cjs.map +1 -1
  538. package/singlestore/driver.d.cts +1 -1
  539. package/singlestore/driver.d.ts +1 -1
  540. package/singlestore/driver.js +3 -3
  541. package/singlestore/driver.js.map +1 -1
  542. package/singlestore/session.cjs.map +1 -1
  543. package/singlestore/session.d.cts +4 -4
  544. package/singlestore/session.d.ts +4 -4
  545. package/singlestore/session.js.map +1 -1
  546. package/singlestore-core/db.cjs.map +1 -1
  547. package/singlestore-core/db.d.cts +3 -3
  548. package/singlestore-core/db.d.ts +3 -3
  549. package/singlestore-core/db.js.map +1 -1
  550. package/singlestore-core/dialect.cjs +16 -6
  551. package/singlestore-core/dialect.cjs.map +1 -1
  552. package/singlestore-core/dialect.d.cts +6 -6
  553. package/singlestore-core/dialect.d.ts +6 -6
  554. package/singlestore-core/dialect.js +6 -12
  555. package/singlestore-core/dialect.js.map +1 -1
  556. package/singlestore-core/query-builders/query.cjs +12 -2
  557. package/singlestore-core/query-builders/query.cjs.map +1 -1
  558. package/singlestore-core/query-builders/query.d.cts +6 -6
  559. package/singlestore-core/query-builders/query.d.ts +6 -6
  560. package/singlestore-core/query-builders/query.js +2 -4
  561. package/singlestore-core/query-builders/query.js.map +1 -1
  562. package/singlestore-core/session.cjs.map +1 -1
  563. package/singlestore-core/session.d.cts +5 -5
  564. package/singlestore-core/session.d.ts +5 -5
  565. package/singlestore-core/session.js.map +1 -1
  566. package/singlestore-proxy/driver.cjs +1 -1
  567. package/singlestore-proxy/driver.cjs.map +1 -1
  568. package/singlestore-proxy/driver.js +3 -3
  569. package/singlestore-proxy/driver.js.map +1 -1
  570. package/singlestore-proxy/session.cjs.map +1 -1
  571. package/singlestore-proxy/session.d.cts +4 -4
  572. package/singlestore-proxy/session.d.ts +4 -4
  573. package/singlestore-proxy/session.js.map +1 -1
  574. package/sql/expressions/conditions.cjs.map +1 -1
  575. package/sql/expressions/conditions.d.cts +4 -4
  576. package/sql/expressions/conditions.d.ts +4 -4
  577. package/sql/expressions/conditions.js.map +1 -1
  578. package/sql/sql.cjs +21 -0
  579. package/sql/sql.cjs.map +1 -1
  580. package/sql/sql.d.cts +8 -8
  581. package/sql/sql.d.ts +8 -8
  582. package/sql/sql.js +22 -1
  583. package/sql/sql.js.map +1 -1
  584. package/sql-js/driver.cjs +16 -5
  585. package/sql-js/driver.cjs.map +1 -1
  586. package/sql-js/driver.d.cts +3 -2
  587. package/sql-js/driver.d.ts +3 -2
  588. package/sql-js/driver.js +6 -8
  589. package/sql-js/driver.js.map +1 -1
  590. package/sql-js/migrator.cjs.map +1 -1
  591. package/sql-js/migrator.d.cts +2 -1
  592. package/sql-js/migrator.d.ts +2 -1
  593. package/sql-js/migrator.js.map +1 -1
  594. package/sql-js/session.cjs +71 -36
  595. package/sql-js/session.cjs.map +1 -1
  596. package/sql-js/session.d.cts +16 -13
  597. package/sql-js/session.d.ts +16 -13
  598. package/sql-js/session.js +71 -36
  599. package/sql-js/session.js.map +1 -1
  600. package/sqlite-core/columns/blob.cjs +12 -0
  601. package/sqlite-core/columns/blob.cjs.map +1 -1
  602. package/sqlite-core/columns/blob.d.cts +2 -1
  603. package/sqlite-core/columns/blob.d.ts +2 -1
  604. package/sqlite-core/columns/blob.js +12 -0
  605. package/sqlite-core/columns/blob.js.map +1 -1
  606. package/sqlite-core/db.cjs +39 -12
  607. package/sqlite-core/db.cjs.map +1 -1
  608. package/sqlite-core/db.d.cts +16 -8
  609. package/sqlite-core/db.d.ts +16 -8
  610. package/sqlite-core/db.js +38 -11
  611. package/sqlite-core/db.js.map +1 -1
  612. package/sqlite-core/dialect.cjs +193 -7
  613. package/sqlite-core/dialect.cjs.map +1 -1
  614. package/sqlite-core/dialect.d.cts +31 -9
  615. package/sqlite-core/dialect.d.ts +31 -9
  616. package/sqlite-core/dialect.js +191 -14
  617. package/sqlite-core/dialect.js.map +1 -1
  618. package/sqlite-core/query-builders/_query.cjs +187 -0
  619. package/sqlite-core/query-builders/_query.cjs.map +1 -0
  620. package/sqlite-core/query-builders/_query.d.cts +55 -0
  621. package/sqlite-core/query-builders/_query.d.ts +55 -0
  622. package/sqlite-core/query-builders/_query.js +151 -0
  623. package/sqlite-core/query-builders/_query.js.map +1 -0
  624. package/sqlite-core/query-builders/count.cjs.map +1 -1
  625. package/sqlite-core/query-builders/count.d.cts +1 -1
  626. package/sqlite-core/query-builders/count.d.ts +1 -1
  627. package/sqlite-core/query-builders/count.js.map +1 -1
  628. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  629. package/sqlite-core/query-builders/delete.d.cts +1 -1
  630. package/sqlite-core/query-builders/delete.d.ts +1 -1
  631. package/sqlite-core/query-builders/delete.js.map +1 -1
  632. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  633. package/sqlite-core/query-builders/insert.d.cts +3 -3
  634. package/sqlite-core/query-builders/insert.d.ts +3 -3
  635. package/sqlite-core/query-builders/insert.js.map +1 -1
  636. package/sqlite-core/query-builders/query.cjs +56 -35
  637. package/sqlite-core/query-builders/query.cjs.map +1 -1
  638. package/sqlite-core/query-builders/query.d.cts +18 -17
  639. package/sqlite-core/query-builders/query.d.ts +18 -17
  640. package/sqlite-core/query-builders/query.js +56 -35
  641. package/sqlite-core/query-builders/query.js.map +1 -1
  642. package/sqlite-core/query-builders/select.cjs.map +1 -1
  643. package/sqlite-core/query-builders/select.d.cts +3 -3
  644. package/sqlite-core/query-builders/select.d.ts +3 -3
  645. package/sqlite-core/query-builders/select.js.map +1 -1
  646. package/sqlite-core/query-builders/update.cjs.map +1 -1
  647. package/sqlite-core/query-builders/update.d.cts +3 -3
  648. package/sqlite-core/query-builders/update.d.ts +3 -3
  649. package/sqlite-core/query-builders/update.js.map +1 -1
  650. package/sqlite-core/session.cjs +6 -2
  651. package/sqlite-core/session.cjs.map +1 -1
  652. package/sqlite-core/session.d.cts +15 -7
  653. package/sqlite-core/session.d.ts +15 -7
  654. package/sqlite-core/session.js +6 -2
  655. package/sqlite-core/session.js.map +1 -1
  656. package/sqlite-proxy/driver.cjs +23 -5
  657. package/sqlite-proxy/driver.cjs.map +1 -1
  658. package/sqlite-proxy/driver.d.cts +4 -3
  659. package/sqlite-proxy/driver.d.ts +4 -3
  660. package/sqlite-proxy/driver.js +13 -5
  661. package/sqlite-proxy/driver.js.map +1 -1
  662. package/sqlite-proxy/migrator.cjs.map +1 -1
  663. package/sqlite-proxy/migrator.d.cts +2 -1
  664. package/sqlite-proxy/migrator.d.ts +2 -1
  665. package/sqlite-proxy/migrator.js.map +1 -1
  666. package/sqlite-proxy/session.cjs +50 -6
  667. package/sqlite-proxy/session.cjs.map +1 -1
  668. package/sqlite-proxy/session.d.cts +14 -8
  669. package/sqlite-proxy/session.d.ts +14 -8
  670. package/sqlite-proxy/session.js +50 -6
  671. package/sqlite-proxy/session.js.map +1 -1
  672. package/table.cjs.map +1 -1
  673. package/table.d.cts +2 -2
  674. package/table.d.ts +2 -2
  675. package/table.js.map +1 -1
  676. package/tidb-serverless/driver.cjs +22 -5
  677. package/tidb-serverless/driver.cjs.map +1 -1
  678. package/tidb-serverless/driver.d.cts +7 -6
  679. package/tidb-serverless/driver.d.ts +7 -6
  680. package/tidb-serverless/driver.js +12 -8
  681. package/tidb-serverless/driver.js.map +1 -1
  682. package/tidb-serverless/migrator.cjs.map +1 -1
  683. package/tidb-serverless/migrator.d.cts +2 -1
  684. package/tidb-serverless/migrator.d.ts +2 -1
  685. package/tidb-serverless/migrator.js.map +1 -1
  686. package/tidb-serverless/session.cjs +62 -5
  687. package/tidb-serverless/session.cjs.map +1 -1
  688. package/tidb-serverless/session.d.cts +14 -9
  689. package/tidb-serverless/session.d.ts +14 -9
  690. package/tidb-serverless/session.js +62 -5
  691. package/tidb-serverless/session.js.map +1 -1
  692. package/utils.cjs +2 -2
  693. package/utils.cjs.map +1 -1
  694. package/utils.d.cts +3 -1
  695. package/utils.d.ts +3 -1
  696. package/utils.js +2 -2
  697. package/utils.js.map +1 -1
  698. package/vercel-postgres/driver.cjs +23 -7
  699. package/vercel-postgres/driver.cjs.map +1 -1
  700. package/vercel-postgres/driver.d.cts +9 -8
  701. package/vercel-postgres/driver.d.ts +9 -8
  702. package/vercel-postgres/driver.js +13 -10
  703. package/vercel-postgres/driver.js.map +1 -1
  704. package/vercel-postgres/migrator.cjs.map +1 -1
  705. package/vercel-postgres/migrator.d.cts +2 -1
  706. package/vercel-postgres/migrator.d.ts +2 -1
  707. package/vercel-postgres/migrator.js.map +1 -1
  708. package/vercel-postgres/session.cjs +58 -4
  709. package/vercel-postgres/session.cjs.map +1 -1
  710. package/vercel-postgres/session.d.cts +13 -8
  711. package/vercel-postgres/session.d.ts +13 -8
  712. package/vercel-postgres/session.js +58 -4
  713. package/vercel-postgres/session.js.map +1 -1
  714. package/version.cjs +2 -2
  715. package/version.cjs.map +1 -1
  716. package/version.d.cts +2 -2
  717. package/version.d.ts +2 -2
  718. package/version.js +2 -2
  719. package/version.js.map +1 -1
  720. package/xata-http/driver.cjs +17 -5
  721. package/xata-http/driver.cjs.map +1 -1
  722. package/xata-http/driver.d.cts +5 -4
  723. package/xata-http/driver.d.ts +5 -4
  724. package/xata-http/driver.js +7 -5
  725. package/xata-http/driver.js.map +1 -1
  726. package/xata-http/migrator.cjs.map +1 -1
  727. package/xata-http/migrator.d.cts +2 -1
  728. package/xata-http/migrator.d.ts +2 -1
  729. package/xata-http/migrator.js.map +1 -1
  730. package/xata-http/session.cjs +30 -2
  731. package/xata-http/session.cjs.map +1 -1
  732. package/xata-http/session.d.cts +13 -8
  733. package/xata-http/session.d.ts +13 -8
  734. package/xata-http/session.js +30 -2
  735. package/xata-http/session.js.map +1 -1
@@ -1,9 +1,11 @@
1
+ import * as V1 from "../_relations.js";
1
2
  import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from "../alias.js";
2
3
  import { CasingCache } from "../casing.js";
3
4
  import { Column } from "../column.js";
4
5
  import { entityKind, is } from "../entity.js";
5
6
  import { DrizzleError } from "../errors.js";
6
7
  import {
8
+ PgArray,
7
9
  PgColumn,
8
10
  PgDate,
9
11
  PgDateString,
@@ -17,20 +19,21 @@ import {
17
19
  } from "./columns/index.js";
18
20
  import { PgTable } from "./table.js";
19
21
  import {
20
- getOperators,
21
- getOrderByOperators,
22
- Many,
23
- normalizeRelation,
24
- One
22
+ getTableAsAliasSQL,
23
+ One,
24
+ relationExtrasToSQL,
25
+ relationsFilterToSQL,
26
+ relationsOrderToSQL,
27
+ relationToSQL
25
28
  } from "../relations.js";
26
- import { and, eq, View } from "../sql/index.js";
29
+ import { and, eq, isSQLWrapper, View } from "../sql/index.js";
27
30
  import {
28
31
  Param,
29
32
  SQL,
30
33
  sql
31
34
  } from "../sql/sql.js";
32
35
  import { Subquery } from "../subquery.js";
33
- import { getTableName, getTableUniqueName, Table } from "../table.js";
36
+ import { Columns, getTableName, getTableUniqueName, Table } from "../table.js";
34
37
  import { orderSelectedFields } from "../utils.js";
35
38
  import { ViewBaseConfig } from "../view-common.js";
36
39
  import { PgViewBase } from "./view-base.js";
@@ -424,488 +427,8 @@ class PgDialect {
424
427
  invokeSource
425
428
  });
426
429
  }
427
- // buildRelationalQueryWithPK({
428
- // fullSchema,
429
- // schema,
430
- // tableNamesMap,
431
- // table,
432
- // tableConfig,
433
- // queryConfig: config,
434
- // tableAlias,
435
- // isRoot = false,
436
- // joinOn,
437
- // }: {
438
- // fullSchema: Record<string, unknown>;
439
- // schema: TablesRelationalConfig;
440
- // tableNamesMap: Record<string, string>;
441
- // table: PgTable;
442
- // tableConfig: TableRelationalConfig;
443
- // queryConfig: true | DBQueryConfig<'many', true>;
444
- // tableAlias: string;
445
- // isRoot?: boolean;
446
- // joinOn?: SQL;
447
- // }): BuildRelationalQueryResult<PgTable, PgColumn> {
448
- // // For { "<relation>": true }, return a table with selection of all columns
449
- // if (config === true) {
450
- // const selectionEntries = Object.entries(tableConfig.columns);
451
- // const selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = selectionEntries.map((
452
- // [key, value],
453
- // ) => ({
454
- // dbKey: value.name,
455
- // tsKey: key,
456
- // field: value as PgColumn,
457
- // relationTableTsKey: undefined,
458
- // isJson: false,
459
- // selection: [],
460
- // }));
461
- // return {
462
- // tableTsKey: tableConfig.tsName,
463
- // sql: table,
464
- // selection,
465
- // };
466
- // }
467
- // // let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
468
- // // let selectionForBuild = selection;
469
- // const aliasedColumns = Object.fromEntries(
470
- // Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),
471
- // );
472
- // const aliasedRelations = Object.fromEntries(
473
- // Object.entries(tableConfig.relations).map(([key, value]) => [key, aliasedRelation(value, tableAlias)]),
474
- // );
475
- // const aliasedFields = Object.assign({}, aliasedColumns, aliasedRelations);
476
- // let where, hasUserDefinedWhere;
477
- // if (config.where) {
478
- // const whereSql = typeof config.where === 'function' ? config.where(aliasedFields, operators) : config.where;
479
- // where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
480
- // hasUserDefinedWhere = !!where;
481
- // }
482
- // where = and(joinOn, where);
483
- // // const fieldsSelection: { tsKey: string; value: PgColumn | SQL.Aliased; isExtra?: boolean }[] = [];
484
- // let joins: Join[] = [];
485
- // let selectedColumns: string[] = [];
486
- // // Figure out which columns to select
487
- // if (config.columns) {
488
- // let isIncludeMode = false;
489
- // for (const [field, value] of Object.entries(config.columns)) {
490
- // if (value === undefined) {
491
- // continue;
492
- // }
493
- // if (field in tableConfig.columns) {
494
- // if (!isIncludeMode && value === true) {
495
- // isIncludeMode = true;
496
- // }
497
- // selectedColumns.push(field);
498
- // }
499
- // }
500
- // if (selectedColumns.length > 0) {
501
- // selectedColumns = isIncludeMode
502
- // ? selectedColumns.filter((c) => config.columns?.[c] === true)
503
- // : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
504
- // }
505
- // } else {
506
- // // Select all columns if selection is not specified
507
- // selectedColumns = Object.keys(tableConfig.columns);
508
- // }
509
- // // for (const field of selectedColumns) {
510
- // // const column = tableConfig.columns[field]! as PgColumn;
511
- // // fieldsSelection.push({ tsKey: field, value: column });
512
- // // }
513
- // let initiallySelectedRelations: {
514
- // tsKey: string;
515
- // queryConfig: true | DBQueryConfig<'many', false>;
516
- // relation: Relation;
517
- // }[] = [];
518
- // // let selectedRelations: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
519
- // // Figure out which relations to select
520
- // if (config.with) {
521
- // initiallySelectedRelations = Object.entries(config.with)
522
- // .filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])
523
- // .map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));
524
- // }
525
- // const manyRelations = initiallySelectedRelations.filter((r) =>
526
- // is(r.relation, Many)
527
- // && (schema[tableNamesMap[r.relation.referencedTable[Table.Symbol.Name]]!]?.primaryKey.length ?? 0) > 0
528
- // );
529
- // // If this is the last Many relation (or there are no Many relations), we are on the innermost subquery level
530
- // const isInnermostQuery = manyRelations.length < 2;
531
- // const selectedExtras: {
532
- // tsKey: string;
533
- // value: SQL.Aliased;
534
- // }[] = [];
535
- // // Figure out which extras to select
536
- // if (isInnermostQuery && config.extras) {
537
- // const extras = typeof config.extras === 'function'
538
- // ? config.extras(aliasedFields, { sql })
539
- // : config.extras;
540
- // for (const [tsKey, value] of Object.entries(extras)) {
541
- // selectedExtras.push({
542
- // tsKey,
543
- // value: mapColumnsInAliasedSQLToAlias(value, tableAlias),
544
- // });
545
- // }
546
- // }
547
- // // Transform `fieldsSelection` into `selection`
548
- // // `fieldsSelection` shouldn't be used after this point
549
- // // for (const { tsKey, value, isExtra } of fieldsSelection) {
550
- // // selection.push({
551
- // // dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,
552
- // // tsKey,
553
- // // field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
554
- // // relationTableTsKey: undefined,
555
- // // isJson: false,
556
- // // isExtra,
557
- // // selection: [],
558
- // // });
559
- // // }
560
- // let orderByOrig = typeof config.orderBy === 'function'
561
- // ? config.orderBy(aliasedFields, orderByOperators)
562
- // : config.orderBy ?? [];
563
- // if (!Array.isArray(orderByOrig)) {
564
- // orderByOrig = [orderByOrig];
565
- // }
566
- // const orderBy = orderByOrig.map((orderByValue) => {
567
- // if (is(orderByValue, Column)) {
568
- // return aliasedTableColumn(orderByValue, tableAlias) as PgColumn;
569
- // }
570
- // return mapColumnsInSQLToAlias(orderByValue, tableAlias);
571
- // });
572
- // const limit = isInnermostQuery ? config.limit : undefined;
573
- // const offset = isInnermostQuery ? config.offset : undefined;
574
- // // For non-root queries without additional config except columns, return a table with selection
575
- // if (
576
- // !isRoot
577
- // && initiallySelectedRelations.length === 0
578
- // && selectedExtras.length === 0
579
- // && !where
580
- // && orderBy.length === 0
581
- // && limit === undefined
582
- // && offset === undefined
583
- // ) {
584
- // return {
585
- // tableTsKey: tableConfig.tsName,
586
- // sql: table,
587
- // selection: selectedColumns.map((key) => ({
588
- // dbKey: tableConfig.columns[key]!.name,
589
- // tsKey: key,
590
- // field: tableConfig.columns[key] as PgColumn,
591
- // relationTableTsKey: undefined,
592
- // isJson: false,
593
- // selection: [],
594
- // })),
595
- // };
596
- // }
597
- // const selectedRelationsWithoutPK:
598
- // // Process all relations without primary keys, because they need to be joined differently and will all be on the same query level
599
- // for (
600
- // const {
601
- // tsKey: selectedRelationTsKey,
602
- // queryConfig: selectedRelationConfigValue,
603
- // relation,
604
- // } of initiallySelectedRelations
605
- // ) {
606
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
607
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
608
- // const relationTableTsName = tableNamesMap[relationTableName]!;
609
- // const relationTable = schema[relationTableTsName]!;
610
- // if (relationTable.primaryKey.length > 0) {
611
- // continue;
612
- // }
613
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
614
- // const joinOn = and(
615
- // ...normalizedRelation.fields.map((field, i) =>
616
- // eq(
617
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
618
- // aliasedTableColumn(field, tableAlias),
619
- // )
620
- // ),
621
- // );
622
- // const builtRelation = this.buildRelationalQueryWithoutPK({
623
- // fullSchema,
624
- // schema,
625
- // tableNamesMap,
626
- // table: fullSchema[relationTableTsName] as PgTable,
627
- // tableConfig: schema[relationTableTsName]!,
628
- // queryConfig: selectedRelationConfigValue,
629
- // tableAlias: relationTableAlias,
630
- // joinOn,
631
- // nestedQueryRelation: relation,
632
- // });
633
- // const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);
634
- // joins.push({
635
- // on: sql`true`,
636
- // table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
637
- // alias: relationTableAlias,
638
- // joinType: 'left',
639
- // lateral: true,
640
- // });
641
- // selectedRelations.push({
642
- // dbKey: selectedRelationTsKey,
643
- // tsKey: selectedRelationTsKey,
644
- // field,
645
- // relationTableTsKey: relationTableTsName,
646
- // isJson: true,
647
- // selection: builtRelation.selection,
648
- // });
649
- // }
650
- // const oneRelations = initiallySelectedRelations.filter((r): r is typeof r & { relation: One } =>
651
- // is(r.relation, One)
652
- // );
653
- // // Process all One relations with PKs, because they can all be joined on the same level
654
- // for (
655
- // const {
656
- // tsKey: selectedRelationTsKey,
657
- // queryConfig: selectedRelationConfigValue,
658
- // relation,
659
- // } of oneRelations
660
- // ) {
661
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
662
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
663
- // const relationTableTsName = tableNamesMap[relationTableName]!;
664
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
665
- // const relationTable = schema[relationTableTsName]!;
666
- // if (relationTable.primaryKey.length === 0) {
667
- // continue;
668
- // }
669
- // const joinOn = and(
670
- // ...normalizedRelation.fields.map((field, i) =>
671
- // eq(
672
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
673
- // aliasedTableColumn(field, tableAlias),
674
- // )
675
- // ),
676
- // );
677
- // const builtRelation = this.buildRelationalQueryWithPK({
678
- // fullSchema,
679
- // schema,
680
- // tableNamesMap,
681
- // table: fullSchema[relationTableTsName] as PgTable,
682
- // tableConfig: schema[relationTableTsName]!,
683
- // queryConfig: selectedRelationConfigValue,
684
- // tableAlias: relationTableAlias,
685
- // joinOn,
686
- // });
687
- // const field = sql`case when ${sql.identifier(relationTableAlias)} is null then null else json_build_array(${
688
- // sql.join(
689
- // builtRelation.selection.map(({ field }) =>
690
- // is(field, SQL.Aliased)
691
- // ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
692
- // : is(field, Column)
693
- // ? aliasedTableColumn(field, relationTableAlias)
694
- // : field
695
- // ),
696
- // sql`, `,
697
- // )
698
- // }) end`.as(selectedRelationTsKey);
699
- // const isLateralJoin = is(builtRelation.sql, SQL);
700
- // joins.push({
701
- // on: isLateralJoin ? sql`true` : joinOn,
702
- // table: is(builtRelation.sql, SQL)
703
- // ? new Subquery(builtRelation.sql, {}, relationTableAlias)
704
- // : aliasedTable(builtRelation.sql, relationTableAlias),
705
- // alias: relationTableAlias,
706
- // joinType: 'left',
707
- // lateral: is(builtRelation.sql, SQL),
708
- // });
709
- // selectedRelations.push({
710
- // dbKey: selectedRelationTsKey,
711
- // tsKey: selectedRelationTsKey,
712
- // field,
713
- // relationTableTsKey: relationTableTsName,
714
- // isJson: true,
715
- // selection: builtRelation.selection,
716
- // });
717
- // }
718
- // let distinct: PgSelectConfig['distinct'];
719
- // let tableFrom: PgTable | Subquery = table;
720
- // // Process first Many relation - each one requires a nested subquery
721
- // const manyRelation = manyRelations[0];
722
- // if (manyRelation) {
723
- // const {
724
- // tsKey: selectedRelationTsKey,
725
- // queryConfig: selectedRelationQueryConfig,
726
- // relation,
727
- // } = manyRelation;
728
- // distinct = {
729
- // on: tableConfig.primaryKey.map((c) => aliasedTableColumn(c as PgColumn, tableAlias)),
730
- // };
731
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
732
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
733
- // const relationTableTsName = tableNamesMap[relationTableName]!;
734
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
735
- // const joinOn = and(
736
- // ...normalizedRelation.fields.map((field, i) =>
737
- // eq(
738
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
739
- // aliasedTableColumn(field, tableAlias),
740
- // )
741
- // ),
742
- // );
743
- // const builtRelationJoin = this.buildRelationalQueryWithPK({
744
- // fullSchema,
745
- // schema,
746
- // tableNamesMap,
747
- // table: fullSchema[relationTableTsName] as PgTable,
748
- // tableConfig: schema[relationTableTsName]!,
749
- // queryConfig: selectedRelationQueryConfig,
750
- // tableAlias: relationTableAlias,
751
- // joinOn,
752
- // });
753
- // const builtRelationSelectionField = sql`case when ${
754
- // sql.identifier(relationTableAlias)
755
- // } is null then '[]' else json_agg(json_build_array(${
756
- // sql.join(
757
- // builtRelationJoin.selection.map(({ field }) =>
758
- // is(field, SQL.Aliased)
759
- // ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
760
- // : is(field, Column)
761
- // ? aliasedTableColumn(field, relationTableAlias)
762
- // : field
763
- // ),
764
- // sql`, `,
765
- // )
766
- // })) over (partition by ${sql.join(distinct.on, sql`, `)}) end`.as(selectedRelationTsKey);
767
- // const isLateralJoin = is(builtRelationJoin.sql, SQL);
768
- // joins.push({
769
- // on: isLateralJoin ? sql`true` : joinOn,
770
- // table: isLateralJoin
771
- // ? new Subquery(builtRelationJoin.sql as SQL, {}, relationTableAlias)
772
- // : aliasedTable(builtRelationJoin.sql as PgTable, relationTableAlias),
773
- // alias: relationTableAlias,
774
- // joinType: 'left',
775
- // lateral: isLateralJoin,
776
- // });
777
- // // Build the "from" subquery with the remaining Many relations
778
- // const builtTableFrom = this.buildRelationalQueryWithPK({
779
- // fullSchema,
780
- // schema,
781
- // tableNamesMap,
782
- // table,
783
- // tableConfig,
784
- // queryConfig: {
785
- // ...config,
786
- // where: undefined,
787
- // orderBy: undefined,
788
- // limit: undefined,
789
- // offset: undefined,
790
- // with: manyRelations.slice(1).reduce<NonNullable<typeof config['with']>>(
791
- // (result, { tsKey, queryConfig: configValue }) => {
792
- // result[tsKey] = configValue;
793
- // return result;
794
- // },
795
- // {},
796
- // ),
797
- // },
798
- // tableAlias,
799
- // });
800
- // selectedRelations.push({
801
- // dbKey: selectedRelationTsKey,
802
- // tsKey: selectedRelationTsKey,
803
- // field: builtRelationSelectionField,
804
- // relationTableTsKey: relationTableTsName,
805
- // isJson: true,
806
- // selection: builtRelationJoin.selection,
807
- // });
808
- // // selection = builtTableFrom.selection.map((item) =>
809
- // // is(item.field, SQL.Aliased)
810
- // // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
811
- // // : item
812
- // // );
813
- // // selectionForBuild = [{
814
- // // dbKey: '*',
815
- // // tsKey: '*',
816
- // // field: sql`${sql.identifier(tableAlias)}.*`,
817
- // // selection: [],
818
- // // isJson: false,
819
- // // relationTableTsKey: undefined,
820
- // // }];
821
- // // const newSelectionItem: (typeof selection)[number] = {
822
- // // dbKey: selectedRelationTsKey,
823
- // // tsKey: selectedRelationTsKey,
824
- // // field,
825
- // // relationTableTsKey: relationTableTsName,
826
- // // isJson: true,
827
- // // selection: builtRelationJoin.selection,
828
- // // };
829
- // // selection.push(newSelectionItem);
830
- // // selectionForBuild.push(newSelectionItem);
831
- // tableFrom = is(builtTableFrom.sql, PgTable)
832
- // ? builtTableFrom.sql
833
- // : new Subquery(builtTableFrom.sql, {}, tableAlias);
834
- // }
835
- // if (selectedColumns.length === 0 && selectedRelations.length === 0 && selectedExtras.length === 0) {
836
- // throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
837
- // }
838
- // let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'];
839
- // function prepareSelectedColumns() {
840
- // return selectedColumns.map((key) => ({
841
- // dbKey: tableConfig.columns[key]!.name,
842
- // tsKey: key,
843
- // field: tableConfig.columns[key] as PgColumn,
844
- // relationTableTsKey: undefined,
845
- // isJson: false,
846
- // selection: [],
847
- // }));
848
- // }
849
- // function prepareSelectedExtras() {
850
- // return selectedExtras.map((item) => ({
851
- // dbKey: item.value.fieldAlias,
852
- // tsKey: item.tsKey,
853
- // field: item.value,
854
- // relationTableTsKey: undefined,
855
- // isJson: false,
856
- // selection: [],
857
- // }));
858
- // }
859
- // if (isRoot) {
860
- // selection = [
861
- // ...prepareSelectedColumns(),
862
- // ...prepareSelectedExtras(),
863
- // ];
864
- // }
865
- // if (hasUserDefinedWhere || orderBy.length > 0) {
866
- // tableFrom = new Subquery(
867
- // this.buildSelectQuery({
868
- // table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
869
- // fields: {},
870
- // fieldsFlat: selectionForBuild.map(({ field }) => ({
871
- // path: [],
872
- // field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
873
- // })),
874
- // joins,
875
- // distinct,
876
- // }),
877
- // {},
878
- // tableAlias,
879
- // );
880
- // selectionForBuild = selection.map((item) =>
881
- // is(item.field, SQL.Aliased)
882
- // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
883
- // : item
884
- // );
885
- // joins = [];
886
- // distinct = undefined;
887
- // }
888
- // const result = this.buildSelectQuery({
889
- // table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
890
- // fields: {},
891
- // fieldsFlat: selectionForBuild.map(({ field }) => ({
892
- // path: [],
893
- // field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
894
- // })),
895
- // where,
896
- // limit,
897
- // offset,
898
- // joins,
899
- // orderBy,
900
- // distinct,
901
- // });
902
- // return {
903
- // tableTsKey: tableConfig.tsName,
904
- // sql: result,
905
- // selection,
906
- // };
907
- // }
908
- buildRelationalQueryWithoutPK({
430
+ /** @deprecated */
431
+ _buildRelationalQuery({
909
432
  fullSchema,
910
433
  schema,
911
434
  tableNamesMap,
@@ -934,7 +457,7 @@ class PgDialect {
934
457
  Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)])
935
458
  );
936
459
  if (config.where) {
937
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
460
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
938
461
  where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
939
462
  }
940
463
  const fieldsSelection = [];
@@ -986,7 +509,7 @@ class PgDialect {
986
509
  selection: []
987
510
  });
988
511
  }
989
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
512
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
990
513
  if (!Array.isArray(orderByOrig)) {
991
514
  orderByOrig = [orderByOrig];
992
515
  }
@@ -1003,7 +526,7 @@ class PgDialect {
1003
526
  queryConfig: selectedRelationConfigValue,
1004
527
  relation
1005
528
  } of selectedRelations) {
1006
- const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
529
+ const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
1007
530
  const relationTableName = getTableUniqueName(relation.referencedTable);
1008
531
  const relationTableTsName = tableNamesMap[relationTableName];
1009
532
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -1015,13 +538,13 @@ class PgDialect {
1015
538
  )
1016
539
  )
1017
540
  );
1018
- const builtRelation = this.buildRelationalQueryWithoutPK({
541
+ const builtRelation = this._buildRelationalQuery({
1019
542
  fullSchema,
1020
543
  schema,
1021
544
  tableNamesMap,
1022
545
  table: fullSchema[relationTableTsName],
1023
546
  tableConfig: schema[relationTableTsName],
1024
- queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
547
+ queryConfig: is(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
1025
548
  tableAlias: relationTableAlias,
1026
549
  joinOn: joinOn2,
1027
550
  nestedQueryRelation: relation
@@ -1056,7 +579,7 @@ class PgDialect {
1056
579
  ),
1057
580
  sql`, `
1058
581
  )})`;
1059
- if (is(nestedQueryRelation, Many)) {
582
+ if (is(nestedQueryRelation, V1.Many)) {
1060
583
  field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0}), '[]'::json)`;
1061
584
  }
1062
585
  const nestedSelection = [{
@@ -1125,6 +648,177 @@ class PgDialect {
1125
648
  selection
1126
649
  };
1127
650
  }
651
+ nestedSelectionerror() {
652
+ throw new DrizzleError({
653
+ message: `Views with nested selections are not supported by the relational query builder`
654
+ });
655
+ }
656
+ buildRqbColumn(table, column, key) {
657
+ if (is(column, Column)) {
658
+ const name = sql`${table}.${sql.identifier(this.casing.getColumnCasing(column))}`;
659
+ let targetType = column.columnType;
660
+ let col = column;
661
+ let arrVal = "";
662
+ while (is(col, PgArray)) {
663
+ col = column.baseColumn;
664
+ targetType = col.columnType;
665
+ arrVal = arrVal + "[]";
666
+ }
667
+ switch (targetType) {
668
+ case "PgNumeric":
669
+ case "PgBigInt64":
670
+ case "PgBigSerial64":
671
+ case "PgTimestampString":
672
+ case "PgGeometry":
673
+ case "PgGeometryObject": {
674
+ return sql`${name}::text${sql.raw(arrVal).if(arrVal)} as ${sql.identifier(key)}`;
675
+ }
676
+ default: {
677
+ return sql`${name} as ${sql.identifier(key)}`;
678
+ }
679
+ }
680
+ }
681
+ return sql`${table}.${is(column, SQL.Aliased) ? sql.identifier(column.fieldAlias) : isSQLWrapper(column) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
682
+ }
683
+ unwrapAllColumns = (table, selection) => {
684
+ return sql.join(
685
+ Object.entries(table[Columns]).map(([k, v]) => {
686
+ selection.push({
687
+ key: k,
688
+ field: v
689
+ });
690
+ return this.buildRqbColumn(table, v, k);
691
+ }),
692
+ sql`, `
693
+ );
694
+ };
695
+ buildColumns = (table, selection, config) => config?.columns ? (() => {
696
+ const entries = Object.entries(config.columns);
697
+ const columnContainer = table[Columns];
698
+ const columnIdentifiers = [];
699
+ let colSelectionMode;
700
+ for (const [k, v] of entries) {
701
+ if (v === void 0)
702
+ continue;
703
+ colSelectionMode = colSelectionMode || v;
704
+ if (v) {
705
+ const column = columnContainer[k];
706
+ columnIdentifiers.push(
707
+ this.buildRqbColumn(table, column, k)
708
+ );
709
+ selection.push({
710
+ key: k,
711
+ field: column
712
+ });
713
+ }
714
+ }
715
+ if (colSelectionMode === false) {
716
+ for (const [k, v] of Object.entries(columnContainer)) {
717
+ if (config.columns[k] === false)
718
+ continue;
719
+ columnIdentifiers.push(this.buildRqbColumn(table, v, k));
720
+ selection.push({
721
+ key: k,
722
+ field: v
723
+ });
724
+ }
725
+ }
726
+ return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
727
+ })() : this.unwrapAllColumns(table, selection);
728
+ buildRelationalQuery({
729
+ tables,
730
+ schema,
731
+ tableNamesMap,
732
+ table,
733
+ tableConfig,
734
+ queryConfig: config,
735
+ relationWhere,
736
+ mode,
737
+ errorPath,
738
+ depth,
739
+ throughJoin
740
+ }) {
741
+ const selection = [];
742
+ const isSingle = mode === "first";
743
+ const params = config === true ? void 0 : config;
744
+ const currentPath = errorPath ?? "";
745
+ const currentDepth = depth ?? 0;
746
+ if (!currentDepth)
747
+ table = aliasedTable(table, `d${currentDepth}`);
748
+ const limit = isSingle ? 1 : params?.limit;
749
+ const offset = params?.offset;
750
+ const where = params?.where && relationWhere ? and(
751
+ relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing),
752
+ relationWhere
753
+ ) : params?.where ? relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing) : relationWhere;
754
+ const order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : void 0;
755
+ const columns = this.buildColumns(table, selection, params);
756
+ const extras = params?.extras ? relationExtrasToSQL(table, params.extras) : void 0;
757
+ if (extras)
758
+ selection.push(...extras.selection);
759
+ const selectionArr = columns ? [columns] : [];
760
+ const joins = params ? (() => {
761
+ const { with: joins2 } = params;
762
+ if (!joins2)
763
+ return;
764
+ const withEntries = Object.entries(joins2).filter(([_, v]) => v);
765
+ if (!withEntries.length)
766
+ return;
767
+ return sql.join(
768
+ withEntries.map(([k, join]) => {
769
+ const relation = tableConfig.relations[k];
770
+ const isSingle2 = is(relation, One);
771
+ const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
772
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
773
+ const { filter, joinCondition } = relationToSQL(
774
+ this.casing,
775
+ relation,
776
+ table,
777
+ targetTable,
778
+ throughTable
779
+ );
780
+ selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
781
+ const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
782
+ const innerQuery = this.buildRelationalQuery({
783
+ table: targetTable,
784
+ mode: isSingle2 ? "first" : "many",
785
+ schema,
786
+ queryConfig: join,
787
+ tableConfig: schema[tableNamesMap[getTableUniqueName(relation.targetTable)]],
788
+ tableNamesMap,
789
+ tables,
790
+ relationWhere: filter,
791
+ errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
792
+ depth: currentDepth + 1,
793
+ throughJoin: throughJoin2
794
+ });
795
+ selection.push({
796
+ field: targetTable,
797
+ key: k,
798
+ selection: innerQuery.selection,
799
+ isArray: !isSingle2,
800
+ isOptional: (relation.optional ?? false) || join !== true && !!join.where
801
+ });
802
+ const joinQuery = sql`left join lateral(select ${isSingle2 ? sql`row_to_json(${sql.identifier("t")}.*) ${sql.identifier("r")}` : sql`coalesce(json_agg(row_to_json(${sql.identifier("t")}.*)), '[]') as ${sql.identifier("r")}`} from (${innerQuery.sql}) as ${sql.identifier("t")}) as ${sql.identifier(k)} on true`;
803
+ return joinQuery;
804
+ }),
805
+ sql` `
806
+ );
807
+ })() : void 0;
808
+ if (extras?.sql)
809
+ selectionArr.push(extras.sql);
810
+ if (!selectionArr.length) {
811
+ throw new DrizzleError({
812
+ message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
813
+ });
814
+ }
815
+ const selectionSet = sql.join(selectionArr.filter((e) => e !== void 0), sql`, `);
816
+ const query = sql`select ${selectionSet} from ${getTableAsAliasSQL(table)}${throughJoin}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
817
+ return {
818
+ sql: query,
819
+ selection
820
+ };
821
+ }
1128
822
  }
1129
823
  export {
1130
824
  PgDialect