drizzle-orm 0.39.2-aaa57ff → 0.39.2-dc3b366

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 (629) 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-sql/driver.cjs +5 -16
  38. package/bun-sql/driver.cjs.map +1 -1
  39. package/bun-sql/driver.d.cts +6 -7
  40. package/bun-sql/driver.d.ts +6 -7
  41. package/bun-sql/driver.js +8 -6
  42. package/bun-sql/driver.js.map +1 -1
  43. package/bun-sql/migrator.cjs.map +1 -1
  44. package/bun-sql/migrator.d.cts +1 -2
  45. package/bun-sql/migrator.d.ts +1 -2
  46. package/bun-sql/migrator.js.map +1 -1
  47. package/bun-sql/session.cjs +6 -50
  48. package/bun-sql/session.cjs.map +1 -1
  49. package/bun-sql/session.d.cts +9 -14
  50. package/bun-sql/session.d.ts +9 -14
  51. package/bun-sql/session.js +6 -50
  52. package/bun-sql/session.js.map +1 -1
  53. package/bun-sqlite/driver.cjs +5 -22
  54. package/bun-sqlite/driver.cjs.map +1 -1
  55. package/bun-sqlite/driver.d.cts +6 -7
  56. package/bun-sqlite/driver.d.ts +6 -7
  57. package/bun-sqlite/driver.js +8 -12
  58. package/bun-sqlite/driver.js.map +1 -1
  59. package/bun-sqlite/migrator.cjs.map +1 -1
  60. package/bun-sqlite/migrator.d.cts +1 -2
  61. package/bun-sqlite/migrator.d.ts +1 -2
  62. package/bun-sqlite/migrator.js.map +1 -1
  63. package/bun-sqlite/session.cjs +4 -49
  64. package/bun-sqlite/session.cjs.map +1 -1
  65. package/bun-sqlite/session.d.cts +8 -14
  66. package/bun-sqlite/session.d.ts +8 -14
  67. package/bun-sqlite/session.js +4 -49
  68. package/bun-sqlite/session.js.map +1 -1
  69. package/d1/driver.cjs +5 -22
  70. package/d1/driver.cjs.map +1 -1
  71. package/d1/driver.d.cts +2 -3
  72. package/d1/driver.d.ts +2 -3
  73. package/d1/driver.js +8 -12
  74. package/d1/driver.js.map +1 -1
  75. package/d1/migrator.cjs.map +1 -1
  76. package/d1/migrator.d.cts +1 -2
  77. package/d1/migrator.d.ts +1 -2
  78. package/d1/migrator.js.map +1 -1
  79. package/d1/session.cjs +8 -50
  80. package/d1/session.cjs.map +1 -1
  81. package/d1/session.d.cts +8 -15
  82. package/d1/session.d.ts +8 -15
  83. package/d1/session.js +8 -50
  84. package/d1/session.js.map +1 -1
  85. package/durable-sqlite/driver.cjs +5 -16
  86. package/durable-sqlite/driver.cjs.map +1 -1
  87. package/durable-sqlite/driver.d.cts +2 -3
  88. package/durable-sqlite/driver.d.ts +2 -3
  89. package/durable-sqlite/driver.js +8 -6
  90. package/durable-sqlite/driver.js.map +1 -1
  91. package/durable-sqlite/migrator.cjs.map +1 -1
  92. package/durable-sqlite/migrator.d.cts +1 -2
  93. package/durable-sqlite/migrator.d.ts +1 -2
  94. package/durable-sqlite/migrator.js.map +1 -1
  95. package/durable-sqlite/session.cjs +4 -46
  96. package/durable-sqlite/session.cjs.map +1 -1
  97. package/durable-sqlite/session.d.cts +8 -14
  98. package/durable-sqlite/session.d.ts +8 -14
  99. package/durable-sqlite/session.js +4 -46
  100. package/durable-sqlite/session.js.map +1 -1
  101. package/expo-sqlite/driver.cjs +5 -22
  102. package/expo-sqlite/driver.cjs.map +1 -1
  103. package/expo-sqlite/driver.d.cts +2 -3
  104. package/expo-sqlite/driver.d.ts +2 -3
  105. package/expo-sqlite/driver.js +8 -12
  106. package/expo-sqlite/driver.js.map +1 -1
  107. package/expo-sqlite/migrator.cjs.map +1 -1
  108. package/expo-sqlite/migrator.d.cts +2 -3
  109. package/expo-sqlite/migrator.d.ts +2 -3
  110. package/expo-sqlite/migrator.js.map +1 -1
  111. package/expo-sqlite/query.cjs +2 -13
  112. package/expo-sqlite/query.cjs.map +1 -1
  113. package/expo-sqlite/query.d.cts +1 -2
  114. package/expo-sqlite/query.d.ts +1 -2
  115. package/expo-sqlite/query.js +2 -3
  116. package/expo-sqlite/query.js.map +1 -1
  117. package/expo-sqlite/session.cjs +4 -47
  118. package/expo-sqlite/session.cjs.map +1 -1
  119. package/expo-sqlite/session.d.cts +8 -14
  120. package/expo-sqlite/session.d.ts +8 -14
  121. package/expo-sqlite/session.js +4 -47
  122. package/expo-sqlite/session.js.map +1 -1
  123. package/libsql/driver-core.cjs +5 -22
  124. package/libsql/driver-core.cjs.map +1 -1
  125. package/libsql/driver-core.d.cts +1 -2
  126. package/libsql/driver-core.d.ts +1 -2
  127. package/libsql/driver-core.js +8 -12
  128. package/libsql/driver-core.js.map +1 -1
  129. package/libsql/driver.cjs.map +1 -1
  130. package/libsql/driver.d.cts +5 -6
  131. package/libsql/driver.d.ts +5 -6
  132. package/libsql/driver.js.map +1 -1
  133. package/libsql/http/index.cjs.map +1 -1
  134. package/libsql/http/index.d.cts +5 -6
  135. package/libsql/http/index.d.ts +5 -6
  136. package/libsql/http/index.js.map +1 -1
  137. package/libsql/migrator.cjs.map +1 -1
  138. package/libsql/migrator.d.cts +1 -2
  139. package/libsql/migrator.d.ts +1 -2
  140. package/libsql/migrator.js.map +1 -1
  141. package/libsql/node/index.cjs.map +1 -1
  142. package/libsql/node/index.d.cts +5 -6
  143. package/libsql/node/index.d.ts +5 -6
  144. package/libsql/node/index.js.map +1 -1
  145. package/libsql/session.cjs +4 -56
  146. package/libsql/session.cjs.map +1 -1
  147. package/libsql/session.d.cts +9 -15
  148. package/libsql/session.d.ts +9 -15
  149. package/libsql/session.js +4 -56
  150. package/libsql/session.js.map +1 -1
  151. package/libsql/sqlite3/index.cjs.map +1 -1
  152. package/libsql/sqlite3/index.d.cts +5 -6
  153. package/libsql/sqlite3/index.d.ts +5 -6
  154. package/libsql/sqlite3/index.js.map +1 -1
  155. package/libsql/wasm/index.cjs.map +1 -1
  156. package/libsql/wasm/index.d.cts +5 -6
  157. package/libsql/wasm/index.d.ts +5 -6
  158. package/libsql/wasm/index.js.map +1 -1
  159. package/libsql/web/index.cjs.map +1 -1
  160. package/libsql/web/index.d.cts +5 -6
  161. package/libsql/web/index.d.ts +5 -6
  162. package/libsql/web/index.js.map +1 -1
  163. package/libsql/ws/index.cjs.map +1 -1
  164. package/libsql/ws/index.d.cts +5 -6
  165. package/libsql/ws/index.d.ts +5 -6
  166. package/libsql/ws/index.js.map +1 -1
  167. package/mysql-core/db.cjs +6 -30
  168. package/mysql-core/db.cjs.map +1 -1
  169. package/mysql-core/db.d.cts +8 -15
  170. package/mysql-core/db.d.ts +8 -15
  171. package/mysql-core/db.js +5 -29
  172. package/mysql-core/db.js.map +1 -1
  173. package/mysql-core/dialect.cjs +15 -197
  174. package/mysql-core/dialect.cjs.map +1 -1
  175. package/mysql-core/dialect.d.cts +13 -36
  176. package/mysql-core/dialect.d.ts +13 -36
  177. package/mysql-core/dialect.js +22 -196
  178. package/mysql-core/dialect.js.map +1 -1
  179. package/mysql-core/query-builders/count.cjs.map +1 -1
  180. package/mysql-core/query-builders/count.d.cts +1 -1
  181. package/mysql-core/query-builders/count.d.ts +1 -1
  182. package/mysql-core/query-builders/count.js.map +1 -1
  183. package/mysql-core/query-builders/query.cjs +31 -18
  184. package/mysql-core/query-builders/query.cjs.map +1 -1
  185. package/mysql-core/query-builders/query.d.cts +10 -8
  186. package/mysql-core/query-builders/query.d.ts +10 -8
  187. package/mysql-core/query-builders/query.js +31 -18
  188. package/mysql-core/query-builders/query.js.map +1 -1
  189. package/mysql-core/session.cjs +2 -3
  190. package/mysql-core/session.cjs.map +1 -1
  191. package/mysql-core/session.d.cts +7 -10
  192. package/mysql-core/session.d.ts +7 -10
  193. package/mysql-core/session.js +2 -3
  194. package/mysql-core/session.js.map +1 -1
  195. package/mysql-proxy/driver.cjs +5 -22
  196. package/mysql-proxy/driver.cjs.map +1 -1
  197. package/mysql-proxy/driver.d.cts +2 -3
  198. package/mysql-proxy/driver.d.ts +2 -3
  199. package/mysql-proxy/driver.js +8 -12
  200. package/mysql-proxy/driver.js.map +1 -1
  201. package/mysql-proxy/migrator.cjs.map +1 -1
  202. package/mysql-proxy/migrator.d.cts +1 -2
  203. package/mysql-proxy/migrator.d.ts +1 -2
  204. package/mysql-proxy/migrator.js.map +1 -1
  205. package/mysql-proxy/session.cjs +2 -27
  206. package/mysql-proxy/session.cjs.map +1 -1
  207. package/mysql-proxy/session.d.cts +8 -13
  208. package/mysql-proxy/session.d.ts +8 -13
  209. package/mysql-proxy/session.js +2 -27
  210. package/mysql-proxy/session.js.map +1 -1
  211. package/mysql2/driver.cjs +7 -24
  212. package/mysql2/driver.cjs.map +1 -1
  213. package/mysql2/driver.d.cts +9 -10
  214. package/mysql2/driver.d.ts +9 -10
  215. package/mysql2/driver.js +10 -14
  216. package/mysql2/driver.js.map +1 -1
  217. package/mysql2/migrator.cjs.map +1 -1
  218. package/mysql2/migrator.d.cts +1 -2
  219. package/mysql2/migrator.d.ts +1 -2
  220. package/mysql2/migrator.js.map +1 -1
  221. package/mysql2/session.cjs +2 -30
  222. package/mysql2/session.cjs.map +1 -1
  223. package/mysql2/session.d.cts +8 -13
  224. package/mysql2/session.d.ts +8 -13
  225. package/mysql2/session.js +2 -30
  226. package/mysql2/session.js.map +1 -1
  227. package/neon-http/driver.cjs +7 -21
  228. package/neon-http/driver.cjs.map +1 -1
  229. package/neon-http/driver.d.cts +9 -10
  230. package/neon-http/driver.d.ts +9 -10
  231. package/neon-http/driver.js +7 -11
  232. package/neon-http/driver.js.map +1 -1
  233. package/neon-http/migrator.cjs.map +1 -1
  234. package/neon-http/migrator.d.cts +1 -2
  235. package/neon-http/migrator.d.ts +1 -2
  236. package/neon-http/migrator.js.map +1 -1
  237. package/neon-http/session.cjs +2 -32
  238. package/neon-http/session.cjs.map +1 -1
  239. package/neon-http/session.d.cts +8 -13
  240. package/neon-http/session.d.ts +8 -13
  241. package/neon-http/session.js +2 -32
  242. package/neon-http/session.js.map +1 -1
  243. package/neon-serverless/driver.cjs +7 -18
  244. package/neon-serverless/driver.cjs.map +1 -1
  245. package/neon-serverless/driver.d.cts +8 -9
  246. package/neon-serverless/driver.d.ts +8 -9
  247. package/neon-serverless/driver.js +10 -8
  248. package/neon-serverless/driver.js.map +1 -1
  249. package/neon-serverless/migrator.cjs.map +1 -1
  250. package/neon-serverless/migrator.d.cts +1 -2
  251. package/neon-serverless/migrator.d.ts +1 -2
  252. package/neon-serverless/migrator.js.map +1 -1
  253. package/neon-serverless/session.cjs +5 -40
  254. package/neon-serverless/session.cjs.map +1 -1
  255. package/neon-serverless/session.d.cts +8 -13
  256. package/neon-serverless/session.d.ts +8 -13
  257. package/neon-serverless/session.js +5 -40
  258. package/neon-serverless/session.js.map +1 -1
  259. package/node-postgres/driver.cjs +7 -13
  260. package/node-postgres/driver.cjs.map +1 -1
  261. package/node-postgres/driver.d.cts +8 -9
  262. package/node-postgres/driver.d.ts +8 -9
  263. package/node-postgres/driver.js +10 -13
  264. package/node-postgres/driver.js.map +1 -1
  265. package/node-postgres/migrator.cjs.map +1 -1
  266. package/node-postgres/migrator.d.cts +1 -2
  267. package/node-postgres/migrator.d.ts +1 -2
  268. package/node-postgres/migrator.js.map +1 -1
  269. package/node-postgres/session.cjs +4 -45
  270. package/node-postgres/session.cjs.map +1 -1
  271. package/node-postgres/session.d.cts +8 -13
  272. package/node-postgres/session.d.ts +8 -13
  273. package/node-postgres/session.js +4 -45
  274. package/node-postgres/session.js.map +1 -1
  275. package/op-sqlite/driver.cjs +5 -22
  276. package/op-sqlite/driver.cjs.map +1 -1
  277. package/op-sqlite/driver.d.cts +2 -3
  278. package/op-sqlite/driver.d.ts +2 -3
  279. package/op-sqlite/driver.js +8 -12
  280. package/op-sqlite/driver.js.map +1 -1
  281. package/op-sqlite/migrator.cjs.map +1 -1
  282. package/op-sqlite/migrator.d.cts +2 -3
  283. package/op-sqlite/migrator.d.ts +2 -3
  284. package/op-sqlite/migrator.js.map +1 -1
  285. package/op-sqlite/session.cjs +4 -47
  286. package/op-sqlite/session.cjs.map +1 -1
  287. package/op-sqlite/session.d.cts +8 -14
  288. package/op-sqlite/session.d.ts +8 -14
  289. package/op-sqlite/session.js +4 -47
  290. package/op-sqlite/session.js.map +1 -1
  291. package/package.json +51 -99
  292. package/pg-core/db.cjs +5 -32
  293. package/pg-core/db.cjs.map +1 -1
  294. package/pg-core/db.d.cts +9 -16
  295. package/pg-core/db.d.ts +9 -16
  296. package/pg-core/db.js +4 -31
  297. package/pg-core/db.js.map +1 -1
  298. package/pg-core/dialect.cjs +488 -173
  299. package/pg-core/dialect.cjs.map +1 -1
  300. package/pg-core/dialect.d.cts +8 -27
  301. package/pg-core/dialect.d.ts +8 -27
  302. package/pg-core/dialect.js +495 -172
  303. package/pg-core/dialect.js.map +1 -1
  304. package/pg-core/query-builders/count.cjs.map +1 -1
  305. package/pg-core/query-builders/count.d.cts +1 -1
  306. package/pg-core/query-builders/count.d.ts +1 -1
  307. package/pg-core/query-builders/count.js.map +1 -1
  308. package/pg-core/query-builders/query.cjs +18 -15
  309. package/pg-core/query-builders/query.cjs.map +1 -1
  310. package/pg-core/query-builders/query.d.cts +6 -6
  311. package/pg-core/query-builders/query.d.ts +6 -6
  312. package/pg-core/query-builders/query.js +18 -15
  313. package/pg-core/query-builders/query.js.map +1 -1
  314. package/pg-core/session.cjs +2 -3
  315. package/pg-core/session.cjs.map +1 -1
  316. package/pg-core/session.d.cts +6 -9
  317. package/pg-core/session.d.ts +6 -9
  318. package/pg-core/session.js +2 -3
  319. package/pg-core/session.js.map +1 -1
  320. package/pg-proxy/driver.cjs +5 -21
  321. package/pg-proxy/driver.cjs.map +1 -1
  322. package/pg-proxy/driver.d.cts +2 -3
  323. package/pg-proxy/driver.d.ts +2 -3
  324. package/pg-proxy/driver.js +8 -11
  325. package/pg-proxy/driver.js.map +1 -1
  326. package/pg-proxy/migrator.cjs.map +1 -1
  327. package/pg-proxy/migrator.d.cts +1 -2
  328. package/pg-proxy/migrator.d.ts +1 -2
  329. package/pg-proxy/migrator.js.map +1 -1
  330. package/pg-proxy/session.cjs +2 -37
  331. package/pg-proxy/session.cjs.map +1 -1
  332. package/pg-proxy/session.d.cts +8 -13
  333. package/pg-proxy/session.d.ts +8 -13
  334. package/pg-proxy/session.js +2 -37
  335. package/pg-proxy/session.js.map +1 -1
  336. package/pglite/driver.cjs +7 -23
  337. package/pglite/driver.cjs.map +1 -1
  338. package/pglite/driver.d.cts +8 -9
  339. package/pglite/driver.d.ts +8 -9
  340. package/pglite/driver.js +10 -13
  341. package/pglite/driver.js.map +1 -1
  342. package/pglite/migrator.cjs.map +1 -1
  343. package/pglite/migrator.d.cts +1 -2
  344. package/pglite/migrator.d.ts +1 -2
  345. package/pglite/migrator.js.map +1 -1
  346. package/pglite/session.cjs +3 -34
  347. package/pglite/session.cjs.map +1 -1
  348. package/pglite/session.d.cts +8 -13
  349. package/pglite/session.d.ts +8 -13
  350. package/pglite/session.js +3 -34
  351. package/pglite/session.js.map +1 -1
  352. package/planetscale-serverless/driver.cjs +5 -22
  353. package/planetscale-serverless/driver.cjs.map +1 -1
  354. package/planetscale-serverless/driver.d.cts +6 -7
  355. package/planetscale-serverless/driver.d.ts +6 -7
  356. package/planetscale-serverless/driver.js +8 -12
  357. package/planetscale-serverless/driver.js.map +1 -1
  358. package/planetscale-serverless/migrator.cjs.map +1 -1
  359. package/planetscale-serverless/migrator.d.cts +1 -2
  360. package/planetscale-serverless/migrator.d.ts +1 -2
  361. package/planetscale-serverless/migrator.js.map +1 -1
  362. package/planetscale-serverless/session.cjs +5 -45
  363. package/planetscale-serverless/session.cjs.map +1 -1
  364. package/planetscale-serverless/session.d.cts +9 -14
  365. package/planetscale-serverless/session.d.ts +9 -14
  366. package/planetscale-serverless/session.js +5 -45
  367. package/planetscale-serverless/session.js.map +1 -1
  368. package/postgres-js/driver.cjs +5 -6
  369. package/postgres-js/driver.cjs.map +1 -1
  370. package/postgres-js/driver.d.cts +6 -7
  371. package/postgres-js/driver.d.ts +6 -7
  372. package/postgres-js/driver.js +8 -6
  373. package/postgres-js/driver.js.map +1 -1
  374. package/postgres-js/migrator.cjs.map +1 -1
  375. package/postgres-js/migrator.d.cts +1 -2
  376. package/postgres-js/migrator.d.ts +1 -2
  377. package/postgres-js/migrator.js.map +1 -1
  378. package/postgres-js/session.cjs +6 -51
  379. package/postgres-js/session.cjs.map +1 -1
  380. package/postgres-js/session.d.cts +9 -15
  381. package/postgres-js/session.d.ts +9 -15
  382. package/postgres-js/session.js +6 -51
  383. package/postgres-js/session.js.map +1 -1
  384. package/prisma/mysql/driver.cjs +1 -1
  385. package/prisma/mysql/driver.cjs.map +1 -1
  386. package/prisma/mysql/driver.js +1 -1
  387. package/prisma/mysql/driver.js.map +1 -1
  388. package/prisma/mysql/session.cjs +0 -3
  389. package/prisma/mysql/session.cjs.map +1 -1
  390. package/prisma/mysql/session.d.cts +1 -3
  391. package/prisma/mysql/session.d.ts +1 -3
  392. package/prisma/mysql/session.js +0 -3
  393. package/prisma/mysql/session.js.map +1 -1
  394. package/prisma/pg/driver.cjs +1 -1
  395. package/prisma/pg/driver.cjs.map +1 -1
  396. package/prisma/pg/driver.js +1 -1
  397. package/prisma/pg/driver.js.map +1 -1
  398. package/prisma/pg/session.cjs +0 -3
  399. package/prisma/pg/session.cjs.map +1 -1
  400. package/prisma/pg/session.d.cts +1 -3
  401. package/prisma/pg/session.d.ts +1 -3
  402. package/prisma/pg/session.js +0 -3
  403. package/prisma/pg/session.js.map +1 -1
  404. package/prisma/sqlite/driver.cjs +1 -1
  405. package/prisma/sqlite/driver.cjs.map +1 -1
  406. package/prisma/sqlite/driver.js +1 -1
  407. package/prisma/sqlite/driver.js.map +1 -1
  408. package/prisma/sqlite/session.cjs +0 -3
  409. package/prisma/sqlite/session.cjs.map +1 -1
  410. package/prisma/sqlite/session.d.cts +2 -4
  411. package/prisma/sqlite/session.d.ts +2 -4
  412. package/prisma/sqlite/session.js +0 -3
  413. package/prisma/sqlite/session.js.map +1 -1
  414. package/relations.cjs +245 -596
  415. package/relations.cjs.map +1 -1
  416. package/relations.d.cts +140 -292
  417. package/relations.d.ts +140 -292
  418. package/relations.js +240 -589
  419. package/relations.js.map +1 -1
  420. package/singlestore/driver.cjs +1 -1
  421. package/singlestore/driver.cjs.map +1 -1
  422. package/singlestore/driver.d.cts +1 -1
  423. package/singlestore/driver.d.ts +1 -1
  424. package/singlestore/driver.js +3 -3
  425. package/singlestore/driver.js.map +1 -1
  426. package/singlestore/session.cjs.map +1 -1
  427. package/singlestore/session.d.cts +4 -4
  428. package/singlestore/session.d.ts +4 -4
  429. package/singlestore/session.js.map +1 -1
  430. package/singlestore-core/db.cjs.map +1 -1
  431. package/singlestore-core/db.d.cts +3 -3
  432. package/singlestore-core/db.d.ts +3 -3
  433. package/singlestore-core/db.js.map +1 -1
  434. package/singlestore-core/dialect.cjs +6 -16
  435. package/singlestore-core/dialect.cjs.map +1 -1
  436. package/singlestore-core/dialect.d.cts +6 -6
  437. package/singlestore-core/dialect.d.ts +6 -6
  438. package/singlestore-core/dialect.js +12 -6
  439. package/singlestore-core/dialect.js.map +1 -1
  440. package/singlestore-core/query-builders/query.cjs +2 -12
  441. package/singlestore-core/query-builders/query.cjs.map +1 -1
  442. package/singlestore-core/query-builders/query.d.cts +6 -6
  443. package/singlestore-core/query-builders/query.d.ts +6 -6
  444. package/singlestore-core/query-builders/query.js +4 -2
  445. package/singlestore-core/query-builders/query.js.map +1 -1
  446. package/singlestore-core/session.cjs.map +1 -1
  447. package/singlestore-core/session.d.cts +5 -5
  448. package/singlestore-core/session.d.ts +5 -5
  449. package/singlestore-core/session.js.map +1 -1
  450. package/singlestore-proxy/driver.cjs +1 -1
  451. package/singlestore-proxy/driver.cjs.map +1 -1
  452. package/singlestore-proxy/driver.js +3 -3
  453. package/singlestore-proxy/driver.js.map +1 -1
  454. package/singlestore-proxy/session.cjs.map +1 -1
  455. package/singlestore-proxy/session.d.cts +4 -4
  456. package/singlestore-proxy/session.d.ts +4 -4
  457. package/singlestore-proxy/session.js.map +1 -1
  458. package/sql/expressions/conditions.cjs.map +1 -1
  459. package/sql/expressions/conditions.d.cts +4 -4
  460. package/sql/expressions/conditions.d.ts +4 -4
  461. package/sql/expressions/conditions.js.map +1 -1
  462. package/sql/sql.cjs +0 -21
  463. package/sql/sql.cjs.map +1 -1
  464. package/sql/sql.d.cts +8 -8
  465. package/sql/sql.d.ts +8 -8
  466. package/sql/sql.js +1 -22
  467. package/sql/sql.js.map +1 -1
  468. package/sql-js/driver.cjs +5 -16
  469. package/sql-js/driver.cjs.map +1 -1
  470. package/sql-js/driver.d.cts +2 -3
  471. package/sql-js/driver.d.ts +2 -3
  472. package/sql-js/driver.js +8 -6
  473. package/sql-js/driver.js.map +1 -1
  474. package/sql-js/migrator.cjs.map +1 -1
  475. package/sql-js/migrator.d.cts +1 -2
  476. package/sql-js/migrator.d.ts +1 -2
  477. package/sql-js/migrator.js.map +1 -1
  478. package/sql-js/session.cjs +36 -71
  479. package/sql-js/session.cjs.map +1 -1
  480. package/sql-js/session.d.cts +13 -16
  481. package/sql-js/session.d.ts +13 -16
  482. package/sql-js/session.js +36 -71
  483. package/sql-js/session.js.map +1 -1
  484. package/sqlite-core/db.cjs +12 -39
  485. package/sqlite-core/db.cjs.map +1 -1
  486. package/sqlite-core/db.d.cts +8 -16
  487. package/sqlite-core/db.d.ts +8 -16
  488. package/sqlite-core/db.js +11 -38
  489. package/sqlite-core/db.js.map +1 -1
  490. package/sqlite-core/dialect.cjs +7 -186
  491. package/sqlite-core/dialect.cjs.map +1 -1
  492. package/sqlite-core/dialect.d.cts +9 -31
  493. package/sqlite-core/dialect.d.ts +9 -31
  494. package/sqlite-core/dialect.js +14 -185
  495. package/sqlite-core/dialect.js.map +1 -1
  496. package/sqlite-core/query-builders/count.cjs.map +1 -1
  497. package/sqlite-core/query-builders/count.d.cts +1 -1
  498. package/sqlite-core/query-builders/count.d.ts +1 -1
  499. package/sqlite-core/query-builders/count.js.map +1 -1
  500. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  501. package/sqlite-core/query-builders/delete.d.cts +1 -1
  502. package/sqlite-core/query-builders/delete.d.ts +1 -1
  503. package/sqlite-core/query-builders/delete.js.map +1 -1
  504. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  505. package/sqlite-core/query-builders/insert.d.cts +3 -3
  506. package/sqlite-core/query-builders/insert.d.ts +3 -3
  507. package/sqlite-core/query-builders/insert.js.map +1 -1
  508. package/sqlite-core/query-builders/query.cjs +35 -56
  509. package/sqlite-core/query-builders/query.cjs.map +1 -1
  510. package/sqlite-core/query-builders/query.d.cts +17 -18
  511. package/sqlite-core/query-builders/query.d.ts +17 -18
  512. package/sqlite-core/query-builders/query.js +35 -56
  513. package/sqlite-core/query-builders/query.js.map +1 -1
  514. package/sqlite-core/query-builders/select.cjs.map +1 -1
  515. package/sqlite-core/query-builders/select.d.cts +3 -3
  516. package/sqlite-core/query-builders/select.d.ts +3 -3
  517. package/sqlite-core/query-builders/select.js.map +1 -1
  518. package/sqlite-core/query-builders/update.cjs.map +1 -1
  519. package/sqlite-core/query-builders/update.d.cts +3 -3
  520. package/sqlite-core/query-builders/update.d.ts +3 -3
  521. package/sqlite-core/query-builders/update.js.map +1 -1
  522. package/sqlite-core/session.cjs +2 -6
  523. package/sqlite-core/session.cjs.map +1 -1
  524. package/sqlite-core/session.d.cts +7 -15
  525. package/sqlite-core/session.d.ts +7 -15
  526. package/sqlite-core/session.js +2 -6
  527. package/sqlite-core/session.js.map +1 -1
  528. package/sqlite-proxy/driver.cjs +5 -23
  529. package/sqlite-proxy/driver.cjs.map +1 -1
  530. package/sqlite-proxy/driver.d.cts +3 -4
  531. package/sqlite-proxy/driver.d.ts +3 -4
  532. package/sqlite-proxy/driver.js +5 -13
  533. package/sqlite-proxy/driver.js.map +1 -1
  534. package/sqlite-proxy/migrator.cjs.map +1 -1
  535. package/sqlite-proxy/migrator.d.cts +1 -2
  536. package/sqlite-proxy/migrator.d.ts +1 -2
  537. package/sqlite-proxy/migrator.js.map +1 -1
  538. package/sqlite-proxy/session.cjs +6 -50
  539. package/sqlite-proxy/session.cjs.map +1 -1
  540. package/sqlite-proxy/session.d.cts +8 -14
  541. package/sqlite-proxy/session.d.ts +8 -14
  542. package/sqlite-proxy/session.js +6 -50
  543. package/sqlite-proxy/session.js.map +1 -1
  544. package/table.cjs.map +1 -1
  545. package/table.d.cts +2 -2
  546. package/table.d.ts +2 -2
  547. package/table.js.map +1 -1
  548. package/tidb-serverless/driver.cjs +5 -22
  549. package/tidb-serverless/driver.cjs.map +1 -1
  550. package/tidb-serverless/driver.d.cts +6 -7
  551. package/tidb-serverless/driver.d.ts +6 -7
  552. package/tidb-serverless/driver.js +8 -12
  553. package/tidb-serverless/driver.js.map +1 -1
  554. package/tidb-serverless/migrator.cjs.map +1 -1
  555. package/tidb-serverless/migrator.d.cts +1 -2
  556. package/tidb-serverless/migrator.d.ts +1 -2
  557. package/tidb-serverless/migrator.js.map +1 -1
  558. package/tidb-serverless/session.cjs +5 -62
  559. package/tidb-serverless/session.cjs.map +1 -1
  560. package/tidb-serverless/session.d.cts +9 -14
  561. package/tidb-serverless/session.d.ts +9 -14
  562. package/tidb-serverless/session.js +5 -62
  563. package/tidb-serverless/session.js.map +1 -1
  564. package/utils.cjs +2 -2
  565. package/utils.cjs.map +1 -1
  566. package/utils.d.cts +1 -3
  567. package/utils.d.ts +1 -3
  568. package/utils.js +2 -2
  569. package/utils.js.map +1 -1
  570. package/vercel-postgres/driver.cjs +7 -23
  571. package/vercel-postgres/driver.cjs.map +1 -1
  572. package/vercel-postgres/driver.d.cts +8 -9
  573. package/vercel-postgres/driver.d.ts +8 -9
  574. package/vercel-postgres/driver.js +10 -13
  575. package/vercel-postgres/driver.js.map +1 -1
  576. package/vercel-postgres/migrator.cjs.map +1 -1
  577. package/vercel-postgres/migrator.d.cts +1 -2
  578. package/vercel-postgres/migrator.d.ts +1 -2
  579. package/vercel-postgres/migrator.js.map +1 -1
  580. package/vercel-postgres/session.cjs +4 -34
  581. package/vercel-postgres/session.cjs.map +1 -1
  582. package/vercel-postgres/session.d.cts +8 -13
  583. package/vercel-postgres/session.d.ts +8 -13
  584. package/vercel-postgres/session.js +4 -34
  585. package/vercel-postgres/session.js.map +1 -1
  586. package/version.cjs +1 -1
  587. package/version.d.cts +1 -1
  588. package/version.d.ts +1 -1
  589. package/version.js +1 -1
  590. package/xata-http/driver.cjs +5 -17
  591. package/xata-http/driver.cjs.map +1 -1
  592. package/xata-http/driver.d.cts +4 -5
  593. package/xata-http/driver.d.ts +4 -5
  594. package/xata-http/driver.js +5 -7
  595. package/xata-http/driver.js.map +1 -1
  596. package/xata-http/migrator.cjs.map +1 -1
  597. package/xata-http/migrator.d.cts +1 -2
  598. package/xata-http/migrator.d.ts +1 -2
  599. package/xata-http/migrator.js.map +1 -1
  600. package/xata-http/session.cjs +2 -30
  601. package/xata-http/session.cjs.map +1 -1
  602. package/xata-http/session.d.cts +8 -13
  603. package/xata-http/session.d.ts +8 -13
  604. package/xata-http/session.js +2 -30
  605. package/xata-http/session.js.map +1 -1
  606. package/_relations.cjs +0 -328
  607. package/_relations.cjs.map +0 -1
  608. package/_relations.d.cts +0 -215
  609. package/_relations.d.ts +0 -215
  610. package/_relations.js +0 -316
  611. package/_relations.js.map +0 -1
  612. package/mysql-core/query-builders/_query.cjs +0 -149
  613. package/mysql-core/query-builders/_query.cjs.map +0 -1
  614. package/mysql-core/query-builders/_query.d.cts +0 -44
  615. package/mysql-core/query-builders/_query.d.ts +0 -44
  616. package/mysql-core/query-builders/_query.js +0 -114
  617. package/mysql-core/query-builders/_query.js.map +0 -1
  618. package/pg-core/query-builders/_query.cjs +0 -155
  619. package/pg-core/query-builders/_query.cjs.map +0 -1
  620. package/pg-core/query-builders/_query.d.cts +0 -47
  621. package/pg-core/query-builders/_query.d.ts +0 -47
  622. package/pg-core/query-builders/_query.js +0 -120
  623. package/pg-core/query-builders/_query.js.map +0 -1
  624. package/sqlite-core/query-builders/_query.cjs +0 -187
  625. package/sqlite-core/query-builders/_query.cjs.map +0 -1
  626. package/sqlite-core/query-builders/_query.d.cts +0 -55
  627. package/sqlite-core/query-builders/_query.d.ts +0 -55
  628. package/sqlite-core/query-builders/_query.js +0 -151
  629. package/sqlite-core/query-builders/_query.js.map +0 -1
@@ -1,12 +1,10 @@
1
1
  import type { ResultSetHeader } from 'mysql2/promise';
2
- import type * as V1 from "../_relations.js";
3
2
  import { entityKind } from "../entity.js";
4
- import type { AnyRelations, EmptyRelations, ExtractTablesWithRelations, TablesRelationalConfig } from "../relations.js";
3
+ import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
5
4
  import { type SQL, type SQLWrapper } from "../sql/sql.js";
6
5
  import { WithSubquery } from "../subquery.js";
7
6
  import type { DrizzleTypeError } from "../utils.js";
8
7
  import type { MySqlDialect } from "./dialect.js";
9
- import { _RelationalQueryBuilder } from "./query-builders/_query.js";
10
8
  import { MySqlCountBuilder } from "./query-builders/count.js";
11
9
  import { MySqlDeleteBase, MySqlInsertBuilder, MySqlSelectBuilder, MySqlUpdateBuilder } from "./query-builders/index.js";
12
10
  import { RelationalQueryBuilder } from "./query-builders/query.js";
@@ -15,27 +13,22 @@ import type { Mode, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, MyS
15
13
  import type { WithBuilder } from "./subquery.js";
16
14
  import type { MySqlTable } from "./table.js";
17
15
  import type { MySqlViewBase } from "./view-base.js";
18
- export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TTablesConfig extends TablesRelationalConfig = ExtractTablesWithRelations<TRelations>, TSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>> {
16
+ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
19
17
  protected readonly mode: Mode;
20
18
  static readonly [entityKind]: string;
21
19
  readonly _: {
22
20
  readonly schema: TSchema | undefined;
23
21
  readonly fullSchema: TFullSchema;
24
- readonly relations: TRelations;
25
22
  readonly tableNamesMap: Record<string, string>;
26
23
  };
27
- /** @deprecated */
28
- _query: TFullSchema extends Record<string, never> ? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'> : {
29
- [K in keyof TSchema]: _RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;
30
- };
31
- query: {
32
- [K in keyof TRelations['tables']]: RelationalQueryBuilder<TPreparedQueryHKT, TTablesConfig, TTablesConfig[K]>;
24
+ query: TFullSchema extends Record<string, never> ? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'> : {
25
+ [K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;
33
26
  };
34
27
  constructor(
35
28
  /** @internal */
36
29
  dialect: MySqlDialect,
37
30
  /** @internal */
38
- session: MySqlSession<any, any, any, any, any, any>, relations: AnyRelations | undefined, schema: V1.RelationalSchemaConfig<TSchema> | undefined, mode: Mode);
31
+ session: MySqlSession<any, any, any, any>, schema: RelationalSchemaConfig<TSchema> | undefined, mode: Mode);
39
32
  /**
40
33
  * Creates a subquery that defines a temporary named result set as a CTE.
41
34
  *
@@ -69,7 +62,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
69
62
  * ```
70
63
  */
71
64
  $with: WithBuilder;
72
- $count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any, any, any>>;
65
+ $count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any>>;
73
66
  /**
74
67
  * Incorporates a previously defined CTE (using `$with`) into the main query.
75
68
  *
@@ -230,9 +223,9 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
230
223
  execute<T extends {
231
224
  [column: string]: any;
232
225
  } = ResultSetHeader>(query: SQLWrapper | string): Promise<MySqlQueryResultKind<TQueryResult, T>>;
233
- transaction<T>(transaction: (tx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TTablesConfig, TSchema>, config?: MySqlTransactionConfig) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
226
+ transaction<T>(transaction: (tx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>, config?: MySqlTransactionConfig) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
234
227
  }
235
228
  export type MySQLWithReplicas<Q> = Q & {
236
229
  $primary: Q;
237
230
  };
238
- export declare const withReplicas: <HKT extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TTablesConfig extends TablesRelationalConfig, TSchema extends V1.TablesRelationalConfig, Q extends MySqlDatabase<HKT, TPreparedQueryHKT, TFullSchema, TRelations, TTablesConfig, TSchema extends Record<string, unknown> ? V1.ExtractTablesWithRelations<TFullSchema> : TSchema>>(primary: Q, replicas: [Q, ...Q[]], getReplica?: (replicas: Q[]) => Q) => MySQLWithReplicas<Q>;
231
+ export declare const withReplicas: <HKT extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig, Q extends MySqlDatabase<HKT, TPreparedQueryHKT, TFullSchema, TSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema>>(primary: Q, replicas: [Q, ...Q[]], getReplica?: (replicas: Q[]) => Q) => MySQLWithReplicas<Q>;
package/mysql-core/db.js CHANGED
@@ -2,7 +2,6 @@ import { entityKind } from "../entity.js";
2
2
  import { SelectionProxyHandler } from "../selection-proxy.js";
3
3
  import { sql } from "../sql/sql.js";
4
4
  import { WithSubquery } from "../subquery.js";
5
- import { _RelationalQueryBuilder } from "./query-builders/_query.js";
6
5
  import { MySqlCountBuilder } from "./query-builders/count.js";
7
6
  import {
8
7
  MySqlDeleteBase,
@@ -13,26 +12,23 @@ import {
13
12
  } from "./query-builders/index.js";
14
13
  import { RelationalQueryBuilder } from "./query-builders/query.js";
15
14
  class MySqlDatabase {
16
- constructor(dialect, session, relations, schema, mode) {
15
+ constructor(dialect, session, schema, mode) {
17
16
  this.dialect = dialect;
18
17
  this.session = session;
19
18
  this.mode = mode;
20
- const rel = relations ?? {};
21
19
  this._ = schema ? {
22
20
  schema: schema.schema,
23
21
  fullSchema: schema.fullSchema,
24
- tableNamesMap: schema.tableNamesMap,
25
- relations: rel
22
+ tableNamesMap: schema.tableNamesMap
26
23
  } : {
27
24
  schema: void 0,
28
25
  fullSchema: {},
29
- tableNamesMap: {},
30
- relations: rel
26
+ tableNamesMap: {}
31
27
  };
32
- this._query = {};
28
+ this.query = {};
33
29
  if (this._.schema) {
34
30
  for (const [tableName, columns] of Object.entries(this._.schema)) {
35
- this._query[tableName] = new _RelationalQueryBuilder(
31
+ this.query[tableName] = new RelationalQueryBuilder(
36
32
  schema.fullSchema,
37
33
  this._.schema,
38
34
  this._.tableNamesMap,
@@ -44,25 +40,8 @@ class MySqlDatabase {
44
40
  );
45
41
  }
46
42
  }
47
- this.query = {};
48
- if (relations) {
49
- for (const [tableName, relation] of Object.entries(relations.tablesConfig)) {
50
- this.query[tableName] = new RelationalQueryBuilder(
51
- relations.tables,
52
- relations.tablesConfig,
53
- relations.tableNamesMap,
54
- relation.table,
55
- relation,
56
- dialect,
57
- session
58
- );
59
- }
60
- }
61
43
  }
62
44
  static [entityKind] = "MySqlDatabase";
63
- /** @deprecated */
64
- _query;
65
- // TO-DO: Figure out how to pass DrizzleTypeError without breaking withReplicas
66
45
  query;
67
46
  /**
68
47
  * Creates a subquery that defines a temporary named result set as a CTE.
@@ -271,9 +250,6 @@ const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(
271
250
  selectDistinct,
272
251
  $count,
273
252
  with: $with,
274
- get _query() {
275
- return getReplica(replicas)._query;
276
- },
277
253
  get query() {
278
254
  return getReplica(replicas).query;
279
255
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport type * as V1 from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { AnyRelations, EmptyRelations, ExtractTablesWithRelations, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { _RelationalQueryBuilder } from './query-builders/_query.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithBuilder } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTTablesConfig extends TablesRelationalConfig = ExtractTablesWithRelations<TRelations>,\n\tTSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly relations: TRelations;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\t/** @deprecated */\n\t_query: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: _RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\t// TO-DO: Figure out how to pass DrizzleTypeError without breaking withReplicas\n\tquery: {\n\t\t[K in keyof TRelations['tables']]: RelationalQueryBuilder<\n\t\t\tTPreparedQueryHKT,\n\t\t\tTTablesConfig,\n\t\t\tTTablesConfig[K]\n\t\t>;\n\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any, any, any>,\n\t\trelations: AnyRelations | undefined,\n\t\tschema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tconst rel = relations ?? {} as EmptyRelations;\n\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t\trelations: rel as TRelations,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t\trelations: rel as TRelations,\n\t\t\t};\n\t\tthis._query = {} as typeof this['_query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this._query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['_query'])[tableName] =\n\t\t\t\t\tnew _RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (relations) {\n\t\t\tfor (const [tableName, relation] of Object.entries(relations.tablesConfig)) {\n\t\t\t\t(this.query as MySqlDatabase<\n\t\t\t\t\tTQueryResult,\n\t\t\t\t\tTPreparedQueryHKT,\n\t\t\t\t\tTSchema,\n\t\t\t\t\tAnyRelations,\n\t\t\t\t\tTablesRelationalConfig,\n\t\t\t\t\tV1.TablesRelationalConfig\n\t\t\t\t>['query'])[\n\t\t\t\t\ttableName\n\t\t\t\t] = new RelationalQueryBuilder(\n\t\t\t\t\trelations.tables,\n\t\t\t\t\trelations.tablesConfig,\n\t\t\t\t\trelations.tableNamesMap,\n\t\t\t\t\trelation.table as MySqlTable,\n\t\t\t\t\trelation,\n\t\t\t\t\tdialect,\n\t\t\t\t\tsession,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with: WithBuilder = (alias: string, selection?: ColumnsSelection) => {\n\t\tconst self = this;\n\t\tconst as = (\n\t\t\tqb:\n\t\t\t\t| TypedQueryBuilder<ColumnsSelection | undefined>\n\t\t\t\t| SQL\n\t\t\t\t| ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection | undefined> | SQL),\n\t\t) => {\n\t\t\tif (typeof qb === 'function') {\n\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t}\n\n\t\t\treturn new Proxy(\n\t\t\t\tnew WithSubquery(\n\t\t\t\t\tqb.getSQL(),\n\t\t\t\t\tselection ?? ('getSelectedFields' in qb ? qb.getSelectedFields() ?? {} : {}) as SelectedFields,\n\t\t\t\t\talias,\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t);\n\t\t};\n\t\treturn { as };\n\t};\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TTablesConfig, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTTablesConfig extends TablesRelationalConfig,\n\tTSchema extends V1.TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTRelations,\n\t\tTTablesConfig,\n\t\tTSchema extends Record<string, unknown> ? V1.ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $count: Q['$count'] = (...args: [any]) => getReplica(replicas).$count(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\t$count,\n\t\twith: $with,\n\t\tget _query() {\n\t\t\treturn getReplica(replicas)._query;\n\t\t},\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AAEA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AACtC,SAA0C,WAA4B;AACtE,SAAS,oBAAoB;AAG7B,SAAS,+BAA+B;AACxC,SAAS,yBAAyB;AAClC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAehC,MAAM,cAOX;AAAA,EA0BD,YAEU,SAEA,SACT,WACA,QACmB,MAClB;AANQ;AAEA;AAGU;AAEnB,UAAM,MAAM,aAAa,CAAC;AAE1B,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,MACtB,WAAW;AAAA,IACZ,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,MAChB,WAAW;AAAA,IACZ;AACD,SAAK,SAAS,CAAC;AACf,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,QAAC,KAAK,OAAyF,SAAS,IACvG,IAAI;AAAA,UACH,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA,UACP,KAAK,EAAE;AAAA,UACP,OAAQ,WAAW,SAAS;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK;AAAA,QACN;AAAA,MACF;AAAA,IACD;AACA,SAAK,QAAQ,CAAC;AACd,QAAI,WAAW;AACd,iBAAW,CAAC,WAAW,QAAQ,KAAK,OAAO,QAAQ,UAAU,YAAY,GAAG;AAC3E,QAAC,KAAK,MAQL,SACD,IAAI,IAAI;AAAA,UACP,UA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AAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,SAAS;AACZ,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,IACA,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithBuilder } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with: WithBuilder = (alias: string, selection?: ColumnsSelection) => {\n\t\tconst self = this;\n\t\tconst as = (\n\t\t\tqb:\n\t\t\t\t| TypedQueryBuilder<ColumnsSelection | undefined>\n\t\t\t\t| SQL\n\t\t\t\t| ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection | undefined> | SQL),\n\t\t) => {\n\t\t\tif (typeof qb === 'function') {\n\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t}\n\n\t\t\treturn new Proxy(\n\t\t\t\tnew WithSubquery(\n\t\t\t\t\tqb.getSQL(),\n\t\t\t\t\tselection ?? ('getSelectedFields' in qb ? qb.getSelectedFields() ?? {} : {}) as SelectedFields,\n\t\t\t\t\talias,\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t);\n\t\t};\n\t\treturn { as };\n\t};\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $count: Q['$count'] = (...args: [any]) => getReplica(replicas).$count(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\t$count,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AACtC,SAA0C,WAA4B;AACtE,SAAS,oBAAoB;AAG7B,SAAS,yBAAyB;AAClC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAehC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AACd,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,QAAC,KAAK,MAAuF,SAAS,IACrG,IAAI;AAAA,UACH,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA,UACP,KAAK,EAAE;AAAA,UACP,OAAQ,WAAW,SAA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,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,21 +15,12 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var dialect_exports = {};
30
20
  __export(dialect_exports, {
31
21
  MySqlDialect: () => MySqlDialect
32
22
  });
33
23
  module.exports = __toCommonJS(dialect_exports);
34
- var V1 = __toESM(require("../_relations.cjs"), 1);
35
24
  var import_alias = require("../alias.cjs");
36
25
  var import_casing = require("../casing.cjs");
37
26
  var import_column = require("../column.cjs");
@@ -412,8 +401,7 @@ class MySqlDialect {
412
401
  invokeSource
413
402
  });
414
403
  }
415
- /** @deprecated */
416
- _buildRelationalQuery({
404
+ buildRelationalQuery({
417
405
  fullSchema,
418
406
  schema,
419
407
  tableNamesMap,
@@ -442,7 +430,7 @@ class MySqlDialect {
442
430
  Object.entries(tableConfig.columns).map(([key, value]) => [key, (0, import_alias.aliasedTableColumn)(value, tableAlias)])
443
431
  );
444
432
  if (config.where) {
445
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
433
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0, import_relations.getOperators)()) : config.where;
446
434
  where = whereSql && (0, import_alias.mapColumnsInSQLToAlias)(whereSql, tableAlias);
447
435
  }
448
436
  const fieldsSelection = [];
@@ -494,7 +482,7 @@ class MySqlDialect {
494
482
  selection: []
495
483
  });
496
484
  }
497
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
485
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0, import_relations.getOrderByOperators)()) : config.orderBy ?? [];
498
486
  if (!Array.isArray(orderByOrig)) {
499
487
  orderByOrig = [orderByOrig];
500
488
  }
@@ -511,7 +499,7 @@ class MySqlDialect {
511
499
  queryConfig: selectedRelationConfigValue,
512
500
  relation
513
501
  } of selectedRelations) {
514
- const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
502
+ const normalizedRelation = (0, import_relations.normalizeRelation)(schema, tableNamesMap, relation);
515
503
  const relationTableName = (0, import_table.getTableUniqueName)(relation.referencedTable);
516
504
  const relationTableTsName = tableNamesMap[relationTableName];
517
505
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -523,13 +511,13 @@ class MySqlDialect {
523
511
  )
524
512
  )
525
513
  );
526
- const builtRelation = this._buildRelationalQuery({
514
+ const builtRelation = this.buildRelationalQuery({
527
515
  fullSchema,
528
516
  schema,
529
517
  tableNamesMap,
530
518
  table: fullSchema[relationTableTsName],
531
519
  tableConfig: schema[relationTableTsName],
532
- queryConfig: (0, import_entity.is)(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
520
+ queryConfig: (0, import_entity.is)(relation, import_relations.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
533
521
  tableAlias: relationTableAlias,
534
522
  joinOn: joinOn2,
535
523
  nestedQueryRelation: relation
@@ -564,7 +552,7 @@ class MySqlDialect {
564
552
  ),
565
553
  import_sql.sql`, `
566
554
  )})`;
567
- if ((0, import_entity.is)(nestedQueryRelation, V1.Many)) {
555
+ if ((0, import_entity.is)(nestedQueryRelation, import_relations.Many)) {
568
556
  field = import_sql.sql`coalesce(json_arrayagg(${field}), json_array())`;
569
557
  }
570
558
  const nestedSelection = [{
@@ -638,8 +626,7 @@ class MySqlDialect {
638
626
  selection
639
627
  };
640
628
  }
641
- /** @deprecated */
642
- _buildRelationalQueryWithoutLateralSubqueries({
629
+ buildRelationalQueryWithoutLateralSubqueries({
643
630
  fullSchema,
644
631
  schema,
645
632
  tableNamesMap,
@@ -667,7 +654,7 @@ class MySqlDialect {
667
654
  Object.entries(tableConfig.columns).map(([key, value]) => [key, (0, import_alias.aliasedTableColumn)(value, tableAlias)])
668
655
  );
669
656
  if (config.where) {
670
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
657
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0, import_relations.getOperators)()) : config.where;
671
658
  where = whereSql && (0, import_alias.mapColumnsInSQLToAlias)(whereSql, tableAlias);
672
659
  }
673
660
  const fieldsSelection = [];
@@ -719,7 +706,7 @@ class MySqlDialect {
719
706
  selection: []
720
707
  });
721
708
  }
722
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
709
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0, import_relations.getOrderByOperators)()) : config.orderBy ?? [];
723
710
  if (!Array.isArray(orderByOrig)) {
724
711
  orderByOrig = [orderByOrig];
725
712
  }
@@ -736,7 +723,7 @@ class MySqlDialect {
736
723
  queryConfig: selectedRelationConfigValue,
737
724
  relation
738
725
  } of selectedRelations) {
739
- const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
726
+ const normalizedRelation = (0, import_relations.normalizeRelation)(schema, tableNamesMap, relation);
740
727
  const relationTableName = (0, import_table.getTableUniqueName)(relation.referencedTable);
741
728
  const relationTableTsName = tableNamesMap[relationTableName];
742
729
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -748,19 +735,19 @@ class MySqlDialect {
748
735
  )
749
736
  )
750
737
  );
751
- const builtRelation = this._buildRelationalQueryWithoutLateralSubqueries({
738
+ const builtRelation = this.buildRelationalQueryWithoutLateralSubqueries({
752
739
  fullSchema,
753
740
  schema,
754
741
  tableNamesMap,
755
742
  table: fullSchema[relationTableTsName],
756
743
  tableConfig: schema[relationTableTsName],
757
- queryConfig: (0, import_entity.is)(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
744
+ queryConfig: (0, import_entity.is)(relation, import_relations.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
758
745
  tableAlias: relationTableAlias,
759
746
  joinOn: joinOn2,
760
747
  nestedQueryRelation: relation
761
748
  });
762
749
  let fieldSql = import_sql.sql`(${builtRelation.sql})`;
763
- if ((0, import_entity.is)(relation, V1.Many)) {
750
+ if ((0, import_entity.is)(relation, import_relations.Many)) {
764
751
  fieldSql = import_sql.sql`coalesce(${fieldSql}, json_array())`;
765
752
  }
766
753
  const field = fieldSql.as(selectedRelationTsKey);
@@ -788,7 +775,7 @@ class MySqlDialect {
788
775
  ),
789
776
  import_sql.sql`, `
790
777
  )})`;
791
- if ((0, import_entity.is)(nestedQueryRelation, V1.Many)) {
778
+ if ((0, import_entity.is)(nestedQueryRelation, import_relations.Many)) {
792
779
  field = import_sql.sql`json_arrayagg(${field})`;
793
780
  }
794
781
  const nestedSelection = [{
@@ -860,175 +847,6 @@ class MySqlDialect {
860
847
  selection
861
848
  };
862
849
  }
863
- nestedSelectionerror() {
864
- throw new import_errors.DrizzleError({
865
- message: `Views with nested selections are not supported by the relational query builder`
866
- });
867
- }
868
- buildRqbColumn(column, key) {
869
- return import_sql.sql`${(0, import_entity.is)(column, import_column.Column) ? import_sql.sql.identifier(column.name) : (0, import_entity.is)(column, import_sql.SQL.Aliased) ? import_sql.sql.identifier(column.fieldAlias) : (0, import_sql.isSQLWrapper)(column) ? import_sql.sql.identifier(key) : this.nestedSelectionerror()} as ${import_sql.sql.identifier(key)}`;
870
- }
871
- unwrapAllColumns = (table, selection) => {
872
- return import_sql.sql.join(
873
- Object.entries(table[import_table.Columns]).map(([k, v]) => {
874
- selection.push({
875
- key: k,
876
- field: v
877
- });
878
- return import_sql.sql`${table}.${this.buildRqbColumn(v, k)}`;
879
- }),
880
- import_sql.sql`, `
881
- );
882
- };
883
- getSelectedTableColumns = (table, columns) => {
884
- const selectedColumns = [];
885
- const columnContainer = table[import_table.Columns];
886
- const entries = Object.entries(columns);
887
- let colSelectionMode;
888
- for (const [k, v] of entries) {
889
- if (v === void 0)
890
- continue;
891
- colSelectionMode = colSelectionMode || v;
892
- if (v) {
893
- const column = columnContainer[k];
894
- selectedColumns.push({
895
- column,
896
- tsName: k
897
- });
898
- }
899
- }
900
- if (colSelectionMode === false) {
901
- for (const [k, v] of Object.entries(columnContainer)) {
902
- if (columns[k] === false)
903
- continue;
904
- selectedColumns.push({
905
- column: v,
906
- tsName: k
907
- });
908
- }
909
- }
910
- return selectedColumns;
911
- };
912
- buildColumns = (table, selection, params) => params?.columns ? (() => {
913
- const columnIdentifiers = [];
914
- const selectedColumns = this.getSelectedTableColumns(table, params.columns);
915
- for (const { column, tsName } of selectedColumns) {
916
- columnIdentifiers.push(import_sql.sql`${table}.${this.buildRqbColumn(column, tsName)}`);
917
- selection.push({
918
- key: tsName,
919
- field: column
920
- });
921
- }
922
- return columnIdentifiers.length ? import_sql.sql.join(columnIdentifiers, import_sql.sql`, `) : void 0;
923
- })() : this.unwrapAllColumns(table, selection);
924
- buildRelationalQuery({
925
- tables,
926
- schema,
927
- tableNamesMap,
928
- table,
929
- tableConfig,
930
- queryConfig: config,
931
- relationWhere,
932
- mode,
933
- errorPath,
934
- depth,
935
- isNested,
936
- throughJoin
937
- }) {
938
- const selection = [];
939
- const isSingle = mode === "first";
940
- const params = config === true ? void 0 : config;
941
- const currentPath = errorPath ?? "";
942
- const currentDepth = depth ?? 0;
943
- if (!currentDepth)
944
- table = (0, import_alias.aliasedTable)(table, `d${currentDepth}`);
945
- const limit = isSingle ? 1 : params?.limit;
946
- const offset = params?.offset;
947
- const columns = this.buildColumns(table, selection, params);
948
- const where = params?.where && relationWhere ? (0, import_expressions.and)((0, import_relations.relationsFilterToSQL)(table, params.where), relationWhere) : params?.where ? (0, import_relations.relationsFilterToSQL)(table, params.where) : relationWhere;
949
- const order = params?.orderBy ? (0, import_relations.relationsOrderToSQL)(table, params.orderBy) : void 0;
950
- const extras = params?.extras ? (0, import_relations.relationExtrasToSQL)(table, params.extras) : void 0;
951
- if (extras)
952
- selection.push(...extras.selection);
953
- const selectionArr = columns ? [columns] : [];
954
- const joins = params ? (() => {
955
- const { with: joins2 } = params;
956
- if (!joins2)
957
- return;
958
- const withEntries = Object.entries(joins2).filter(([_, v]) => v);
959
- if (!withEntries.length)
960
- return;
961
- return import_sql.sql.join(
962
- withEntries.map(([k, join]) => {
963
- selectionArr.push(import_sql.sql`${import_sql.sql.identifier(k)}.${import_sql.sql.identifier("r")} as ${import_sql.sql.identifier(k)}`);
964
- if ((0, import_entity.is)(tableConfig.relations[k], import_relations.AggregatedField)) {
965
- const relation2 = tableConfig.relations[k];
966
- relation2.onTable(table);
967
- const query2 = relation2.getSQL();
968
- selection.push({
969
- key: k,
970
- field: relation2
971
- });
972
- return import_sql.sql` left join lateral (${query2}) as ${import_sql.sql.identifier(k)} on true`;
973
- }
974
- const relation = tableConfig.relations[k];
975
- const isSingle2 = (0, import_entity.is)(relation, import_relations.One);
976
- const targetTable = (0, import_alias.aliasedTable)(relation.targetTable, `d${currentDepth + 1}`);
977
- const throughTable = relation.throughTable ? (0, import_alias.aliasedTable)(relation.throughTable, `tr${currentDepth}`) : void 0;
978
- const { filter, joinCondition } = (0, import_relations.relationToSQL)(
979
- relation,
980
- table,
981
- targetTable,
982
- throughTable
983
- );
984
- const throughJoin2 = throughTable ? import_sql.sql` inner join ${(0, import_relations.getTableAsAliasSQL)(throughTable)} on ${joinCondition}` : void 0;
985
- const innerQuery = this.buildRelationalQuery({
986
- table: targetTable,
987
- mode: isSingle2 ? "first" : "many",
988
- schema,
989
- queryConfig: join,
990
- tableConfig: schema[tableNamesMap[(0, import_table.getTableUniqueName)(relation.targetTable)]],
991
- tableNamesMap,
992
- tables,
993
- relationWhere: filter,
994
- errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
995
- depth: currentDepth + 1,
996
- isNested: true,
997
- throughJoin: throughJoin2
998
- });
999
- selection.push({
1000
- field: targetTable,
1001
- key: k,
1002
- selection: innerQuery.selection,
1003
- isArray: !isSingle2,
1004
- isOptional: (relation.optional ?? false) || join !== true && !!join.where
1005
- });
1006
- const jsonColumns = import_sql.sql.join(
1007
- innerQuery.selection.map((s) => import_sql.sql`${import_sql.sql.raw(this.escapeString(s.key))}, ${import_sql.sql.identifier(s.key)}`),
1008
- import_sql.sql`, `
1009
- );
1010
- const joinQuery = import_sql.sql` left join lateral(select ${import_sql.sql`${isSingle2 ? import_sql.sql`json_object(${jsonColumns})` : import_sql.sql`coalesce(json_arrayagg(json_object(${jsonColumns})), json_array())`} as ${import_sql.sql.identifier("r")}`} from (${innerQuery.sql}) as ${import_sql.sql.identifier("t")}) as ${import_sql.sql.identifier(k)} on true`;
1011
- return joinQuery;
1012
- })
1013
- );
1014
- })() : void 0;
1015
- if (extras?.sql)
1016
- selectionArr.push(extras.sql);
1017
- if (!selectionArr.length) {
1018
- throw new import_errors.DrizzleError({
1019
- message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
1020
- });
1021
- }
1022
- if (isNested && order) {
1023
- selectionArr.push(import_sql.sql`row_number() over (order by ${order})`);
1024
- }
1025
- const selectionSet = import_sql.sql.join(selectionArr, import_sql.sql`, `);
1026
- const query = import_sql.sql`select ${selectionSet} from ${(0, import_relations.getTableAsAliasSQL)(table)}${throughJoin}${import_sql.sql`${joins}`.if(joins)}${import_sql.sql` where ${where}`.if(where)}${import_sql.sql` order by ${order}`.if(order)}${import_sql.sql` limit ${limit}`.if(limit !== void 0)}${import_sql.sql` offset ${offset}`.if(offset !== void 0)}`;
1027
- return {
1028
- sql: query,
1029
- selection
1030
- };
1031
- }
1032
850
  }
1033
851
  // Annotate the CommonJS export names for ESM import in node:
1034
852
  0 && (module.exports = {