drizzle-orm 0.36.3 → 0.36.4-0ab568f

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