drizzle-orm 0.38.3-7db411e → 0.38.3-8e428d1

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