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,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var dialect_exports = {};
20
30
  __export(dialect_exports, {
21
31
  PgDialect: () => PgDialect
22
32
  });
23
33
  module.exports = __toCommonJS(dialect_exports);
34
+ var V1 = __toESM(require("../_relations.cjs"), 1);
24
35
  var import_alias = require("../alias.cjs");
25
36
  var import_casing = require("../casing.cjs");
26
37
  var import_column = require("../column.cjs");
@@ -344,7 +355,7 @@ class PgDialect {
344
355
  const offsetSql = offset ? import_sql2.sql` offset ${offset}` : void 0;
345
356
  return import_sql2.sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
346
357
  }
347
- buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) {
358
+ buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
348
359
  const valuesSqlList = [];
349
360
  const columns = table[import_table2.Table.Symbol.Columns];
350
361
  const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
@@ -391,7 +402,8 @@ class PgDialect {
391
402
  const valuesSql = import_sql2.sql.join(valuesSqlList);
392
403
  const returningSql = returning ? import_sql2.sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
393
404
  const onConflictSql = onConflict ? import_sql2.sql` on conflict ${onConflict}` : void 0;
394
- return import_sql2.sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
405
+ const overridingSql = overridingSystemValue_ === true ? import_sql2.sql`overriding system value ` : void 0;
406
+ return import_sql2.sql`${withSql}insert into ${table} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
395
407
  }
396
408
  buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
397
409
  const concurrentlySql = concurrently ? import_sql2.sql` concurrently` : void 0;
@@ -425,488 +437,8 @@ class PgDialect {
425
437
  invokeSource
426
438
  });
427
439
  }
428
- // buildRelationalQueryWithPK({
429
- // fullSchema,
430
- // schema,
431
- // tableNamesMap,
432
- // table,
433
- // tableConfig,
434
- // queryConfig: config,
435
- // tableAlias,
436
- // isRoot = false,
437
- // joinOn,
438
- // }: {
439
- // fullSchema: Record<string, unknown>;
440
- // schema: TablesRelationalConfig;
441
- // tableNamesMap: Record<string, string>;
442
- // table: PgTable;
443
- // tableConfig: TableRelationalConfig;
444
- // queryConfig: true | DBQueryConfig<'many', true>;
445
- // tableAlias: string;
446
- // isRoot?: boolean;
447
- // joinOn?: SQL;
448
- // }): BuildRelationalQueryResult<PgTable, PgColumn> {
449
- // // For { "<relation>": true }, return a table with selection of all columns
450
- // if (config === true) {
451
- // const selectionEntries = Object.entries(tableConfig.columns);
452
- // const selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = selectionEntries.map((
453
- // [key, value],
454
- // ) => ({
455
- // dbKey: value.name,
456
- // tsKey: key,
457
- // field: value as PgColumn,
458
- // relationTableTsKey: undefined,
459
- // isJson: false,
460
- // selection: [],
461
- // }));
462
- // return {
463
- // tableTsKey: tableConfig.tsName,
464
- // sql: table,
465
- // selection,
466
- // };
467
- // }
468
- // // let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
469
- // // let selectionForBuild = selection;
470
- // const aliasedColumns = Object.fromEntries(
471
- // Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),
472
- // );
473
- // const aliasedRelations = Object.fromEntries(
474
- // Object.entries(tableConfig.relations).map(([key, value]) => [key, aliasedRelation(value, tableAlias)]),
475
- // );
476
- // const aliasedFields = Object.assign({}, aliasedColumns, aliasedRelations);
477
- // let where, hasUserDefinedWhere;
478
- // if (config.where) {
479
- // const whereSql = typeof config.where === 'function' ? config.where(aliasedFields, operators) : config.where;
480
- // where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
481
- // hasUserDefinedWhere = !!where;
482
- // }
483
- // where = and(joinOn, where);
484
- // // const fieldsSelection: { tsKey: string; value: PgColumn | SQL.Aliased; isExtra?: boolean }[] = [];
485
- // let joins: Join[] = [];
486
- // let selectedColumns: string[] = [];
487
- // // Figure out which columns to select
488
- // if (config.columns) {
489
- // let isIncludeMode = false;
490
- // for (const [field, value] of Object.entries(config.columns)) {
491
- // if (value === undefined) {
492
- // continue;
493
- // }
494
- // if (field in tableConfig.columns) {
495
- // if (!isIncludeMode && value === true) {
496
- // isIncludeMode = true;
497
- // }
498
- // selectedColumns.push(field);
499
- // }
500
- // }
501
- // if (selectedColumns.length > 0) {
502
- // selectedColumns = isIncludeMode
503
- // ? selectedColumns.filter((c) => config.columns?.[c] === true)
504
- // : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
505
- // }
506
- // } else {
507
- // // Select all columns if selection is not specified
508
- // selectedColumns = Object.keys(tableConfig.columns);
509
- // }
510
- // // for (const field of selectedColumns) {
511
- // // const column = tableConfig.columns[field]! as PgColumn;
512
- // // fieldsSelection.push({ tsKey: field, value: column });
513
- // // }
514
- // let initiallySelectedRelations: {
515
- // tsKey: string;
516
- // queryConfig: true | DBQueryConfig<'many', false>;
517
- // relation: Relation;
518
- // }[] = [];
519
- // // let selectedRelations: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
520
- // // Figure out which relations to select
521
- // if (config.with) {
522
- // initiallySelectedRelations = Object.entries(config.with)
523
- // .filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])
524
- // .map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));
525
- // }
526
- // const manyRelations = initiallySelectedRelations.filter((r) =>
527
- // is(r.relation, Many)
528
- // && (schema[tableNamesMap[r.relation.referencedTable[Table.Symbol.Name]]!]?.primaryKey.length ?? 0) > 0
529
- // );
530
- // // If this is the last Many relation (or there are no Many relations), we are on the innermost subquery level
531
- // const isInnermostQuery = manyRelations.length < 2;
532
- // const selectedExtras: {
533
- // tsKey: string;
534
- // value: SQL.Aliased;
535
- // }[] = [];
536
- // // Figure out which extras to select
537
- // if (isInnermostQuery && config.extras) {
538
- // const extras = typeof config.extras === 'function'
539
- // ? config.extras(aliasedFields, { sql })
540
- // : config.extras;
541
- // for (const [tsKey, value] of Object.entries(extras)) {
542
- // selectedExtras.push({
543
- // tsKey,
544
- // value: mapColumnsInAliasedSQLToAlias(value, tableAlias),
545
- // });
546
- // }
547
- // }
548
- // // Transform `fieldsSelection` into `selection`
549
- // // `fieldsSelection` shouldn't be used after this point
550
- // // for (const { tsKey, value, isExtra } of fieldsSelection) {
551
- // // selection.push({
552
- // // dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,
553
- // // tsKey,
554
- // // field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
555
- // // relationTableTsKey: undefined,
556
- // // isJson: false,
557
- // // isExtra,
558
- // // selection: [],
559
- // // });
560
- // // }
561
- // let orderByOrig = typeof config.orderBy === 'function'
562
- // ? config.orderBy(aliasedFields, orderByOperators)
563
- // : config.orderBy ?? [];
564
- // if (!Array.isArray(orderByOrig)) {
565
- // orderByOrig = [orderByOrig];
566
- // }
567
- // const orderBy = orderByOrig.map((orderByValue) => {
568
- // if (is(orderByValue, Column)) {
569
- // return aliasedTableColumn(orderByValue, tableAlias) as PgColumn;
570
- // }
571
- // return mapColumnsInSQLToAlias(orderByValue, tableAlias);
572
- // });
573
- // const limit = isInnermostQuery ? config.limit : undefined;
574
- // const offset = isInnermostQuery ? config.offset : undefined;
575
- // // For non-root queries without additional config except columns, return a table with selection
576
- // if (
577
- // !isRoot
578
- // && initiallySelectedRelations.length === 0
579
- // && selectedExtras.length === 0
580
- // && !where
581
- // && orderBy.length === 0
582
- // && limit === undefined
583
- // && offset === undefined
584
- // ) {
585
- // return {
586
- // tableTsKey: tableConfig.tsName,
587
- // sql: table,
588
- // selection: selectedColumns.map((key) => ({
589
- // dbKey: tableConfig.columns[key]!.name,
590
- // tsKey: key,
591
- // field: tableConfig.columns[key] as PgColumn,
592
- // relationTableTsKey: undefined,
593
- // isJson: false,
594
- // selection: [],
595
- // })),
596
- // };
597
- // }
598
- // const selectedRelationsWithoutPK:
599
- // // Process all relations without primary keys, because they need to be joined differently and will all be on the same query level
600
- // for (
601
- // const {
602
- // tsKey: selectedRelationTsKey,
603
- // queryConfig: selectedRelationConfigValue,
604
- // relation,
605
- // } of initiallySelectedRelations
606
- // ) {
607
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
608
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
609
- // const relationTableTsName = tableNamesMap[relationTableName]!;
610
- // const relationTable = schema[relationTableTsName]!;
611
- // if (relationTable.primaryKey.length > 0) {
612
- // continue;
613
- // }
614
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
615
- // const joinOn = and(
616
- // ...normalizedRelation.fields.map((field, i) =>
617
- // eq(
618
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
619
- // aliasedTableColumn(field, tableAlias),
620
- // )
621
- // ),
622
- // );
623
- // const builtRelation = this.buildRelationalQueryWithoutPK({
624
- // fullSchema,
625
- // schema,
626
- // tableNamesMap,
627
- // table: fullSchema[relationTableTsName] as PgTable,
628
- // tableConfig: schema[relationTableTsName]!,
629
- // queryConfig: selectedRelationConfigValue,
630
- // tableAlias: relationTableAlias,
631
- // joinOn,
632
- // nestedQueryRelation: relation,
633
- // });
634
- // const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);
635
- // joins.push({
636
- // on: sql`true`,
637
- // table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
638
- // alias: relationTableAlias,
639
- // joinType: 'left',
640
- // lateral: true,
641
- // });
642
- // selectedRelations.push({
643
- // dbKey: selectedRelationTsKey,
644
- // tsKey: selectedRelationTsKey,
645
- // field,
646
- // relationTableTsKey: relationTableTsName,
647
- // isJson: true,
648
- // selection: builtRelation.selection,
649
- // });
650
- // }
651
- // const oneRelations = initiallySelectedRelations.filter((r): r is typeof r & { relation: One } =>
652
- // is(r.relation, One)
653
- // );
654
- // // Process all One relations with PKs, because they can all be joined on the same level
655
- // for (
656
- // const {
657
- // tsKey: selectedRelationTsKey,
658
- // queryConfig: selectedRelationConfigValue,
659
- // relation,
660
- // } of oneRelations
661
- // ) {
662
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
663
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
664
- // const relationTableTsName = tableNamesMap[relationTableName]!;
665
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
666
- // const relationTable = schema[relationTableTsName]!;
667
- // if (relationTable.primaryKey.length === 0) {
668
- // continue;
669
- // }
670
- // const joinOn = and(
671
- // ...normalizedRelation.fields.map((field, i) =>
672
- // eq(
673
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
674
- // aliasedTableColumn(field, tableAlias),
675
- // )
676
- // ),
677
- // );
678
- // const builtRelation = this.buildRelationalQueryWithPK({
679
- // fullSchema,
680
- // schema,
681
- // tableNamesMap,
682
- // table: fullSchema[relationTableTsName] as PgTable,
683
- // tableConfig: schema[relationTableTsName]!,
684
- // queryConfig: selectedRelationConfigValue,
685
- // tableAlias: relationTableAlias,
686
- // joinOn,
687
- // });
688
- // const field = sql`case when ${sql.identifier(relationTableAlias)} is null then null else json_build_array(${
689
- // sql.join(
690
- // builtRelation.selection.map(({ field }) =>
691
- // is(field, SQL.Aliased)
692
- // ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
693
- // : is(field, Column)
694
- // ? aliasedTableColumn(field, relationTableAlias)
695
- // : field
696
- // ),
697
- // sql`, `,
698
- // )
699
- // }) end`.as(selectedRelationTsKey);
700
- // const isLateralJoin = is(builtRelation.sql, SQL);
701
- // joins.push({
702
- // on: isLateralJoin ? sql`true` : joinOn,
703
- // table: is(builtRelation.sql, SQL)
704
- // ? new Subquery(builtRelation.sql, {}, relationTableAlias)
705
- // : aliasedTable(builtRelation.sql, relationTableAlias),
706
- // alias: relationTableAlias,
707
- // joinType: 'left',
708
- // lateral: is(builtRelation.sql, SQL),
709
- // });
710
- // selectedRelations.push({
711
- // dbKey: selectedRelationTsKey,
712
- // tsKey: selectedRelationTsKey,
713
- // field,
714
- // relationTableTsKey: relationTableTsName,
715
- // isJson: true,
716
- // selection: builtRelation.selection,
717
- // });
718
- // }
719
- // let distinct: PgSelectConfig['distinct'];
720
- // let tableFrom: PgTable | Subquery = table;
721
- // // Process first Many relation - each one requires a nested subquery
722
- // const manyRelation = manyRelations[0];
723
- // if (manyRelation) {
724
- // const {
725
- // tsKey: selectedRelationTsKey,
726
- // queryConfig: selectedRelationQueryConfig,
727
- // relation,
728
- // } = manyRelation;
729
- // distinct = {
730
- // on: tableConfig.primaryKey.map((c) => aliasedTableColumn(c as PgColumn, tableAlias)),
731
- // };
732
- // const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
733
- // const relationTableName = relation.referencedTable[Table.Symbol.Name];
734
- // const relationTableTsName = tableNamesMap[relationTableName]!;
735
- // const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
736
- // const joinOn = and(
737
- // ...normalizedRelation.fields.map((field, i) =>
738
- // eq(
739
- // aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
740
- // aliasedTableColumn(field, tableAlias),
741
- // )
742
- // ),
743
- // );
744
- // const builtRelationJoin = this.buildRelationalQueryWithPK({
745
- // fullSchema,
746
- // schema,
747
- // tableNamesMap,
748
- // table: fullSchema[relationTableTsName] as PgTable,
749
- // tableConfig: schema[relationTableTsName]!,
750
- // queryConfig: selectedRelationQueryConfig,
751
- // tableAlias: relationTableAlias,
752
- // joinOn,
753
- // });
754
- // const builtRelationSelectionField = sql`case when ${
755
- // sql.identifier(relationTableAlias)
756
- // } is null then '[]' else json_agg(json_build_array(${
757
- // sql.join(
758
- // builtRelationJoin.selection.map(({ field }) =>
759
- // is(field, SQL.Aliased)
760
- // ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
761
- // : is(field, Column)
762
- // ? aliasedTableColumn(field, relationTableAlias)
763
- // : field
764
- // ),
765
- // sql`, `,
766
- // )
767
- // })) over (partition by ${sql.join(distinct.on, sql`, `)}) end`.as(selectedRelationTsKey);
768
- // const isLateralJoin = is(builtRelationJoin.sql, SQL);
769
- // joins.push({
770
- // on: isLateralJoin ? sql`true` : joinOn,
771
- // table: isLateralJoin
772
- // ? new Subquery(builtRelationJoin.sql as SQL, {}, relationTableAlias)
773
- // : aliasedTable(builtRelationJoin.sql as PgTable, relationTableAlias),
774
- // alias: relationTableAlias,
775
- // joinType: 'left',
776
- // lateral: isLateralJoin,
777
- // });
778
- // // Build the "from" subquery with the remaining Many relations
779
- // const builtTableFrom = this.buildRelationalQueryWithPK({
780
- // fullSchema,
781
- // schema,
782
- // tableNamesMap,
783
- // table,
784
- // tableConfig,
785
- // queryConfig: {
786
- // ...config,
787
- // where: undefined,
788
- // orderBy: undefined,
789
- // limit: undefined,
790
- // offset: undefined,
791
- // with: manyRelations.slice(1).reduce<NonNullable<typeof config['with']>>(
792
- // (result, { tsKey, queryConfig: configValue }) => {
793
- // result[tsKey] = configValue;
794
- // return result;
795
- // },
796
- // {},
797
- // ),
798
- // },
799
- // tableAlias,
800
- // });
801
- // selectedRelations.push({
802
- // dbKey: selectedRelationTsKey,
803
- // tsKey: selectedRelationTsKey,
804
- // field: builtRelationSelectionField,
805
- // relationTableTsKey: relationTableTsName,
806
- // isJson: true,
807
- // selection: builtRelationJoin.selection,
808
- // });
809
- // // selection = builtTableFrom.selection.map((item) =>
810
- // // is(item.field, SQL.Aliased)
811
- // // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
812
- // // : item
813
- // // );
814
- // // selectionForBuild = [{
815
- // // dbKey: '*',
816
- // // tsKey: '*',
817
- // // field: sql`${sql.identifier(tableAlias)}.*`,
818
- // // selection: [],
819
- // // isJson: false,
820
- // // relationTableTsKey: undefined,
821
- // // }];
822
- // // const newSelectionItem: (typeof selection)[number] = {
823
- // // dbKey: selectedRelationTsKey,
824
- // // tsKey: selectedRelationTsKey,
825
- // // field,
826
- // // relationTableTsKey: relationTableTsName,
827
- // // isJson: true,
828
- // // selection: builtRelationJoin.selection,
829
- // // };
830
- // // selection.push(newSelectionItem);
831
- // // selectionForBuild.push(newSelectionItem);
832
- // tableFrom = is(builtTableFrom.sql, PgTable)
833
- // ? builtTableFrom.sql
834
- // : new Subquery(builtTableFrom.sql, {}, tableAlias);
835
- // }
836
- // if (selectedColumns.length === 0 && selectedRelations.length === 0 && selectedExtras.length === 0) {
837
- // throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
838
- // }
839
- // let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'];
840
- // function prepareSelectedColumns() {
841
- // return selectedColumns.map((key) => ({
842
- // dbKey: tableConfig.columns[key]!.name,
843
- // tsKey: key,
844
- // field: tableConfig.columns[key] as PgColumn,
845
- // relationTableTsKey: undefined,
846
- // isJson: false,
847
- // selection: [],
848
- // }));
849
- // }
850
- // function prepareSelectedExtras() {
851
- // return selectedExtras.map((item) => ({
852
- // dbKey: item.value.fieldAlias,
853
- // tsKey: item.tsKey,
854
- // field: item.value,
855
- // relationTableTsKey: undefined,
856
- // isJson: false,
857
- // selection: [],
858
- // }));
859
- // }
860
- // if (isRoot) {
861
- // selection = [
862
- // ...prepareSelectedColumns(),
863
- // ...prepareSelectedExtras(),
864
- // ];
865
- // }
866
- // if (hasUserDefinedWhere || orderBy.length > 0) {
867
- // tableFrom = new Subquery(
868
- // this.buildSelectQuery({
869
- // table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
870
- // fields: {},
871
- // fieldsFlat: selectionForBuild.map(({ field }) => ({
872
- // path: [],
873
- // field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
874
- // })),
875
- // joins,
876
- // distinct,
877
- // }),
878
- // {},
879
- // tableAlias,
880
- // );
881
- // selectionForBuild = selection.map((item) =>
882
- // is(item.field, SQL.Aliased)
883
- // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
884
- // : item
885
- // );
886
- // joins = [];
887
- // distinct = undefined;
888
- // }
889
- // const result = this.buildSelectQuery({
890
- // table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
891
- // fields: {},
892
- // fieldsFlat: selectionForBuild.map(({ field }) => ({
893
- // path: [],
894
- // field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
895
- // })),
896
- // where,
897
- // limit,
898
- // offset,
899
- // joins,
900
- // orderBy,
901
- // distinct,
902
- // });
903
- // return {
904
- // tableTsKey: tableConfig.tsName,
905
- // sql: result,
906
- // selection,
907
- // };
908
- // }
909
- buildRelationalQueryWithoutPK({
440
+ /** @deprecated */
441
+ _buildRelationalQuery({
910
442
  fullSchema,
911
443
  schema,
912
444
  tableNamesMap,
@@ -935,7 +467,7 @@ class PgDialect {
935
467
  Object.entries(tableConfig.columns).map(([key, value]) => [key, (0, import_alias.aliasedTableColumn)(value, tableAlias)])
936
468
  );
937
469
  if (config.where) {
938
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0, import_relations.getOperators)()) : config.where;
470
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
939
471
  where = whereSql && (0, import_alias.mapColumnsInSQLToAlias)(whereSql, tableAlias);
940
472
  }
941
473
  const fieldsSelection = [];
@@ -987,7 +519,7 @@ class PgDialect {
987
519
  selection: []
988
520
  });
989
521
  }
990
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0, import_relations.getOrderByOperators)()) : config.orderBy ?? [];
522
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
991
523
  if (!Array.isArray(orderByOrig)) {
992
524
  orderByOrig = [orderByOrig];
993
525
  }
@@ -1004,7 +536,7 @@ class PgDialect {
1004
536
  queryConfig: selectedRelationConfigValue,
1005
537
  relation
1006
538
  } of selectedRelations) {
1007
- const normalizedRelation = (0, import_relations.normalizeRelation)(schema, tableNamesMap, relation);
539
+ const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
1008
540
  const relationTableName = (0, import_table2.getTableUniqueName)(relation.referencedTable);
1009
541
  const relationTableTsName = tableNamesMap[relationTableName];
1010
542
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -1016,13 +548,13 @@ class PgDialect {
1016
548
  )
1017
549
  )
1018
550
  );
1019
- const builtRelation = this.buildRelationalQueryWithoutPK({
551
+ const builtRelation = this._buildRelationalQuery({
1020
552
  fullSchema,
1021
553
  schema,
1022
554
  tableNamesMap,
1023
555
  table: fullSchema[relationTableTsName],
1024
556
  tableConfig: schema[relationTableTsName],
1025
- queryConfig: (0, import_entity.is)(relation, import_relations.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
557
+ queryConfig: (0, import_entity.is)(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
1026
558
  tableAlias: relationTableAlias,
1027
559
  joinOn: joinOn2,
1028
560
  nestedQueryRelation: relation
@@ -1057,7 +589,7 @@ class PgDialect {
1057
589
  ),
1058
590
  import_sql2.sql`, `
1059
591
  )})`;
1060
- if ((0, import_entity.is)(nestedQueryRelation, import_relations.Many)) {
592
+ if ((0, import_entity.is)(nestedQueryRelation, V1.Many)) {
1061
593
  field = import_sql2.sql`coalesce(json_agg(${field}${orderBy.length > 0 ? import_sql2.sql` order by ${import_sql2.sql.join(orderBy, import_sql2.sql`, `)}` : void 0}), '[]'::json)`;
1062
594
  }
1063
595
  const nestedSelection = [{
@@ -1126,6 +658,133 @@ class PgDialect {
1126
658
  selection
1127
659
  };
1128
660
  }
661
+ unwrapAllColumns = (table, selection) => {
662
+ return import_sql2.sql.join(
663
+ Object.entries(table[import_table2.Columns]).map(([k, v]) => {
664
+ selection.push({
665
+ key: k,
666
+ field: v
667
+ });
668
+ return import_sql2.sql`${v} as ${import_sql2.sql.identifier(k)}`;
669
+ }),
670
+ import_sql2.sql`, `
671
+ );
672
+ };
673
+ buildColumns = (table, tableConfig, selection, config) => config?.columns ? (() => {
674
+ const entries = Object.entries(config.columns);
675
+ const columnIdentifiers = [];
676
+ let colSelectionMode;
677
+ for (const [k, v] of entries) {
678
+ if (colSelectionMode === void 0)
679
+ colSelectionMode = v;
680
+ else if (v !== void 0 && colSelectionMode !== v) {
681
+ throw new Error("Columns cannot be both true and false at the same time");
682
+ }
683
+ if (v) {
684
+ columnIdentifiers.push(
685
+ import_sql2.sql`${table[import_table2.Columns][k]} as ${import_sql2.sql.identifier(k)}`
686
+ );
687
+ selection.push({
688
+ key: k,
689
+ field: table[import_table2.Columns][k]
690
+ });
691
+ }
692
+ }
693
+ if (colSelectionMode === false) {
694
+ for (const [k, v] of Object.entries(table[import_table2.Columns])) {
695
+ if (config.columns[k] === false)
696
+ continue;
697
+ columnIdentifiers.push(import_sql2.sql`${v} as ${import_sql2.sql.identifier(k)}`);
698
+ selection.push({
699
+ key: k,
700
+ field: v
701
+ });
702
+ }
703
+ }
704
+ return columnIdentifiers.length ? import_sql2.sql.join(columnIdentifiers, import_sql2.sql`, `) : this.unwrapAllColumns(table, selection);
705
+ })() : (() => {
706
+ const columnIdentifiers = [this.unwrapAllColumns(table, selection)];
707
+ return import_sql2.sql.join(columnIdentifiers, import_sql2.sql`, `);
708
+ })();
709
+ buildRelationalQuery({
710
+ tables,
711
+ schema,
712
+ tableNamesMap,
713
+ table,
714
+ tableConfig,
715
+ queryConfig: config,
716
+ relationWhere,
717
+ mode
718
+ }) {
719
+ const selection = [];
720
+ const isSingle = mode === "first";
721
+ const params = config === true ? void 0 : config;
722
+ const limit = isSingle ? 1 : params?.limit;
723
+ const offset = params?.offset;
724
+ const where = params?.where && relationWhere ? (0, import_sql.and)((0, import_relations.relationFilterToSQL)(table, params.where), relationWhere) : params?.where ? (0, import_relations.relationFilterToSQL)(table, params.where) : relationWhere;
725
+ const order = params?.orderBy ? (0, import_relations.relationsOrderToSQL)(table, params.orderBy) : void 0;
726
+ const columns = this.buildColumns(table, tableConfig, selection, params);
727
+ const extras = params?.extras ? (0, import_relations.relationExtrasToSQL)(table, params.extras) : void 0;
728
+ if (extras)
729
+ selection.push(...extras.selection);
730
+ const selectionArr = [columns];
731
+ const joins = params ? (() => {
732
+ const { with: joins2 } = params;
733
+ if (!joins2)
734
+ return;
735
+ const withEntries = Object.entries(joins2).filter(([_, v]) => v);
736
+ if (!withEntries.length)
737
+ return;
738
+ return import_sql2.sql.join(
739
+ withEntries.map(([k, join]) => {
740
+ if ((0, import_entity.is)(tableConfig.relations[k], import_relations.AggregatedField)) {
741
+ const relation2 = tableConfig.relations[k];
742
+ relation2.onTable(table);
743
+ const query2 = relation2.getSQL();
744
+ selection.push({
745
+ key: k,
746
+ field: relation2
747
+ });
748
+ selectionArr.push(import_sql2.sql`${import_sql2.sql.identifier(k)}.${import_sql2.sql.identifier("r")} as ${import_sql2.sql.identifier(k)}`);
749
+ return import_sql2.sql`left join lateral(${query2}) as ${import_sql2.sql.identifier(k)} on true`;
750
+ }
751
+ const relation = tableConfig.relations[k];
752
+ const isSingle2 = (0, import_entity.is)(relation, import_relations.One);
753
+ const targetTable = relation.targetTable;
754
+ const relationFilter = (0, import_relations.relationToSQL)(relation);
755
+ selectionArr.push(
756
+ isSingle2 ? import_sql2.sql`${import_sql2.sql.identifier(k)}.${import_sql2.sql.identifier("r")} as ${import_sql2.sql.identifier(k)}` : import_sql2.sql`coalesce(${import_sql2.sql.identifier(k)}.${import_sql2.sql.identifier("r")}, '[]') as ${import_sql2.sql.identifier(k)}`
757
+ );
758
+ const innerQuery = this.buildRelationalQuery({
759
+ table: targetTable,
760
+ mode: isSingle2 ? "first" : "many",
761
+ schema,
762
+ queryConfig: join,
763
+ tableConfig: schema[tableNamesMap[(0, import_table2.getTableUniqueName)(targetTable)]],
764
+ tableNamesMap,
765
+ tables,
766
+ relationWhere: relationFilter
767
+ });
768
+ selection.push({
769
+ field: targetTable,
770
+ key: k,
771
+ selection: innerQuery.selection,
772
+ isArray: !isSingle2
773
+ });
774
+ return import_sql2.sql`left join lateral(select ${isSingle2 ? import_sql2.sql`row_to_json(${import_sql2.sql.identifier("t")}.*) ${import_sql2.sql.identifier("r")}` : import_sql2.sql`json_agg(row_to_json(${import_sql2.sql.identifier("t")}.*)) ${import_sql2.sql.identifier("r")}`} from (${innerQuery.sql}) as ${import_sql2.sql.identifier("t")}) as ${import_sql2.sql.identifier(k)} on true`;
775
+ }),
776
+ import_sql2.sql` `
777
+ );
778
+ })() : void 0;
779
+ if (extras?.sql)
780
+ selectionArr.push(extras.sql);
781
+ const selectionSet = import_sql2.sql.join(selectionArr.filter((e) => e !== void 0), import_sql2.sql`, `);
782
+ const query = import_sql2.sql`select ${selectionSet} from ${table}${import_sql2.sql` ${joins}`.if(joins)}${import_sql2.sql` where ${where}`.if(where)}${import_sql2.sql` order by ${order}`.if(order)}${import_sql2.sql` limit ${limit}`.if(limit !== void 0)}${import_sql2.sql` offset ${offset}`.if(offset !== void 0)}`;
783
+ return {
784
+ sql: query,
785
+ selection
786
+ };
787
+ }
1129
788
  }
1130
789
  // Annotate the CommonJS export names for ESM import in node:
1131
790
  0 && (module.exports = {