drizzle-orm 0.36.4-166fb8d → 0.36.4-3c69a1f

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 (553) hide show
  1. package/_relations.cjs +328 -0
  2. package/_relations.cjs.map +1 -0
  3. package/_relations.d.cts +215 -0
  4. package/_relations.d.ts +215 -0
  5. package/_relations.js +316 -0
  6. package/_relations.js.map +1 -0
  7. package/alias.cjs.map +1 -1
  8. package/alias.d.cts +3 -3
  9. package/alias.d.ts +3 -3
  10. package/alias.js.map +1 -1
  11. package/aws-data-api/pg/driver.cjs +19 -5
  12. package/aws-data-api/pg/driver.cjs.map +1 -1
  13. package/aws-data-api/pg/driver.d.cts +9 -8
  14. package/aws-data-api/pg/driver.d.ts +9 -8
  15. package/aws-data-api/pg/driver.js +9 -8
  16. package/aws-data-api/pg/driver.js.map +1 -1
  17. package/aws-data-api/pg/migrator.cjs.map +1 -1
  18. package/aws-data-api/pg/migrator.d.cts +2 -1
  19. package/aws-data-api/pg/migrator.d.ts +2 -1
  20. package/aws-data-api/pg/migrator.js.map +1 -1
  21. package/aws-data-api/pg/session.cjs +67 -4
  22. package/aws-data-api/pg/session.cjs.map +1 -1
  23. package/aws-data-api/pg/session.d.cts +13 -8
  24. package/aws-data-api/pg/session.d.ts +13 -8
  25. package/aws-data-api/pg/session.js +67 -4
  26. package/aws-data-api/pg/session.js.map +1 -1
  27. package/better-sqlite3/driver.cjs +12 -5
  28. package/better-sqlite3/driver.cjs.map +1 -1
  29. package/better-sqlite3/driver.d.cts +7 -6
  30. package/better-sqlite3/driver.d.ts +7 -6
  31. package/better-sqlite3/driver.js +12 -8
  32. package/better-sqlite3/driver.js.map +1 -1
  33. package/better-sqlite3/migrator.cjs.map +1 -1
  34. package/better-sqlite3/migrator.d.cts +2 -1
  35. package/better-sqlite3/migrator.d.ts +2 -1
  36. package/better-sqlite3/migrator.js.map +1 -1
  37. package/better-sqlite3/session.cjs +49 -4
  38. package/better-sqlite3/session.cjs.map +1 -1
  39. package/better-sqlite3/session.d.cts +14 -8
  40. package/better-sqlite3/session.d.ts +14 -8
  41. package/better-sqlite3/session.js +49 -4
  42. package/better-sqlite3/session.js.map +1 -1
  43. package/bun-sqlite/driver.cjs +22 -5
  44. package/bun-sqlite/driver.cjs.map +1 -1
  45. package/bun-sqlite/driver.d.cts +7 -6
  46. package/bun-sqlite/driver.d.ts +7 -6
  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/d1/driver.cjs +22 -5
  60. package/d1/driver.cjs.map +1 -1
  61. package/d1/driver.d.cts +3 -2
  62. package/d1/driver.d.ts +3 -2
  63. package/d1/driver.js +12 -8
  64. package/d1/driver.js.map +1 -1
  65. package/d1/migrator.cjs.map +1 -1
  66. package/d1/migrator.d.cts +2 -1
  67. package/d1/migrator.d.ts +2 -1
  68. package/d1/migrator.js.map +1 -1
  69. package/d1/session.cjs +48 -6
  70. package/d1/session.cjs.map +1 -1
  71. package/d1/session.d.cts +15 -8
  72. package/d1/session.d.ts +15 -8
  73. package/d1/session.js +48 -6
  74. package/d1/session.js.map +1 -1
  75. package/expo-sqlite/driver.cjs +22 -5
  76. package/expo-sqlite/driver.cjs.map +1 -1
  77. package/expo-sqlite/driver.d.cts +3 -2
  78. package/expo-sqlite/driver.d.ts +3 -2
  79. package/expo-sqlite/driver.js +12 -8
  80. package/expo-sqlite/driver.js.map +1 -1
  81. package/expo-sqlite/migrator.cjs.map +1 -1
  82. package/expo-sqlite/migrator.d.cts +3 -2
  83. package/expo-sqlite/migrator.d.ts +3 -2
  84. package/expo-sqlite/migrator.js.map +1 -1
  85. package/expo-sqlite/query.cjs +13 -2
  86. package/expo-sqlite/query.cjs.map +1 -1
  87. package/expo-sqlite/query.d.cts +2 -1
  88. package/expo-sqlite/query.d.ts +2 -1
  89. package/expo-sqlite/query.js +3 -2
  90. package/expo-sqlite/query.js.map +1 -1
  91. package/expo-sqlite/session.cjs +47 -4
  92. package/expo-sqlite/session.cjs.map +1 -1
  93. package/expo-sqlite/session.d.cts +14 -8
  94. package/expo-sqlite/session.d.ts +14 -8
  95. package/expo-sqlite/session.js +47 -4
  96. package/expo-sqlite/session.js.map +1 -1
  97. package/libsql/driver-core.cjs +22 -5
  98. package/libsql/driver-core.cjs.map +1 -1
  99. package/libsql/driver-core.d.cts +2 -1
  100. package/libsql/driver-core.d.ts +2 -1
  101. package/libsql/driver-core.js +12 -8
  102. package/libsql/driver-core.js.map +1 -1
  103. package/libsql/driver.cjs.map +1 -1
  104. package/libsql/driver.d.cts +6 -5
  105. package/libsql/driver.d.ts +6 -5
  106. package/libsql/driver.js.map +1 -1
  107. package/libsql/http/index.cjs.map +1 -1
  108. package/libsql/http/index.d.cts +6 -5
  109. package/libsql/http/index.d.ts +6 -5
  110. package/libsql/http/index.js.map +1 -1
  111. package/libsql/migrator.cjs.map +1 -1
  112. package/libsql/migrator.d.cts +2 -1
  113. package/libsql/migrator.d.ts +2 -1
  114. package/libsql/migrator.js.map +1 -1
  115. package/libsql/node/index.cjs.map +1 -1
  116. package/libsql/node/index.d.cts +6 -5
  117. package/libsql/node/index.d.ts +6 -5
  118. package/libsql/node/index.js.map +1 -1
  119. package/libsql/session.cjs +60 -4
  120. package/libsql/session.cjs.map +1 -1
  121. package/libsql/session.d.cts +15 -9
  122. package/libsql/session.d.ts +15 -9
  123. package/libsql/session.js +60 -4
  124. package/libsql/session.js.map +1 -1
  125. package/libsql/sqlite3/index.cjs.map +1 -1
  126. package/libsql/sqlite3/index.d.cts +6 -5
  127. package/libsql/sqlite3/index.d.ts +6 -5
  128. package/libsql/sqlite3/index.js.map +1 -1
  129. package/libsql/wasm/index.cjs.map +1 -1
  130. package/libsql/wasm/index.d.cts +6 -5
  131. package/libsql/wasm/index.d.ts +6 -5
  132. package/libsql/wasm/index.js.map +1 -1
  133. package/libsql/web/index.cjs.map +1 -1
  134. package/libsql/web/index.d.cts +6 -5
  135. package/libsql/web/index.d.ts +6 -5
  136. package/libsql/web/index.js.map +1 -1
  137. package/libsql/ws/index.cjs.map +1 -1
  138. package/libsql/ws/index.d.cts +6 -5
  139. package/libsql/ws/index.d.ts +6 -5
  140. package/libsql/ws/index.js.map +1 -1
  141. package/mysql-core/db.cjs +29 -8
  142. package/mysql-core/db.cjs.map +1 -1
  143. package/mysql-core/db.d.cts +15 -8
  144. package/mysql-core/db.d.ts +15 -8
  145. package/mysql-core/db.js +28 -7
  146. package/mysql-core/db.js.map +1 -1
  147. package/mysql-core/dialect.cjs +170 -15
  148. package/mysql-core/dialect.cjs.map +1 -1
  149. package/mysql-core/dialect.d.cts +29 -13
  150. package/mysql-core/dialect.d.ts +29 -13
  151. package/mysql-core/dialect.js +167 -21
  152. package/mysql-core/dialect.js.map +1 -1
  153. package/mysql-core/query-builders/_query.cjs +149 -0
  154. package/mysql-core/query-builders/_query.cjs.map +1 -0
  155. package/mysql-core/query-builders/_query.d.cts +44 -0
  156. package/mysql-core/query-builders/_query.d.ts +44 -0
  157. package/mysql-core/query-builders/_query.js +114 -0
  158. package/mysql-core/query-builders/_query.js.map +1 -0
  159. package/mysql-core/query-builders/count.cjs.map +1 -1
  160. package/mysql-core/query-builders/count.d.cts +1 -1
  161. package/mysql-core/query-builders/count.d.ts +1 -1
  162. package/mysql-core/query-builders/count.js.map +1 -1
  163. package/mysql-core/query-builders/query.cjs +18 -31
  164. package/mysql-core/query-builders/query.cjs.map +1 -1
  165. package/mysql-core/query-builders/query.d.cts +8 -10
  166. package/mysql-core/query-builders/query.d.ts +8 -10
  167. package/mysql-core/query-builders/query.js +18 -31
  168. package/mysql-core/query-builders/query.js.map +1 -1
  169. package/mysql-core/session.cjs +3 -2
  170. package/mysql-core/session.cjs.map +1 -1
  171. package/mysql-core/session.d.cts +10 -7
  172. package/mysql-core/session.d.ts +10 -7
  173. package/mysql-core/session.js +3 -2
  174. package/mysql-core/session.js.map +1 -1
  175. package/mysql-proxy/driver.cjs +22 -5
  176. package/mysql-proxy/driver.cjs.map +1 -1
  177. package/mysql-proxy/driver.d.cts +3 -2
  178. package/mysql-proxy/driver.d.ts +3 -2
  179. package/mysql-proxy/driver.js +12 -8
  180. package/mysql-proxy/driver.js.map +1 -1
  181. package/mysql-proxy/migrator.cjs.map +1 -1
  182. package/mysql-proxy/migrator.d.cts +2 -1
  183. package/mysql-proxy/migrator.d.ts +2 -1
  184. package/mysql-proxy/migrator.js.map +1 -1
  185. package/mysql-proxy/session.cjs +47 -2
  186. package/mysql-proxy/session.cjs.map +1 -1
  187. package/mysql-proxy/session.d.cts +13 -8
  188. package/mysql-proxy/session.d.ts +13 -8
  189. package/mysql-proxy/session.js +47 -2
  190. package/mysql-proxy/session.js.map +1 -1
  191. package/mysql2/driver.cjs +24 -7
  192. package/mysql2/driver.cjs.map +1 -1
  193. package/mysql2/driver.d.cts +10 -9
  194. package/mysql2/driver.d.ts +10 -9
  195. package/mysql2/driver.js +14 -10
  196. package/mysql2/driver.js.map +1 -1
  197. package/mysql2/migrator.cjs.map +1 -1
  198. package/mysql2/migrator.d.cts +2 -1
  199. package/mysql2/migrator.d.ts +2 -1
  200. package/mysql2/migrator.js.map +1 -1
  201. package/mysql2/session.cjs +51 -2
  202. package/mysql2/session.cjs.map +1 -1
  203. package/mysql2/session.d.cts +13 -8
  204. package/mysql2/session.d.ts +13 -8
  205. package/mysql2/session.js +51 -2
  206. package/mysql2/session.js.map +1 -1
  207. package/neon-http/driver.cjs +21 -7
  208. package/neon-http/driver.cjs.map +1 -1
  209. package/neon-http/driver.d.cts +10 -9
  210. package/neon-http/driver.d.ts +10 -9
  211. package/neon-http/driver.js +11 -7
  212. package/neon-http/driver.js.map +1 -1
  213. package/neon-http/migrator.cjs.map +1 -1
  214. package/neon-http/migrator.d.cts +2 -1
  215. package/neon-http/migrator.d.ts +2 -1
  216. package/neon-http/migrator.js.map +1 -1
  217. package/neon-http/session.cjs +32 -2
  218. package/neon-http/session.cjs.map +1 -1
  219. package/neon-http/session.d.cts +13 -8
  220. package/neon-http/session.d.ts +13 -8
  221. package/neon-http/session.js +32 -2
  222. package/neon-http/session.js.map +1 -1
  223. package/neon-serverless/driver.cjs +18 -7
  224. package/neon-serverless/driver.cjs.map +1 -1
  225. package/neon-serverless/driver.d.cts +9 -8
  226. package/neon-serverless/driver.d.ts +9 -8
  227. package/neon-serverless/driver.js +8 -10
  228. package/neon-serverless/driver.js.map +1 -1
  229. package/neon-serverless/migrator.cjs.map +1 -1
  230. package/neon-serverless/migrator.d.cts +2 -1
  231. package/neon-serverless/migrator.d.ts +2 -1
  232. package/neon-serverless/migrator.js.map +1 -1
  233. package/neon-serverless/session.cjs +40 -5
  234. package/neon-serverless/session.cjs.map +1 -1
  235. package/neon-serverless/session.d.cts +13 -8
  236. package/neon-serverless/session.d.ts +13 -8
  237. package/neon-serverless/session.js +40 -5
  238. package/neon-serverless/session.js.map +1 -1
  239. package/node-postgres/driver.cjs +13 -7
  240. package/node-postgres/driver.cjs.map +1 -1
  241. package/node-postgres/driver.d.cts +9 -8
  242. package/node-postgres/driver.d.ts +9 -8
  243. package/node-postgres/driver.js +13 -10
  244. package/node-postgres/driver.js.map +1 -1
  245. package/node-postgres/migrator.cjs.map +1 -1
  246. package/node-postgres/migrator.d.cts +2 -1
  247. package/node-postgres/migrator.d.ts +2 -1
  248. package/node-postgres/migrator.js.map +1 -1
  249. package/node-postgres/session.cjs +45 -4
  250. package/node-postgres/session.cjs.map +1 -1
  251. package/node-postgres/session.d.cts +13 -8
  252. package/node-postgres/session.d.ts +13 -8
  253. package/node-postgres/session.js +45 -4
  254. package/node-postgres/session.js.map +1 -1
  255. package/op-sqlite/driver.cjs +22 -5
  256. package/op-sqlite/driver.cjs.map +1 -1
  257. package/op-sqlite/driver.d.cts +3 -2
  258. package/op-sqlite/driver.d.ts +3 -2
  259. package/op-sqlite/driver.js +12 -8
  260. package/op-sqlite/driver.js.map +1 -1
  261. package/op-sqlite/migrator.cjs.map +1 -1
  262. package/op-sqlite/migrator.d.cts +3 -2
  263. package/op-sqlite/migrator.d.ts +3 -2
  264. package/op-sqlite/migrator.js.map +1 -1
  265. package/op-sqlite/session.cjs +47 -4
  266. package/op-sqlite/session.cjs.map +1 -1
  267. package/op-sqlite/session.d.cts +14 -8
  268. package/op-sqlite/session.d.ts +14 -8
  269. package/op-sqlite/session.js +47 -4
  270. package/op-sqlite/session.js.map +1 -1
  271. package/package.json +63 -15
  272. package/pg-core/db.cjs +31 -7
  273. package/pg-core/db.cjs.map +1 -1
  274. package/pg-core/db.d.cts +16 -9
  275. package/pg-core/db.d.ts +16 -9
  276. package/pg-core/db.js +30 -6
  277. package/pg-core/db.js.map +1 -1
  278. package/pg-core/dialect.cjs +146 -488
  279. package/pg-core/dialect.cjs.map +1 -1
  280. package/pg-core/dialect.d.cts +21 -7
  281. package/pg-core/dialect.d.ts +21 -7
  282. package/pg-core/dialect.js +143 -494
  283. package/pg-core/dialect.js.map +1 -1
  284. package/pg-core/query-builders/_query.cjs +155 -0
  285. package/pg-core/query-builders/_query.cjs.map +1 -0
  286. package/pg-core/query-builders/_query.d.cts +47 -0
  287. package/pg-core/query-builders/_query.d.ts +47 -0
  288. package/pg-core/query-builders/_query.js +120 -0
  289. package/pg-core/query-builders/_query.js.map +1 -0
  290. package/pg-core/query-builders/count.cjs.map +1 -1
  291. package/pg-core/query-builders/count.d.cts +1 -1
  292. package/pg-core/query-builders/count.d.ts +1 -1
  293. package/pg-core/query-builders/count.js.map +1 -1
  294. package/pg-core/query-builders/query.cjs +15 -18
  295. package/pg-core/query-builders/query.cjs.map +1 -1
  296. package/pg-core/query-builders/query.d.cts +6 -6
  297. package/pg-core/query-builders/query.d.ts +6 -6
  298. package/pg-core/query-builders/query.js +15 -18
  299. package/pg-core/query-builders/query.js.map +1 -1
  300. package/pg-core/session.cjs +3 -2
  301. package/pg-core/session.cjs.map +1 -1
  302. package/pg-core/session.d.cts +9 -6
  303. package/pg-core/session.d.ts +9 -6
  304. package/pg-core/session.js +3 -2
  305. package/pg-core/session.js.map +1 -1
  306. package/pg-proxy/driver.cjs +21 -5
  307. package/pg-proxy/driver.cjs.map +1 -1
  308. package/pg-proxy/driver.d.cts +3 -2
  309. package/pg-proxy/driver.d.ts +3 -2
  310. package/pg-proxy/driver.js +11 -8
  311. package/pg-proxy/driver.js.map +1 -1
  312. package/pg-proxy/migrator.cjs.map +1 -1
  313. package/pg-proxy/migrator.d.cts +2 -1
  314. package/pg-proxy/migrator.d.ts +2 -1
  315. package/pg-proxy/migrator.js.map +1 -1
  316. package/pg-proxy/session.cjs +37 -2
  317. package/pg-proxy/session.cjs.map +1 -1
  318. package/pg-proxy/session.d.cts +13 -8
  319. package/pg-proxy/session.d.ts +13 -8
  320. package/pg-proxy/session.js +37 -2
  321. package/pg-proxy/session.js.map +1 -1
  322. package/pglite/driver.cjs +23 -7
  323. package/pglite/driver.cjs.map +1 -1
  324. package/pglite/driver.d.cts +9 -8
  325. package/pglite/driver.d.ts +9 -8
  326. package/pglite/driver.js +13 -10
  327. package/pglite/driver.js.map +1 -1
  328. package/pglite/migrator.cjs.map +1 -1
  329. package/pglite/migrator.d.cts +2 -1
  330. package/pglite/migrator.d.ts +2 -1
  331. package/pglite/migrator.js.map +1 -1
  332. package/pglite/session.cjs +34 -3
  333. package/pglite/session.cjs.map +1 -1
  334. package/pglite/session.d.cts +13 -8
  335. package/pglite/session.d.ts +13 -8
  336. package/pglite/session.js +34 -3
  337. package/pglite/session.js.map +1 -1
  338. package/planetscale-serverless/driver.cjs +22 -5
  339. package/planetscale-serverless/driver.cjs.map +1 -1
  340. package/planetscale-serverless/driver.d.cts +7 -6
  341. package/planetscale-serverless/driver.d.ts +7 -6
  342. package/planetscale-serverless/driver.js +12 -8
  343. package/planetscale-serverless/driver.js.map +1 -1
  344. package/planetscale-serverless/migrator.cjs.map +1 -1
  345. package/planetscale-serverless/migrator.d.cts +2 -1
  346. package/planetscale-serverless/migrator.d.ts +2 -1
  347. package/planetscale-serverless/migrator.js.map +1 -1
  348. package/planetscale-serverless/session.cjs +68 -5
  349. package/planetscale-serverless/session.cjs.map +1 -1
  350. package/planetscale-serverless/session.d.cts +14 -9
  351. package/planetscale-serverless/session.d.ts +14 -9
  352. package/planetscale-serverless/session.js +68 -5
  353. package/planetscale-serverless/session.js.map +1 -1
  354. package/postgres-js/driver.cjs +12 -6
  355. package/postgres-js/driver.cjs.map +1 -1
  356. package/postgres-js/driver.d.cts +7 -6
  357. package/postgres-js/driver.d.ts +7 -6
  358. package/postgres-js/driver.js +12 -9
  359. package/postgres-js/driver.js.map +1 -1
  360. package/postgres-js/migrator.cjs.map +1 -1
  361. package/postgres-js/migrator.d.cts +2 -1
  362. package/postgres-js/migrator.d.ts +2 -1
  363. package/postgres-js/migrator.js.map +1 -1
  364. package/postgres-js/session.cjs +51 -6
  365. package/postgres-js/session.cjs.map +1 -1
  366. package/postgres-js/session.d.cts +15 -9
  367. package/postgres-js/session.d.ts +15 -9
  368. package/postgres-js/session.js +51 -6
  369. package/postgres-js/session.js.map +1 -1
  370. package/prisma/mysql/driver.cjs +1 -1
  371. package/prisma/mysql/driver.cjs.map +1 -1
  372. package/prisma/mysql/driver.js +1 -1
  373. package/prisma/mysql/driver.js.map +1 -1
  374. package/prisma/mysql/session.cjs +3 -0
  375. package/prisma/mysql/session.cjs.map +1 -1
  376. package/prisma/mysql/session.d.cts +3 -1
  377. package/prisma/mysql/session.d.ts +3 -1
  378. package/prisma/mysql/session.js +3 -0
  379. package/prisma/mysql/session.js.map +1 -1
  380. package/prisma/pg/driver.cjs +1 -1
  381. package/prisma/pg/driver.cjs.map +1 -1
  382. package/prisma/pg/driver.js +1 -1
  383. package/prisma/pg/driver.js.map +1 -1
  384. package/prisma/pg/session.cjs +3 -0
  385. package/prisma/pg/session.cjs.map +1 -1
  386. package/prisma/pg/session.d.cts +3 -1
  387. package/prisma/pg/session.d.ts +3 -1
  388. package/prisma/pg/session.js +3 -0
  389. package/prisma/pg/session.js.map +1 -1
  390. package/prisma/sqlite/driver.cjs +1 -1
  391. package/prisma/sqlite/driver.cjs.map +1 -1
  392. package/prisma/sqlite/driver.js +1 -1
  393. package/prisma/sqlite/driver.js.map +1 -1
  394. package/prisma/sqlite/session.cjs +3 -0
  395. package/prisma/sqlite/session.cjs.map +1 -1
  396. package/prisma/sqlite/session.d.cts +4 -2
  397. package/prisma/sqlite/session.d.ts +4 -2
  398. package/prisma/sqlite/session.js +3 -0
  399. package/prisma/sqlite/session.js.map +1 -1
  400. package/relations.cjs +468 -245
  401. package/relations.cjs.map +1 -1
  402. package/relations.d.cts +264 -125
  403. package/relations.d.ts +264 -125
  404. package/relations.js +455 -238
  405. package/relations.js.map +1 -1
  406. package/sql/sql.cjs.map +1 -1
  407. package/sql/sql.d.cts +4 -4
  408. package/sql/sql.d.ts +4 -4
  409. package/sql/sql.js.map +1 -1
  410. package/sql-js/driver.cjs +16 -5
  411. package/sql-js/driver.cjs.map +1 -1
  412. package/sql-js/driver.d.cts +3 -2
  413. package/sql-js/driver.d.ts +3 -2
  414. package/sql-js/driver.js +6 -8
  415. package/sql-js/driver.js.map +1 -1
  416. package/sql-js/migrator.cjs.map +1 -1
  417. package/sql-js/migrator.d.cts +2 -1
  418. package/sql-js/migrator.d.ts +2 -1
  419. package/sql-js/migrator.js.map +1 -1
  420. package/sql-js/session.cjs +58 -4
  421. package/sql-js/session.cjs.map +1 -1
  422. package/sql-js/session.d.cts +14 -8
  423. package/sql-js/session.d.ts +14 -8
  424. package/sql-js/session.js +58 -4
  425. package/sql-js/session.js.map +1 -1
  426. package/sqlite-core/db.cjs +35 -14
  427. package/sqlite-core/db.cjs.map +1 -1
  428. package/sqlite-core/db.d.cts +15 -8
  429. package/sqlite-core/db.d.ts +15 -8
  430. package/sqlite-core/db.js +34 -13
  431. package/sqlite-core/db.js.map +1 -1
  432. package/sqlite-core/dialect.cjs +164 -7
  433. package/sqlite-core/dialect.cjs.map +1 -1
  434. package/sqlite-core/dialect.d.cts +25 -9
  435. package/sqlite-core/dialect.d.ts +25 -9
  436. package/sqlite-core/dialect.js +161 -13
  437. package/sqlite-core/dialect.js.map +1 -1
  438. package/sqlite-core/query-builders/_query.cjs +187 -0
  439. package/sqlite-core/query-builders/_query.cjs.map +1 -0
  440. package/sqlite-core/query-builders/_query.d.cts +55 -0
  441. package/sqlite-core/query-builders/_query.d.ts +55 -0
  442. package/sqlite-core/query-builders/_query.js +151 -0
  443. package/sqlite-core/query-builders/_query.js.map +1 -0
  444. package/sqlite-core/query-builders/count.cjs.map +1 -1
  445. package/sqlite-core/query-builders/count.d.cts +1 -1
  446. package/sqlite-core/query-builders/count.d.ts +1 -1
  447. package/sqlite-core/query-builders/count.js.map +1 -1
  448. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  449. package/sqlite-core/query-builders/delete.d.cts +1 -1
  450. package/sqlite-core/query-builders/delete.d.ts +1 -1
  451. package/sqlite-core/query-builders/delete.js.map +1 -1
  452. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  453. package/sqlite-core/query-builders/insert.d.cts +3 -3
  454. package/sqlite-core/query-builders/insert.d.ts +3 -3
  455. package/sqlite-core/query-builders/insert.js.map +1 -1
  456. package/sqlite-core/query-builders/query.cjs +30 -48
  457. package/sqlite-core/query-builders/query.cjs.map +1 -1
  458. package/sqlite-core/query-builders/query.d.cts +14 -16
  459. package/sqlite-core/query-builders/query.d.ts +14 -16
  460. package/sqlite-core/query-builders/query.js +30 -48
  461. package/sqlite-core/query-builders/query.js.map +1 -1
  462. package/sqlite-core/query-builders/select.cjs.map +1 -1
  463. package/sqlite-core/query-builders/select.d.cts +3 -3
  464. package/sqlite-core/query-builders/select.d.ts +3 -3
  465. package/sqlite-core/query-builders/select.js.map +1 -1
  466. package/sqlite-core/query-builders/update.cjs.map +1 -1
  467. package/sqlite-core/query-builders/update.d.cts +3 -3
  468. package/sqlite-core/query-builders/update.d.ts +3 -3
  469. package/sqlite-core/query-builders/update.js.map +1 -1
  470. package/sqlite-core/session.cjs +6 -2
  471. package/sqlite-core/session.cjs.map +1 -1
  472. package/sqlite-core/session.d.cts +14 -6
  473. package/sqlite-core/session.d.ts +14 -6
  474. package/sqlite-core/session.js +6 -2
  475. package/sqlite-core/session.js.map +1 -1
  476. package/sqlite-proxy/driver.cjs +22 -5
  477. package/sqlite-proxy/driver.cjs.map +1 -1
  478. package/sqlite-proxy/driver.d.cts +4 -3
  479. package/sqlite-proxy/driver.d.ts +4 -3
  480. package/sqlite-proxy/driver.js +12 -5
  481. package/sqlite-proxy/driver.js.map +1 -1
  482. package/sqlite-proxy/migrator.cjs.map +1 -1
  483. package/sqlite-proxy/migrator.d.cts +2 -1
  484. package/sqlite-proxy/migrator.d.ts +2 -1
  485. package/sqlite-proxy/migrator.js.map +1 -1
  486. package/sqlite-proxy/session.cjs +47 -4
  487. package/sqlite-proxy/session.cjs.map +1 -1
  488. package/sqlite-proxy/session.d.cts +14 -8
  489. package/sqlite-proxy/session.d.ts +14 -8
  490. package/sqlite-proxy/session.js +47 -4
  491. package/sqlite-proxy/session.js.map +1 -1
  492. package/table.cjs.map +1 -1
  493. package/table.d.cts +1 -1
  494. package/table.d.ts +1 -1
  495. package/table.js.map +1 -1
  496. package/tidb-serverless/driver.cjs +22 -5
  497. package/tidb-serverless/driver.cjs.map +1 -1
  498. package/tidb-serverless/driver.d.cts +7 -6
  499. package/tidb-serverless/driver.d.ts +7 -6
  500. package/tidb-serverless/driver.js +12 -8
  501. package/tidb-serverless/driver.js.map +1 -1
  502. package/tidb-serverless/migrator.cjs.map +1 -1
  503. package/tidb-serverless/migrator.d.cts +2 -1
  504. package/tidb-serverless/migrator.d.ts +2 -1
  505. package/tidb-serverless/migrator.js.map +1 -1
  506. package/tidb-serverless/session.cjs +62 -5
  507. package/tidb-serverless/session.cjs.map +1 -1
  508. package/tidb-serverless/session.d.cts +14 -9
  509. package/tidb-serverless/session.d.ts +14 -9
  510. package/tidb-serverless/session.js +62 -5
  511. package/tidb-serverless/session.js.map +1 -1
  512. package/utils.cjs +2 -2
  513. package/utils.cjs.map +1 -1
  514. package/utils.d.cts +3 -1
  515. package/utils.d.ts +3 -1
  516. package/utils.js +2 -2
  517. package/utils.js.map +1 -1
  518. package/vercel-postgres/driver.cjs +23 -7
  519. package/vercel-postgres/driver.cjs.map +1 -1
  520. package/vercel-postgres/driver.d.cts +9 -8
  521. package/vercel-postgres/driver.d.ts +9 -8
  522. package/vercel-postgres/driver.js +13 -10
  523. package/vercel-postgres/driver.js.map +1 -1
  524. package/vercel-postgres/migrator.cjs.map +1 -1
  525. package/vercel-postgres/migrator.d.cts +2 -1
  526. package/vercel-postgres/migrator.d.ts +2 -1
  527. package/vercel-postgres/migrator.js.map +1 -1
  528. package/vercel-postgres/session.cjs +34 -4
  529. package/vercel-postgres/session.cjs.map +1 -1
  530. package/vercel-postgres/session.d.cts +13 -8
  531. package/vercel-postgres/session.d.ts +13 -8
  532. package/vercel-postgres/session.js +34 -4
  533. package/vercel-postgres/session.js.map +1 -1
  534. package/version.cjs +1 -1
  535. package/version.d.cts +1 -1
  536. package/version.d.ts +1 -1
  537. package/version.js +1 -1
  538. package/xata-http/driver.cjs +17 -5
  539. package/xata-http/driver.cjs.map +1 -1
  540. package/xata-http/driver.d.cts +5 -4
  541. package/xata-http/driver.d.ts +5 -4
  542. package/xata-http/driver.js +7 -5
  543. package/xata-http/driver.js.map +1 -1
  544. package/xata-http/migrator.cjs.map +1 -1
  545. package/xata-http/migrator.d.cts +2 -1
  546. package/xata-http/migrator.d.ts +2 -1
  547. package/xata-http/migrator.js.map +1 -1
  548. package/xata-http/session.cjs +30 -2
  549. package/xata-http/session.cjs.map +1 -1
  550. package/xata-http/session.d.cts +13 -8
  551. package/xata-http/session.d.ts +13 -8
  552. package/xata-http/session.js +30 -2
  553. package/xata-http/session.js.map +1 -1
@@ -1,6 +1,7 @@
1
+ import * as V1 from "../_relations.cjs";
1
2
  import { entityKind } from "../entity.cjs";
2
3
  import type { MigrationConfig, MigrationMeta } from "../migrator.cjs";
3
- import { type BuildRelationalQueryResult, type DBQueryConfig, type Relation, type TableRelationalConfig, type TablesRelationalConfig } from "../relations.cjs";
4
+ import type { BuildRelationalQueryResult, DBQueryConfig, TableRelationalConfig, TablesRelationalConfig } from "../relations.cjs";
4
5
  import { SQL } from "../sql/sql.cjs";
5
6
  import type { QueryWithTypings } from "../sql/sql.cjs";
6
7
  import { type Casing, type UpdateSet } from "../utils.cjs";
@@ -50,26 +51,41 @@ export declare class MySqlDialect {
50
51
  generatedIds: Record<string, unknown>[];
51
52
  };
52
53
  sqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings;
53
- buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
54
+ /** @deprecated */
55
+ _buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
54
56
  fullSchema: Record<string, unknown>;
55
- schema: TablesRelationalConfig;
57
+ schema: V1.TablesRelationalConfig;
56
58
  tableNamesMap: Record<string, string>;
57
59
  table: MySqlTable;
58
- tableConfig: TableRelationalConfig;
59
- queryConfig: true | DBQueryConfig<'many', true>;
60
+ tableConfig: V1.TableRelationalConfig;
61
+ queryConfig: true | V1.DBQueryConfig<'many', true>;
60
62
  tableAlias: string;
61
- nestedQueryRelation?: Relation;
63
+ nestedQueryRelation?: V1.Relation;
62
64
  joinOn?: SQL;
63
- }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
64
- buildRelationalQueryWithoutLateralSubqueries({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
65
+ }): V1.BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
66
+ /** @deprecated */
67
+ _buildRelationalQueryWithoutLateralSubqueries({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
65
68
  fullSchema: Record<string, unknown>;
66
- schema: TablesRelationalConfig;
69
+ schema: V1.TablesRelationalConfig;
67
70
  tableNamesMap: Record<string, string>;
68
71
  table: MySqlTable;
69
- tableConfig: TableRelationalConfig;
70
- queryConfig: true | DBQueryConfig<'many', true>;
72
+ tableConfig: V1.TableRelationalConfig;
73
+ queryConfig: true | V1.DBQueryConfig<'many', true>;
71
74
  tableAlias: string;
72
- nestedQueryRelation?: Relation;
75
+ nestedQueryRelation?: V1.Relation;
73
76
  joinOn?: SQL;
74
- }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
77
+ }): V1.BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
78
+ private unwrapAllColumns;
79
+ private getSelectedTableColumns;
80
+ private buildColumns;
81
+ buildRelationalQuery({ tables, schema, tableNamesMap, table, tableConfig, queryConfig: config, relationWhere, mode, }: {
82
+ tables: Record<string, MySqlTable>;
83
+ schema: TablesRelationalConfig;
84
+ tableNamesMap: Record<string, string>;
85
+ table: MySqlTable;
86
+ tableConfig: TableRelationalConfig;
87
+ queryConfig?: DBQueryConfig<'many'> | true;
88
+ relationWhere?: SQL;
89
+ mode: 'first' | 'many';
90
+ }): BuildRelationalQueryResult;
75
91
  }
@@ -1,6 +1,7 @@
1
+ import * as V1 from "../_relations.js";
1
2
  import { entityKind } from "../entity.js";
2
3
  import type { MigrationConfig, MigrationMeta } from "../migrator.js";
3
- import { type BuildRelationalQueryResult, type DBQueryConfig, type Relation, type TableRelationalConfig, type TablesRelationalConfig } from "../relations.js";
4
+ import type { BuildRelationalQueryResult, DBQueryConfig, TableRelationalConfig, TablesRelationalConfig } from "../relations.js";
4
5
  import { SQL } from "../sql/sql.js";
5
6
  import type { QueryWithTypings } from "../sql/sql.js";
6
7
  import { type Casing, type UpdateSet } from "../utils.js";
@@ -50,26 +51,41 @@ export declare class MySqlDialect {
50
51
  generatedIds: Record<string, unknown>[];
51
52
  };
52
53
  sqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings;
53
- buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
54
+ /** @deprecated */
55
+ _buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
54
56
  fullSchema: Record<string, unknown>;
55
- schema: TablesRelationalConfig;
57
+ schema: V1.TablesRelationalConfig;
56
58
  tableNamesMap: Record<string, string>;
57
59
  table: MySqlTable;
58
- tableConfig: TableRelationalConfig;
59
- queryConfig: true | DBQueryConfig<'many', true>;
60
+ tableConfig: V1.TableRelationalConfig;
61
+ queryConfig: true | V1.DBQueryConfig<'many', true>;
60
62
  tableAlias: string;
61
- nestedQueryRelation?: Relation;
63
+ nestedQueryRelation?: V1.Relation;
62
64
  joinOn?: SQL;
63
- }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
64
- buildRelationalQueryWithoutLateralSubqueries({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
65
+ }): V1.BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
66
+ /** @deprecated */
67
+ _buildRelationalQueryWithoutLateralSubqueries({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
65
68
  fullSchema: Record<string, unknown>;
66
- schema: TablesRelationalConfig;
69
+ schema: V1.TablesRelationalConfig;
67
70
  tableNamesMap: Record<string, string>;
68
71
  table: MySqlTable;
69
- tableConfig: TableRelationalConfig;
70
- queryConfig: true | DBQueryConfig<'many', true>;
72
+ tableConfig: V1.TableRelationalConfig;
73
+ queryConfig: true | V1.DBQueryConfig<'many', true>;
71
74
  tableAlias: string;
72
- nestedQueryRelation?: Relation;
75
+ nestedQueryRelation?: V1.Relation;
73
76
  joinOn?: SQL;
74
- }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
77
+ }): V1.BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
78
+ private unwrapAllColumns;
79
+ private getSelectedTableColumns;
80
+ private buildColumns;
81
+ buildRelationalQuery({ tables, schema, tableNamesMap, table, tableConfig, queryConfig: config, relationWhere, mode, }: {
82
+ tables: Record<string, MySqlTable>;
83
+ schema: TablesRelationalConfig;
84
+ tableNamesMap: Record<string, string>;
85
+ table: MySqlTable;
86
+ tableConfig: TableRelationalConfig;
87
+ queryConfig?: DBQueryConfig<'many'> | true;
88
+ relationWhere?: SQL;
89
+ mode: 'first' | 'many';
90
+ }): BuildRelationalQueryResult;
75
91
  }
@@ -1,3 +1,4 @@
1
+ import * as V1 from "../_relations.js";
1
2
  import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from "../alias.js";
2
3
  import { CasingCache } from "../casing.js";
3
4
  import { Column } from "../column.js";
@@ -5,15 +6,16 @@ import { entityKind, is } from "../entity.js";
5
6
  import { DrizzleError } from "../errors.js";
6
7
  import { and, eq } from "../expressions.js";
7
8
  import {
8
- getOperators,
9
- getOrderByOperators,
10
- Many,
11
- normalizeRelation,
12
- One
9
+ AggregatedField,
10
+ One,
11
+ relationExtrasToSQL,
12
+ relationFilterToSQL,
13
+ relationsOrderToSQL,
14
+ relationToSQL
13
15
  } from "../relations.js";
14
16
  import { Param, SQL, sql, View } from "../sql/sql.js";
15
17
  import { Subquery } from "../subquery.js";
16
- import { getTableName, getTableUniqueName, Table } from "../table.js";
18
+ import { Columns, getTableName, getTableUniqueName, Table } from "../table.js";
17
19
  import { orderSelectedFields } from "../utils.js";
18
20
  import { ViewBaseConfig } from "../view-common.js";
19
21
  import { MySqlColumn } from "./columns/common.js";
@@ -369,7 +371,8 @@ class MySqlDialect {
369
371
  invokeSource
370
372
  });
371
373
  }
372
- buildRelationalQuery({
374
+ /** @deprecated */
375
+ _buildRelationalQuery({
373
376
  fullSchema,
374
377
  schema,
375
378
  tableNamesMap,
@@ -398,7 +401,7 @@ class MySqlDialect {
398
401
  Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)])
399
402
  );
400
403
  if (config.where) {
401
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
404
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
402
405
  where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
403
406
  }
404
407
  const fieldsSelection = [];
@@ -450,7 +453,7 @@ class MySqlDialect {
450
453
  selection: []
451
454
  });
452
455
  }
453
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
456
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
454
457
  if (!Array.isArray(orderByOrig)) {
455
458
  orderByOrig = [orderByOrig];
456
459
  }
@@ -467,7 +470,7 @@ class MySqlDialect {
467
470
  queryConfig: selectedRelationConfigValue,
468
471
  relation
469
472
  } of selectedRelations) {
470
- const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
473
+ const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
471
474
  const relationTableName = getTableUniqueName(relation.referencedTable);
472
475
  const relationTableTsName = tableNamesMap[relationTableName];
473
476
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -479,13 +482,13 @@ class MySqlDialect {
479
482
  )
480
483
  )
481
484
  );
482
- const builtRelation = this.buildRelationalQuery({
485
+ const builtRelation = this._buildRelationalQuery({
483
486
  fullSchema,
484
487
  schema,
485
488
  tableNamesMap,
486
489
  table: fullSchema[relationTableTsName],
487
490
  tableConfig: schema[relationTableTsName],
488
- queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
491
+ queryConfig: is(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
489
492
  tableAlias: relationTableAlias,
490
493
  joinOn: joinOn2,
491
494
  nestedQueryRelation: relation
@@ -520,7 +523,7 @@ class MySqlDialect {
520
523
  ),
521
524
  sql`, `
522
525
  )})`;
523
- if (is(nestedQueryRelation, Many)) {
526
+ if (is(nestedQueryRelation, V1.Many)) {
524
527
  field = sql`coalesce(json_arrayagg(${field}), json_array())`;
525
528
  }
526
529
  const nestedSelection = [{
@@ -594,7 +597,8 @@ class MySqlDialect {
594
597
  selection
595
598
  };
596
599
  }
597
- buildRelationalQueryWithoutLateralSubqueries({
600
+ /** @deprecated */
601
+ _buildRelationalQueryWithoutLateralSubqueries({
598
602
  fullSchema,
599
603
  schema,
600
604
  tableNamesMap,
@@ -622,7 +626,7 @@ class MySqlDialect {
622
626
  Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)])
623
627
  );
624
628
  if (config.where) {
625
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
629
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
626
630
  where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
627
631
  }
628
632
  const fieldsSelection = [];
@@ -674,7 +678,7 @@ class MySqlDialect {
674
678
  selection: []
675
679
  });
676
680
  }
677
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
681
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
678
682
  if (!Array.isArray(orderByOrig)) {
679
683
  orderByOrig = [orderByOrig];
680
684
  }
@@ -691,7 +695,7 @@ class MySqlDialect {
691
695
  queryConfig: selectedRelationConfigValue,
692
696
  relation
693
697
  } of selectedRelations) {
694
- const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
698
+ const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
695
699
  const relationTableName = getTableUniqueName(relation.referencedTable);
696
700
  const relationTableTsName = tableNamesMap[relationTableName];
697
701
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -703,19 +707,19 @@ class MySqlDialect {
703
707
  )
704
708
  )
705
709
  );
706
- const builtRelation = this.buildRelationalQueryWithoutLateralSubqueries({
710
+ const builtRelation = this._buildRelationalQueryWithoutLateralSubqueries({
707
711
  fullSchema,
708
712
  schema,
709
713
  tableNamesMap,
710
714
  table: fullSchema[relationTableTsName],
711
715
  tableConfig: schema[relationTableTsName],
712
- queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
716
+ queryConfig: is(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
713
717
  tableAlias: relationTableAlias,
714
718
  joinOn: joinOn2,
715
719
  nestedQueryRelation: relation
716
720
  });
717
721
  let fieldSql = sql`(${builtRelation.sql})`;
718
- if (is(relation, Many)) {
722
+ if (is(relation, V1.Many)) {
719
723
  fieldSql = sql`coalesce(${fieldSql}, json_array())`;
720
724
  }
721
725
  const field = fieldSql.as(selectedRelationTsKey);
@@ -743,7 +747,7 @@ class MySqlDialect {
743
747
  ),
744
748
  sql`, `
745
749
  )})`;
746
- if (is(nestedQueryRelation, Many)) {
750
+ if (is(nestedQueryRelation, V1.Many)) {
747
751
  field = sql`json_arrayagg(${field})`;
748
752
  }
749
753
  const nestedSelection = [{
@@ -815,6 +819,148 @@ class MySqlDialect {
815
819
  selection
816
820
  };
817
821
  }
822
+ unwrapAllColumns = (table, selection) => {
823
+ return sql.join(
824
+ Object.entries(table[Columns]).map(([k, v]) => {
825
+ selection.push({
826
+ key: k,
827
+ field: v
828
+ });
829
+ return sql`${v} as ${sql.identifier(k)}`;
830
+ }),
831
+ sql`, `
832
+ );
833
+ };
834
+ getSelectedTableColumns = (table, columns) => {
835
+ const selectedColumns = [];
836
+ if (!columns) {
837
+ for (const [k, v] of Object.entries(table[Columns])) {
838
+ selectedColumns.push({
839
+ column: v,
840
+ tsName: k
841
+ });
842
+ }
843
+ return selectedColumns;
844
+ }
845
+ const entries = Object.entries(columns);
846
+ let colSelectionMode;
847
+ for (const [k, v] of entries) {
848
+ if (colSelectionMode === void 0)
849
+ colSelectionMode = v;
850
+ else if (v !== void 0 && colSelectionMode !== v) {
851
+ throw new Error("Columns cannot be both true and false at the same time");
852
+ }
853
+ if (v) {
854
+ selectedColumns.push({
855
+ column: table[Columns][k],
856
+ tsName: k
857
+ });
858
+ }
859
+ }
860
+ if (colSelectionMode === false) {
861
+ for (const [k, v] of Object.entries(table[Columns])) {
862
+ if (columns[k] === false)
863
+ continue;
864
+ selectedColumns.push({
865
+ column: v,
866
+ tsName: k
867
+ });
868
+ }
869
+ }
870
+ return selectedColumns;
871
+ };
872
+ buildColumns = (table, selection, params) => params?.columns ? (() => {
873
+ const columnIdentifiers = [];
874
+ const selectedColumns = this.getSelectedTableColumns(table, params?.columns);
875
+ for (const column of selectedColumns) {
876
+ columnIdentifiers.push(
877
+ sql`${table[column.tsName]} as ${sql.identifier(column.tsName)}`
878
+ );
879
+ }
880
+ return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : this.unwrapAllColumns(table, selection);
881
+ })() : (() => {
882
+ const columnIdentifiers = [this.unwrapAllColumns(table, selection)];
883
+ return sql.join(columnIdentifiers, sql`, `);
884
+ })();
885
+ buildRelationalQuery({
886
+ tables,
887
+ schema,
888
+ tableNamesMap,
889
+ table,
890
+ tableConfig,
891
+ queryConfig: config,
892
+ relationWhere,
893
+ mode
894
+ }) {
895
+ const selection = [];
896
+ const isSingle = mode === "first";
897
+ const params = config === true ? void 0 : config;
898
+ const limit = isSingle ? 1 : params?.limit;
899
+ const offset = params?.offset;
900
+ const columns = this.buildColumns(table, selection, params);
901
+ const where = params?.where && relationWhere ? and(relationFilterToSQL(table, params.where), relationWhere) : params?.where ? relationFilterToSQL(table, params.where) : relationWhere;
902
+ const order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : void 0;
903
+ const extras = params?.extras ? relationExtrasToSQL(table, params.extras) : void 0;
904
+ if (extras)
905
+ selection.push(...extras.selection);
906
+ const selectionArr = [columns];
907
+ const joins = params ? (() => {
908
+ const { with: joins2 } = params;
909
+ if (!joins2)
910
+ return;
911
+ const withEntries = Object.entries(joins2).filter(([_, v]) => v);
912
+ if (!withEntries.length)
913
+ return;
914
+ return sql.join(
915
+ withEntries.map(([k, join]) => {
916
+ selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
917
+ if (is(tableConfig.relations[k], AggregatedField)) {
918
+ const relation2 = tableConfig.relations[k];
919
+ relation2.onTable(table);
920
+ const query2 = relation2.getSQL();
921
+ selection.push({
922
+ key: k,
923
+ field: relation2
924
+ });
925
+ return sql`, lateral(${query2}) as ${sql.identifier(k)}`;
926
+ }
927
+ const relation = tableConfig.relations[k];
928
+ const isSingle2 = is(relation, One);
929
+ const targetTable = relation.targetTable;
930
+ const relationFilter = relationToSQL(relation);
931
+ const innerQuery = this.buildRelationalQuery({
932
+ table: targetTable,
933
+ mode: isSingle2 ? "first" : "many",
934
+ schema,
935
+ queryConfig: join,
936
+ tableConfig: schema[tableNamesMap[getTableUniqueName(targetTable)]],
937
+ tableNamesMap,
938
+ tables,
939
+ relationWhere: relationFilter
940
+ });
941
+ selection.push({
942
+ field: targetTable,
943
+ key: k,
944
+ selection: innerQuery.selection,
945
+ isArray: !isSingle2
946
+ });
947
+ const jsonColumns = sql.join(
948
+ innerQuery.selection.map((s) => sql`${sql.raw(this.escapeString(s.key))}, ${sql.identifier(s.key)}`),
949
+ sql`, `
950
+ );
951
+ return sql`, lateral(select ${isSingle2 ? sql`json_object(${jsonColumns}) as ${sql.identifier("r")}` : sql`coalesce(json_arrayagg(json_object(${jsonColumns})), json_array()) as ${sql.identifier("r")}`} from (${innerQuery.sql}) as ${sql.identifier("t")}) as ${sql.identifier(k)}`;
952
+ })
953
+ );
954
+ })() : void 0;
955
+ if (extras?.sql)
956
+ selectionArr.push(extras.sql);
957
+ const selectionSet = sql.join(selectionArr, sql`, `);
958
+ const query = sql`select ${selectionSet} from ${table}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
959
+ return {
960
+ sql: query,
961
+ selection
962
+ };
963
+ }
818
964
  }
819
965
  export {
820
966
  MySqlDialect