drizzle-orm 0.43.0-e2b296d → 0.43.1-26a0497

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 (507) hide show
  1. package/aws-data-api/pg/driver.cjs +5 -1
  2. package/aws-data-api/pg/driver.cjs.map +1 -1
  3. package/aws-data-api/pg/driver.d.cts +1 -0
  4. package/aws-data-api/pg/driver.d.ts +1 -0
  5. package/aws-data-api/pg/driver.js +5 -1
  6. package/aws-data-api/pg/driver.js.map +1 -1
  7. package/aws-data-api/pg/session.cjs +15 -4
  8. package/aws-data-api/pg/session.cjs.map +1 -1
  9. package/aws-data-api/pg/session.d.cts +13 -2
  10. package/aws-data-api/pg/session.d.ts +13 -2
  11. package/aws-data-api/pg/session.js +15 -4
  12. package/aws-data-api/pg/session.js.map +1 -1
  13. package/better-sqlite3/driver.cjs.map +1 -1
  14. package/better-sqlite3/driver.js.map +1 -1
  15. package/better-sqlite3/session.cjs +9 -3
  16. package/better-sqlite3/session.cjs.map +1 -1
  17. package/better-sqlite3/session.d.cts +12 -2
  18. package/better-sqlite3/session.d.ts +12 -2
  19. package/better-sqlite3/session.js +9 -3
  20. package/better-sqlite3/session.js.map +1 -1
  21. package/bun-sql/driver.cjs +5 -1
  22. package/bun-sql/driver.cjs.map +1 -1
  23. package/bun-sql/driver.js +5 -1
  24. package/bun-sql/driver.js.map +1 -1
  25. package/bun-sql/session.cjs +21 -9
  26. package/bun-sql/session.cjs.map +1 -1
  27. package/bun-sql/session.d.cts +12 -2
  28. package/bun-sql/session.d.ts +12 -2
  29. package/bun-sql/session.js +21 -9
  30. package/bun-sql/session.js.map +1 -1
  31. package/cache/core/cache.cjs +47 -0
  32. package/cache/core/cache.cjs.map +1 -0
  33. package/cache/core/cache.d.cts +35 -0
  34. package/cache/core/cache.d.ts +35 -0
  35. package/cache/core/cache.js +22 -0
  36. package/cache/core/cache.js.map +1 -0
  37. package/cache/core/index.cjs +23 -0
  38. package/cache/core/index.cjs.map +1 -0
  39. package/cache/core/index.d.cts +1 -0
  40. package/cache/core/index.d.ts +1 -0
  41. package/cache/core/index.js +2 -0
  42. package/cache/core/index.js.map +1 -0
  43. package/cache/core/types.cjs +17 -0
  44. package/cache/core/types.cjs.map +1 -0
  45. package/cache/core/types.d.cts +33 -0
  46. package/cache/core/types.d.ts +33 -0
  47. package/cache/core/types.js +1 -0
  48. package/cache/core/types.js.map +1 -0
  49. package/cache/upstash/cache.cjs +148 -0
  50. package/cache/upstash/cache.cjs.map +1 -0
  51. package/cache/upstash/cache.d.cts +29 -0
  52. package/cache/upstash/cache.d.ts +29 -0
  53. package/cache/upstash/cache.js +123 -0
  54. package/cache/upstash/cache.js.map +1 -0
  55. package/cache/upstash/index.cjs +23 -0
  56. package/cache/upstash/index.cjs.map +1 -0
  57. package/cache/upstash/index.d.cts +1 -0
  58. package/cache/upstash/index.d.ts +1 -0
  59. package/cache/upstash/index.js +2 -0
  60. package/cache/upstash/index.js.map +1 -0
  61. package/d1/driver.cjs +5 -1
  62. package/d1/driver.cjs.map +1 -1
  63. package/d1/driver.js +5 -1
  64. package/d1/driver.js.map +1 -1
  65. package/d1/session.cjs +23 -9
  66. package/d1/session.cjs.map +1 -1
  67. package/d1/session.d.cts +12 -2
  68. package/d1/session.d.ts +12 -2
  69. package/d1/session.js +23 -9
  70. package/d1/session.js.map +1 -1
  71. package/durable-sqlite/session.cjs +1 -1
  72. package/durable-sqlite/session.cjs.map +1 -1
  73. package/durable-sqlite/session.js +1 -1
  74. package/durable-sqlite/session.js.map +1 -1
  75. package/gel/driver.cjs +9 -2
  76. package/gel/driver.cjs.map +1 -1
  77. package/gel/driver.d.cts +2 -0
  78. package/gel/driver.d.ts +2 -0
  79. package/gel/driver.js +9 -2
  80. package/gel/driver.js.map +1 -1
  81. package/gel/session.cjs +25 -10
  82. package/gel/session.cjs.map +1 -1
  83. package/gel/session.d.cts +12 -2
  84. package/gel/session.d.ts +12 -2
  85. package/gel/session.js +25 -10
  86. package/gel/session.js.map +1 -1
  87. package/gel-core/db.cjs +1 -0
  88. package/gel-core/db.cjs.map +1 -1
  89. package/gel-core/db.d.cts +4 -0
  90. package/gel-core/db.d.ts +4 -0
  91. package/gel-core/db.js +1 -0
  92. package/gel-core/db.js.map +1 -1
  93. package/gel-core/dialect.cjs +1 -1
  94. package/gel-core/dialect.cjs.map +1 -1
  95. package/gel-core/dialect.js +1 -1
  96. package/gel-core/dialect.js.map +1 -1
  97. package/gel-core/query-builders/delete.cjs +5 -1
  98. package/gel-core/query-builders/delete.cjs.map +1 -1
  99. package/gel-core/query-builders/delete.js +5 -1
  100. package/gel-core/query-builders/delete.js.map +1 -1
  101. package/gel-core/query-builders/insert.cjs +5 -1
  102. package/gel-core/query-builders/insert.cjs.map +1 -1
  103. package/gel-core/query-builders/insert.js +5 -1
  104. package/gel-core/query-builders/insert.js.map +1 -1
  105. package/gel-core/query-builders/select.cjs +29 -4
  106. package/gel-core/query-builders/select.cjs.map +1 -1
  107. package/gel-core/query-builders/select.d.cts +9 -0
  108. package/gel-core/query-builders/select.d.ts +9 -0
  109. package/gel-core/query-builders/select.js +29 -4
  110. package/gel-core/query-builders/select.js.map +1 -1
  111. package/gel-core/query-builders/update.cjs +5 -1
  112. package/gel-core/query-builders/update.cjs.map +1 -1
  113. package/gel-core/query-builders/update.js +5 -1
  114. package/gel-core/query-builders/update.js.map +1 -1
  115. package/gel-core/session.cjs +52 -1
  116. package/gel-core/session.cjs.map +1 -1
  117. package/gel-core/session.d.cts +14 -3
  118. package/gel-core/session.d.ts +14 -3
  119. package/gel-core/session.js +53 -2
  120. package/gel-core/session.js.map +1 -1
  121. package/gel-core/utils.cjs +16 -0
  122. package/gel-core/utils.cjs.map +1 -1
  123. package/gel-core/utils.d.cts +8 -4
  124. package/gel-core/utils.d.ts +8 -4
  125. package/gel-core/utils.js +15 -0
  126. package/gel-core/utils.js.map +1 -1
  127. package/libsql/driver-core.cjs +5 -1
  128. package/libsql/driver-core.cjs.map +1 -1
  129. package/libsql/driver-core.js +5 -1
  130. package/libsql/driver-core.js.map +1 -1
  131. package/libsql/session.cjs +27 -13
  132. package/libsql/session.cjs.map +1 -1
  133. package/libsql/session.d.cts +12 -2
  134. package/libsql/session.d.ts +12 -2
  135. package/libsql/session.js +27 -13
  136. package/libsql/session.js.map +1 -1
  137. package/mysql-core/db.cjs +1 -0
  138. package/mysql-core/db.cjs.map +1 -1
  139. package/mysql-core/db.d.cts +4 -0
  140. package/mysql-core/db.d.ts +4 -0
  141. package/mysql-core/db.js +1 -0
  142. package/mysql-core/db.js.map +1 -1
  143. package/mysql-core/dialect.cjs +1 -1
  144. package/mysql-core/dialect.cjs.map +1 -1
  145. package/mysql-core/dialect.js +1 -1
  146. package/mysql-core/dialect.js.map +1 -1
  147. package/mysql-core/query-builders/delete.cjs +9 -1
  148. package/mysql-core/query-builders/delete.cjs.map +1 -1
  149. package/mysql-core/query-builders/delete.js +9 -1
  150. package/mysql-core/query-builders/delete.js.map +1 -1
  151. package/mysql-core/query-builders/insert.cjs +8 -1
  152. package/mysql-core/query-builders/insert.cjs.map +1 -1
  153. package/mysql-core/query-builders/insert.d.cts +2 -0
  154. package/mysql-core/query-builders/insert.d.ts +2 -0
  155. package/mysql-core/query-builders/insert.js +8 -1
  156. package/mysql-core/query-builders/insert.js.map +1 -1
  157. package/mysql-core/query-builders/select.cjs +27 -3
  158. package/mysql-core/query-builders/select.cjs.map +1 -1
  159. package/mysql-core/query-builders/select.d.cts +9 -0
  160. package/mysql-core/query-builders/select.d.ts +9 -0
  161. package/mysql-core/query-builders/select.js +28 -4
  162. package/mysql-core/query-builders/select.js.map +1 -1
  163. package/mysql-core/query-builders/update.cjs +11 -1
  164. package/mysql-core/query-builders/update.cjs.map +1 -1
  165. package/mysql-core/query-builders/update.d.cts +2 -0
  166. package/mysql-core/query-builders/update.d.ts +2 -0
  167. package/mysql-core/query-builders/update.js +11 -1
  168. package/mysql-core/query-builders/update.js.map +1 -1
  169. package/mysql-core/session.cjs +53 -0
  170. package/mysql-core/session.cjs.map +1 -1
  171. package/mysql-core/session.d.cts +15 -2
  172. package/mysql-core/session.d.ts +15 -2
  173. package/mysql-core/session.js +54 -1
  174. package/mysql-core/session.js.map +1 -1
  175. package/mysql-core/utils.cjs +16 -0
  176. package/mysql-core/utils.cjs.map +1 -1
  177. package/mysql-core/utils.d.cts +6 -2
  178. package/mysql-core/utils.d.ts +6 -2
  179. package/mysql-core/utils.js +15 -0
  180. package/mysql-core/utils.js.map +1 -1
  181. package/mysql-proxy/session.cjs +15 -5
  182. package/mysql-proxy/session.cjs.map +1 -1
  183. package/mysql-proxy/session.d.cts +12 -2
  184. package/mysql-proxy/session.d.ts +12 -2
  185. package/mysql-proxy/session.js +15 -5
  186. package/mysql-proxy/session.js.map +1 -1
  187. package/mysql2/driver.cjs +10 -2
  188. package/mysql2/driver.cjs.map +1 -1
  189. package/mysql2/driver.d.cts +2 -0
  190. package/mysql2/driver.d.ts +2 -0
  191. package/mysql2/driver.js +10 -2
  192. package/mysql2/driver.js.map +1 -1
  193. package/mysql2/session.cjs +15 -5
  194. package/mysql2/session.cjs.map +1 -1
  195. package/mysql2/session.d.cts +12 -2
  196. package/mysql2/session.d.ts +12 -2
  197. package/mysql2/session.js +15 -5
  198. package/mysql2/session.js.map +1 -1
  199. package/neon-http/driver.cjs +9 -2
  200. package/neon-http/driver.cjs.map +1 -1
  201. package/neon-http/driver.d.cts +2 -0
  202. package/neon-http/driver.d.ts +2 -0
  203. package/neon-http/driver.js +9 -2
  204. package/neon-http/driver.js.map +1 -1
  205. package/neon-http/session.cjs +25 -15
  206. package/neon-http/session.cjs.map +1 -1
  207. package/neon-http/session.d.cts +12 -2
  208. package/neon-http/session.d.ts +12 -2
  209. package/neon-http/session.js +25 -15
  210. package/neon-http/session.js.map +1 -1
  211. package/neon-serverless/driver.cjs +9 -2
  212. package/neon-serverless/driver.cjs.map +1 -1
  213. package/neon-serverless/driver.d.cts +2 -0
  214. package/neon-serverless/driver.d.ts +2 -0
  215. package/neon-serverless/driver.js +9 -2
  216. package/neon-serverless/driver.js.map +1 -1
  217. package/neon-serverless/session.cjs +21 -7
  218. package/neon-serverless/session.cjs.map +1 -1
  219. package/neon-serverless/session.d.cts +12 -2
  220. package/neon-serverless/session.d.ts +12 -2
  221. package/neon-serverless/session.js +21 -7
  222. package/neon-serverless/session.js.map +1 -1
  223. package/node-postgres/driver.cjs +9 -2
  224. package/node-postgres/driver.cjs.map +1 -1
  225. package/node-postgres/driver.d.cts +2 -0
  226. package/node-postgres/driver.d.ts +2 -0
  227. package/node-postgres/driver.js +9 -2
  228. package/node-postgres/driver.js.map +1 -1
  229. package/node-postgres/session.cjs +19 -6
  230. package/node-postgres/session.cjs.map +1 -1
  231. package/node-postgres/session.d.cts +13 -2
  232. package/node-postgres/session.d.ts +13 -2
  233. package/node-postgres/session.js +19 -6
  234. package/node-postgres/session.js.map +1 -1
  235. package/op-sqlite/driver.cjs +5 -1
  236. package/op-sqlite/driver.cjs.map +1 -1
  237. package/op-sqlite/driver.js +5 -1
  238. package/op-sqlite/driver.js.map +1 -1
  239. package/op-sqlite/session.cjs +23 -9
  240. package/op-sqlite/session.cjs.map +1 -1
  241. package/op-sqlite/session.d.cts +12 -2
  242. package/op-sqlite/session.d.ts +12 -2
  243. package/op-sqlite/session.js +23 -9
  244. package/op-sqlite/session.js.map +1 -1
  245. package/package.json +69 -4
  246. package/pg-core/db.cjs +1 -0
  247. package/pg-core/db.cjs.map +1 -1
  248. package/pg-core/db.d.cts +4 -0
  249. package/pg-core/db.d.ts +4 -0
  250. package/pg-core/db.js +1 -0
  251. package/pg-core/db.js.map +1 -1
  252. package/pg-core/dialect.cjs +1 -1
  253. package/pg-core/dialect.cjs.map +1 -1
  254. package/pg-core/dialect.js +1 -1
  255. package/pg-core/dialect.js.map +1 -1
  256. package/pg-core/query-builders/delete.cjs +6 -1
  257. package/pg-core/query-builders/delete.cjs.map +1 -1
  258. package/pg-core/query-builders/delete.d.cts +3 -1
  259. package/pg-core/query-builders/delete.d.ts +3 -1
  260. package/pg-core/query-builders/delete.js +6 -1
  261. package/pg-core/query-builders/delete.js.map +1 -1
  262. package/pg-core/query-builders/insert.cjs +6 -1
  263. package/pg-core/query-builders/insert.cjs.map +1 -1
  264. package/pg-core/query-builders/insert.d.cts +2 -0
  265. package/pg-core/query-builders/insert.d.ts +2 -0
  266. package/pg-core/query-builders/insert.js +6 -1
  267. package/pg-core/query-builders/insert.js.map +1 -1
  268. package/pg-core/query-builders/select.cjs +31 -5
  269. package/pg-core/query-builders/select.cjs.map +1 -1
  270. package/pg-core/query-builders/select.d.cts +15 -6
  271. package/pg-core/query-builders/select.d.ts +15 -6
  272. package/pg-core/query-builders/select.js +31 -5
  273. package/pg-core/query-builders/select.js.map +1 -1
  274. package/pg-core/query-builders/update.cjs +6 -1
  275. package/pg-core/query-builders/update.cjs.map +1 -1
  276. package/pg-core/query-builders/update.d.cts +4 -2
  277. package/pg-core/query-builders/update.d.ts +4 -2
  278. package/pg-core/query-builders/update.js +6 -1
  279. package/pg-core/query-builders/update.js.map +1 -1
  280. package/pg-core/schema.cjs +2 -2
  281. package/pg-core/schema.cjs.map +1 -1
  282. package/pg-core/schema.d.cts +4 -1
  283. package/pg-core/schema.d.ts +4 -1
  284. package/pg-core/schema.js +2 -2
  285. package/pg-core/schema.js.map +1 -1
  286. package/pg-core/session.cjs +52 -1
  287. package/pg-core/session.cjs.map +1 -1
  288. package/pg-core/session.d.cts +14 -3
  289. package/pg-core/session.d.ts +14 -3
  290. package/pg-core/session.js +53 -2
  291. package/pg-core/session.js.map +1 -1
  292. package/pg-core/utils.cjs +16 -0
  293. package/pg-core/utils.cjs.map +1 -1
  294. package/pg-core/utils.d.cts +8 -4
  295. package/pg-core/utils.d.ts +8 -4
  296. package/pg-core/utils.js +16 -1
  297. package/pg-core/utils.js.map +1 -1
  298. package/pg-proxy/driver.cjs +7 -2
  299. package/pg-proxy/driver.cjs.map +1 -1
  300. package/pg-proxy/driver.js +7 -2
  301. package/pg-proxy/driver.js.map +1 -1
  302. package/pg-proxy/session.cjs +15 -5
  303. package/pg-proxy/session.cjs.map +1 -1
  304. package/pg-proxy/session.d.cts +12 -2
  305. package/pg-proxy/session.d.ts +12 -2
  306. package/pg-proxy/session.js +15 -5
  307. package/pg-proxy/session.js.map +1 -1
  308. package/pglite/driver.cjs +9 -2
  309. package/pglite/driver.cjs.map +1 -1
  310. package/pglite/driver.d.cts +2 -0
  311. package/pglite/driver.d.ts +2 -0
  312. package/pglite/driver.js +9 -2
  313. package/pglite/driver.js.map +1 -1
  314. package/pglite/session.cjs +19 -7
  315. package/pglite/session.cjs.map +1 -1
  316. package/pglite/session.d.cts +12 -2
  317. package/pglite/session.d.ts +12 -2
  318. package/pglite/session.js +19 -7
  319. package/pglite/session.js.map +1 -1
  320. package/planetscale-serverless/driver.cjs +5 -1
  321. package/planetscale-serverless/driver.cjs.map +1 -1
  322. package/planetscale-serverless/driver.d.cts +1 -0
  323. package/planetscale-serverless/driver.d.ts +1 -0
  324. package/planetscale-serverless/driver.js +5 -1
  325. package/planetscale-serverless/driver.js.map +1 -1
  326. package/planetscale-serverless/session.cjs +15 -5
  327. package/planetscale-serverless/session.cjs.map +1 -1
  328. package/planetscale-serverless/session.d.cts +12 -2
  329. package/planetscale-serverless/session.d.ts +12 -2
  330. package/planetscale-serverless/session.js +15 -5
  331. package/planetscale-serverless/session.js.map +1 -1
  332. package/postgres-js/driver.cjs +5 -1
  333. package/postgres-js/driver.cjs.map +1 -1
  334. package/postgres-js/driver.js +5 -1
  335. package/postgres-js/driver.js.map +1 -1
  336. package/postgres-js/session.cjs +18 -6
  337. package/postgres-js/session.cjs.map +1 -1
  338. package/postgres-js/session.d.cts +12 -2
  339. package/postgres-js/session.d.ts +12 -2
  340. package/postgres-js/session.js +18 -6
  341. package/postgres-js/session.js.map +1 -1
  342. package/prisma/mysql/session.cjs +1 -1
  343. package/prisma/mysql/session.cjs.map +1 -1
  344. package/prisma/mysql/session.js +1 -1
  345. package/prisma/mysql/session.js.map +1 -1
  346. package/prisma/pg/session.cjs +1 -1
  347. package/prisma/pg/session.cjs.map +1 -1
  348. package/prisma/pg/session.js +1 -1
  349. package/prisma/pg/session.js.map +1 -1
  350. package/query-builders/query-builder.cjs.map +1 -1
  351. package/query-builders/query-builder.d.cts +2 -1
  352. package/query-builders/query-builder.d.ts +2 -1
  353. package/query-builders/query-builder.js.map +1 -1
  354. package/singlestore/driver.cjs +12 -2
  355. package/singlestore/driver.cjs.map +1 -1
  356. package/singlestore/driver.d.cts +2 -0
  357. package/singlestore/driver.d.ts +2 -0
  358. package/singlestore/driver.js +12 -2
  359. package/singlestore/driver.js.map +1 -1
  360. package/singlestore/session.cjs +15 -5
  361. package/singlestore/session.cjs.map +1 -1
  362. package/singlestore/session.d.cts +12 -2
  363. package/singlestore/session.d.ts +12 -2
  364. package/singlestore/session.js +15 -5
  365. package/singlestore/session.js.map +1 -1
  366. package/singlestore-core/db.cjs +1 -0
  367. package/singlestore-core/db.cjs.map +1 -1
  368. package/singlestore-core/db.d.cts +4 -0
  369. package/singlestore-core/db.d.ts +4 -0
  370. package/singlestore-core/db.js +1 -0
  371. package/singlestore-core/db.js.map +1 -1
  372. package/singlestore-core/dialect.cjs +1 -1
  373. package/singlestore-core/dialect.cjs.map +1 -1
  374. package/singlestore-core/dialect.js +1 -1
  375. package/singlestore-core/dialect.js.map +1 -1
  376. package/singlestore-core/query-builders/delete.cjs +9 -1
  377. package/singlestore-core/query-builders/delete.cjs.map +1 -1
  378. package/singlestore-core/query-builders/delete.js +9 -1
  379. package/singlestore-core/query-builders/delete.js.map +1 -1
  380. package/singlestore-core/query-builders/insert.cjs +6 -1
  381. package/singlestore-core/query-builders/insert.cjs.map +1 -1
  382. package/singlestore-core/query-builders/insert.js +6 -1
  383. package/singlestore-core/query-builders/insert.js.map +1 -1
  384. package/singlestore-core/query-builders/select.cjs +28 -3
  385. package/singlestore-core/query-builders/select.cjs.map +1 -1
  386. package/singlestore-core/query-builders/select.d.cts +9 -0
  387. package/singlestore-core/query-builders/select.d.ts +9 -0
  388. package/singlestore-core/query-builders/select.js +28 -3
  389. package/singlestore-core/query-builders/select.js.map +1 -1
  390. package/singlestore-core/query-builders/update.cjs +9 -1
  391. package/singlestore-core/query-builders/update.cjs.map +1 -1
  392. package/singlestore-core/query-builders/update.js +9 -1
  393. package/singlestore-core/query-builders/update.js.map +1 -1
  394. package/singlestore-core/session.cjs +53 -0
  395. package/singlestore-core/session.cjs.map +1 -1
  396. package/singlestore-core/session.d.cts +14 -2
  397. package/singlestore-core/session.d.ts +14 -2
  398. package/singlestore-core/session.js +54 -1
  399. package/singlestore-core/session.js.map +1 -1
  400. package/singlestore-core/utils.cjs +16 -0
  401. package/singlestore-core/utils.cjs.map +1 -1
  402. package/singlestore-core/utils.d.cts +3 -0
  403. package/singlestore-core/utils.d.ts +3 -0
  404. package/singlestore-core/utils.js +15 -0
  405. package/singlestore-core/utils.js.map +1 -1
  406. package/sql/sql.cjs +10 -0
  407. package/sql/sql.cjs.map +1 -1
  408. package/sql/sql.js +10 -0
  409. package/sql/sql.js.map +1 -1
  410. package/sqlite-core/db.cjs +1 -0
  411. package/sqlite-core/db.cjs.map +1 -1
  412. package/sqlite-core/db.d.cts +4 -0
  413. package/sqlite-core/db.d.ts +4 -0
  414. package/sqlite-core/db.js +1 -0
  415. package/sqlite-core/db.js.map +1 -1
  416. package/sqlite-core/query-builders/delete.cjs +7 -1
  417. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  418. package/sqlite-core/query-builders/delete.js +7 -1
  419. package/sqlite-core/query-builders/delete.js.map +1 -1
  420. package/sqlite-core/query-builders/insert.cjs +7 -1
  421. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  422. package/sqlite-core/query-builders/insert.js +7 -1
  423. package/sqlite-core/query-builders/insert.js.map +1 -1
  424. package/sqlite-core/query-builders/select.cjs +31 -3
  425. package/sqlite-core/query-builders/select.cjs.map +1 -1
  426. package/sqlite-core/query-builders/select.d.cts +9 -0
  427. package/sqlite-core/query-builders/select.d.ts +9 -0
  428. package/sqlite-core/query-builders/select.js +31 -3
  429. package/sqlite-core/query-builders/select.js.map +1 -1
  430. package/sqlite-core/query-builders/update.cjs +7 -1
  431. package/sqlite-core/query-builders/update.cjs.map +1 -1
  432. package/sqlite-core/query-builders/update.js +7 -1
  433. package/sqlite-core/query-builders/update.js.map +1 -1
  434. package/sqlite-core/session.cjs +62 -3
  435. package/sqlite-core/session.cjs.map +1 -1
  436. package/sqlite-core/session.d.cts +18 -4
  437. package/sqlite-core/session.d.ts +18 -4
  438. package/sqlite-core/session.js +63 -4
  439. package/sqlite-core/session.js.map +1 -1
  440. package/sqlite-core/utils.cjs +16 -0
  441. package/sqlite-core/utils.cjs.map +1 -1
  442. package/sqlite-core/utils.d.cts +6 -2
  443. package/sqlite-core/utils.d.ts +6 -2
  444. package/sqlite-core/utils.js +15 -0
  445. package/sqlite-core/utils.js.map +1 -1
  446. package/sqlite-proxy/driver.cjs +9 -2
  447. package/sqlite-proxy/driver.cjs.map +1 -1
  448. package/sqlite-proxy/driver.js +9 -2
  449. package/sqlite-proxy/driver.js.map +1 -1
  450. package/sqlite-proxy/session.cjs +22 -8
  451. package/sqlite-proxy/session.cjs.map +1 -1
  452. package/sqlite-proxy/session.d.cts +12 -2
  453. package/sqlite-proxy/session.d.ts +12 -2
  454. package/sqlite-proxy/session.js +22 -8
  455. package/sqlite-proxy/session.js.map +1 -1
  456. package/subquery.cjs +4 -3
  457. package/subquery.cjs.map +1 -1
  458. package/subquery.d.cts +2 -1
  459. package/subquery.d.ts +2 -1
  460. package/subquery.js +4 -3
  461. package/subquery.js.map +1 -1
  462. package/tidb-serverless/driver.cjs +5 -1
  463. package/tidb-serverless/driver.cjs.map +1 -1
  464. package/tidb-serverless/driver.d.cts +1 -0
  465. package/tidb-serverless/driver.d.ts +1 -0
  466. package/tidb-serverless/driver.js +5 -1
  467. package/tidb-serverless/driver.js.map +1 -1
  468. package/tidb-serverless/session.cjs +15 -5
  469. package/tidb-serverless/session.cjs.map +1 -1
  470. package/tidb-serverless/session.d.cts +12 -2
  471. package/tidb-serverless/session.d.ts +12 -2
  472. package/tidb-serverless/session.js +15 -5
  473. package/tidb-serverless/session.js.map +1 -1
  474. package/utils.cjs +22 -0
  475. package/utils.cjs.map +1 -1
  476. package/utils.d.cts +3 -0
  477. package/utils.d.ts +3 -0
  478. package/utils.js +11 -0
  479. package/utils.js.map +1 -1
  480. package/vercel-postgres/driver.cjs +9 -2
  481. package/vercel-postgres/driver.cjs.map +1 -1
  482. package/vercel-postgres/driver.d.cts +2 -0
  483. package/vercel-postgres/driver.d.ts +2 -0
  484. package/vercel-postgres/driver.js +9 -2
  485. package/vercel-postgres/driver.js.map +1 -1
  486. package/vercel-postgres/session.cjs +21 -7
  487. package/vercel-postgres/session.cjs.map +1 -1
  488. package/vercel-postgres/session.d.cts +12 -2
  489. package/vercel-postgres/session.d.ts +12 -2
  490. package/vercel-postgres/session.js +21 -7
  491. package/vercel-postgres/session.js.map +1 -1
  492. package/version.cjs +1 -1
  493. package/version.d.cts +1 -1
  494. package/version.d.ts +1 -1
  495. package/version.js +1 -1
  496. package/xata-http/driver.cjs +7 -2
  497. package/xata-http/driver.cjs.map +1 -1
  498. package/xata-http/driver.d.cts +2 -0
  499. package/xata-http/driver.d.ts +2 -0
  500. package/xata-http/driver.js +7 -2
  501. package/xata-http/driver.js.map +1 -1
  502. package/xata-http/session.cjs +21 -7
  503. package/xata-http/session.cjs.map +1 -1
  504. package/xata-http/session.d.cts +12 -2
  505. package/xata-http/session.d.ts +12 -2
  506. package/xata-http/session.js +21 -7
  507. package/xata-http/session.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mysql-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type {\n\tAnyMySqlQueryResultHKT,\n\tMySqlPreparedQueryConfig,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tPreparedQueryHKTBase,\n\tPreparedQueryKind,\n} from '~/mysql-core/session.ts';\nimport type { MySqlTable } from '~/mysql-core/table.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { InferModelFromColumns } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { haveSameKeys, mapUpdateSet } from '~/utils.ts';\nimport type { AnyMySqlColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsOrdered } from './select.types.ts';\nimport type { MySqlUpdateSetSource } from './update.ts';\n\nexport interface MySqlInsertConfig<TTable extends MySqlTable = MySqlTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | MySqlInsertSelectQueryBuilder<TTable> | SQL;\n\tignore: boolean;\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type AnyMySqlInsertConfig = MySqlInsertConfig<MySqlTable>;\n\nexport type MySqlInsertValue<TTable extends MySqlTable> =\n\t& {\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n\t& {};\n\nexport type MySqlInsertSelectQueryBuilder<TTable extends MySqlTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyMySqlColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class MySqlInsertBuilder<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlInsertBuilder';\n\n\tprivate shouldIgnore = false;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: MySqlSession,\n\t\tprivate dialect: MySqlDialect,\n\t) {}\n\n\tignore(): this {\n\t\tthis.shouldIgnore = true;\n\t\treturn this;\n\t}\n\n\tvalues(value: MySqlInsertValue<TTable>): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tvalues(values: MySqlInsertValue<TTable>[]): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tvalues(\n\t\tvalues: MySqlInsertValue<TTable> | MySqlInsertValue<TTable>[],\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\treturn new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => MySqlInsertSelectQueryBuilder<TTable>,\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: SQL): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: MySqlInsertSelectQueryBuilder<TTable>): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| MySqlInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => MySqlInsertSelectQueryBuilder<TTable> | SQL),\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);\n\t}\n}\n\nexport type MySqlInsertWithout<T extends AnyMySqlInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tMySqlInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\n\t\t\t\tT['_']['preparedQueryHKT'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | '$returning'\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type MySqlInsertDynamic<T extends AnyMySqlInsert> = MySqlInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['preparedQueryHKT'],\n\tT['_']['returning']\n>;\n\nexport type MySqlInsertPrepare<\n\tT extends AnyMySqlInsert,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = PreparedQueryKind<\n\tT['_']['preparedQueryHKT'],\n\tMySqlPreparedQueryConfig & {\n\t\texecute: TReturning extends undefined ? MySqlQueryResultKind<T['_']['queryResult'], never> : TReturning[];\n\t\titerator: never;\n\t},\n\ttrue\n>;\n\nexport type MySqlInsertOnDuplicateKeyUpdateConfig<T extends AnyMySqlInsert> = {\n\tset: MySqlUpdateSetSource<T['_']['table']>;\n};\n\nexport type MySqlInsert<\n\tTTable extends MySqlTable = MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT = AnyMySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TReturning, true, never>;\n\nexport type MySqlInsertReturning<\n\tT extends AnyMySqlInsert,\n\tTDynamic extends boolean,\n> = MySqlInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['preparedQueryHKT'],\n\tInferModelFromColumns<GetPrimarySerialOrDefaultKeys<T['_']['table']['_']['columns']>>,\n\tTDynamic,\n\tT['_']['excludedMethods'] | '$returning'\n>;\n\nexport type AnyMySqlInsert = MySqlInsertBase<any, any, any, any, any, any>;\n\nexport interface MySqlInsertBase<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[], 'mysql'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'mysql';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly returning: TReturning;\n\t\treadonly result: TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport type PrimaryKeyKeys<T extends Record<string, AnyMySqlColumn>> = {\n\t[K in keyof T]: T[K]['_']['isPrimaryKey'] extends true ? T[K]['_']['isAutoincrement'] extends true ? K\n\t\t: T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never\n\t\t: never\n\t\t: T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never\n\t\t: never;\n}[keyof T];\n\nexport type GetPrimarySerialOrDefaultKeys<T extends Record<string, AnyMySqlColumn>> = {\n\t[K in PrimaryKeyKeys<T>]: T[K];\n};\n\nexport class MySqlInsertBase<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[], 'mysql'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'MySqlInsert';\n\n\tdeclare protected $table: TTable;\n\n\tprivate config: MySqlInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: MySqlInsertConfig['values'],\n\t\tignore: boolean,\n\t\tprivate session: MySqlSession,\n\t\tprivate dialect: MySqlDialect,\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, select, ignore };\n\t}\n\n\t/**\n\t * Adds an `on duplicate key update` clause to the query.\n\t *\n\t * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}\n\t *\n\t * @param config The `set` clause\n\t *\n\t * @example\n\t * ```ts\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW'})\n\t * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});\n\t * ```\n\t *\n\t * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:\n\t *\n\t * ```ts\n\t * import { sql } from 'drizzle-orm';\n\t *\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onDuplicateKeyUpdate({ set: { id: sql`id` } });\n\t * ```\n\t */\n\tonDuplicateKeyUpdate(\n\t\tconfig: MySqlInsertOnDuplicateKeyUpdateConfig<this>,\n\t): MySqlInsertWithout<this, TDynamic, 'onDuplicateKeyUpdate'> {\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict = sql`update ${setSql}`;\n\t\treturn this as any;\n\t}\n\n\t$returningId(): MySqlInsertWithout<\n\t\tMySqlInsertReturning<this, TDynamic>,\n\t\tTDynamic,\n\t\t'$returningId'\n\t> {\n\t\tconst returning: SelectedFieldsOrdered = [];\n\t\tfor (const [key, value] of Object.entries(this.config.table[Table.Symbol.Columns])) {\n\t\t\tif (value.primary) {\n\t\t\t\treturning.push({ field: value, path: [key] });\n\t\t\t}\n\t\t}\n\t\tthis.config.returning = returning;\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config).sql;\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tprepare(): MySqlInsertPrepare<this, TReturning> {\n\t\tconst { sql, generatedIds } = this.dialect.buildInsertQuery(this.config);\n\t\treturn this.session.prepareQuery(\n\t\t\tthis.dialect.sqlToQuery(sql),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tgeneratedIds,\n\t\t\tthis.config.returning,\n\t\t) as MySqlInsertPrepare<this, TReturning>;\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t};\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n\n\t$dynamic(): MySqlInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAa/B,SAAS,oBAAoB;AAG7B,SAAS,OAAO,KAAK,WAAW;AAEhC,SAAS,SAAS,aAAa;AAC/B,SAAS,cAAc,oBAAoB;AAE3C,SAAS,oBAAoB;AAyBtB,MAAM,mBAIX;AAAA,EAKD,YACS,OACA,SACA,SACP;AAHO;AACA;AACA;AAAA,EACN;AAAA,EARH,QAAiB,UAAU,IAAY;AAAA,EAE/B,eAAe;AAAA,EAQvB,SAAe;AACd,SAAK,eAAe;AACpB,WAAO;AAAA,EACR;AAAA,EAIA,OACC,QAC2D;AAC3D,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,MAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,WAAW,IAAI,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAED,WAAO,IAAI,gBAAgB,KAAK,OAAO,cAAc,KAAK,cAAc,KAAK,SAAS,KAAK,OAAO;AAAA,EACnG;AAAA,EAQA,OACC,aAI2D;AAC3D,UAAM,SAAS,OA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A,EACnD;AAAA,EAEA,QAAe;AACd,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA,EAEA,UAAgD;AAC/C,UAAM,EAAE,KAAAA,MAAK,aAAa,IAAI,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AACvE,WAAO,KAAK,QAAQ;AAAA,MACnB,KAAK,QAAQ,WAAWA,IAAG;AAAA,MAC3B;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK,OAAO;AAAA,IACb;AAAA,EACD;AAAA,EAES,UAAkD,CAAC,sBAAsB;AACjF,WAAO,KAAK,QAAQ,EAAE,QAAQ,iBAAiB;AAAA,EAChD;AAAA,EAEQ,iBAAiB,MAA+C;AACvE,UAAM,OAAO;AACb,WAAO,iBAAgB,mBAAmB;AACzC,aAAO,KAAK,QAAQ,EAAE,SAAS,iBAAiB;AAAA,IACjD;AAAA,EACD;AAAA,EAEA,WAAW,KAAK,eAAe;AAAA,EAE/B,WAAqC;AACpC,WAAO;AAAA,EACR;AACD;","names":["sql"]}
1
+ {"version":3,"sources":["../../../src/mysql-core/query-builders/insert.ts"],"sourcesContent":["import type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type {\n\tAnyMySqlQueryResultHKT,\n\tMySqlPreparedQueryConfig,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tPreparedQueryHKTBase,\n\tPreparedQueryKind,\n} from '~/mysql-core/session.ts';\nimport type { MySqlTable } from '~/mysql-core/table.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { InferModelFromColumns } from '~/table.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { haveSameKeys, mapUpdateSet } from '~/utils.ts';\nimport type { AnyMySqlColumn } from '../columns/common.ts';\nimport { extractUsedTable } from '../utils.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsOrdered } from './select.types.ts';\nimport type { MySqlUpdateSetSource } from './update.ts';\n\nexport interface MySqlInsertConfig<TTable extends MySqlTable = MySqlTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | MySqlInsertSelectQueryBuilder<TTable> | SQL;\n\tignore: boolean;\n\tonConflict?: SQL;\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type AnyMySqlInsertConfig = MySqlInsertConfig<MySqlTable>;\n\nexport type MySqlInsertValue<TTable extends MySqlTable> =\n\t& {\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n\t& {};\n\nexport type MySqlInsertSelectQueryBuilder<TTable extends MySqlTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnyMySqlColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class MySqlInsertBuilder<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlInsertBuilder';\n\n\tprivate shouldIgnore = false;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: MySqlSession,\n\t\tprivate dialect: MySqlDialect,\n\t) {}\n\n\tignore(): this {\n\t\tthis.shouldIgnore = true;\n\t\treturn this;\n\t}\n\n\tvalues(value: MySqlInsertValue<TTable>): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tvalues(values: MySqlInsertValue<TTable>[]): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tvalues(\n\t\tvalues: MySqlInsertValue<TTable> | MySqlInsertValue<TTable>[],\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\treturn new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => MySqlInsertSelectQueryBuilder<TTable>,\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: SQL): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(selectQuery: MySqlInsertSelectQueryBuilder<TTable>): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| MySqlInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => MySqlInsertSelectQueryBuilder<TTable> | SQL),\n\t): MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);\n\t}\n}\n\nexport type MySqlInsertWithout<T extends AnyMySqlInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tMySqlInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\n\t\t\t\tT['_']['preparedQueryHKT'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | '$returning'\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type MySqlInsertDynamic<T extends AnyMySqlInsert> = MySqlInsert<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['preparedQueryHKT'],\n\tT['_']['returning']\n>;\n\nexport type MySqlInsertPrepare<\n\tT extends AnyMySqlInsert,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = PreparedQueryKind<\n\tT['_']['preparedQueryHKT'],\n\tMySqlPreparedQueryConfig & {\n\t\texecute: TReturning extends undefined ? MySqlQueryResultKind<T['_']['queryResult'], never> : TReturning[];\n\t\titerator: never;\n\t},\n\ttrue\n>;\n\nexport type MySqlInsertOnDuplicateKeyUpdateConfig<T extends AnyMySqlInsert> = {\n\tset: MySqlUpdateSetSource<T['_']['table']>;\n};\n\nexport type MySqlInsert<\n\tTTable extends MySqlTable = MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT = AnyMySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TReturning, true, never>;\n\nexport type MySqlInsertReturning<\n\tT extends AnyMySqlInsert,\n\tTDynamic extends boolean,\n> = MySqlInsertBase<\n\tT['_']['table'],\n\tT['_']['queryResult'],\n\tT['_']['preparedQueryHKT'],\n\tInferModelFromColumns<GetPrimarySerialOrDefaultKeys<T['_']['table']['_']['columns']>>,\n\tTDynamic,\n\tT['_']['excludedMethods'] | '$returning'\n>;\n\nexport type AnyMySqlInsert = MySqlInsertBase<any, any, any, any, any, any>;\n\nexport interface MySqlInsertBase<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[], 'mysql'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\treadonly dialect: 'mysql';\n\t\treadonly table: TTable;\n\t\treadonly queryResult: TQueryResult;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly returning: TReturning;\n\t\treadonly result: TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[];\n\t};\n}\n\nexport type PrimaryKeyKeys<T extends Record<string, AnyMySqlColumn>> = {\n\t[K in keyof T]: T[K]['_']['isPrimaryKey'] extends true ? T[K]['_']['isAutoincrement'] extends true ? K\n\t\t: T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never\n\t\t: never\n\t\t: T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never\n\t\t: never;\n}[keyof T];\n\nexport type GetPrimarySerialOrDefaultKeys<T extends Record<string, AnyMySqlColumn>> = {\n\t[K in PrimaryKeyKeys<T>]: T[K];\n};\n\nexport class MySqlInsertBase<\n\tTTable extends MySqlTable,\n\tTQueryResult extends MySqlQueryResultHKT,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[]>\n\timplements\n\t\tRunnableQuery<TReturning extends undefined ? MySqlQueryResultKind<TQueryResult, never> : TReturning[], 'mysql'>,\n\t\tSQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'MySqlInsert';\n\n\tdeclare protected $table: TTable;\n\n\tprivate config: MySqlInsertConfig<TTable>;\n\tprotected cacheConfig?: WithCacheConfig;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: MySqlInsertConfig['values'],\n\t\tignore: boolean,\n\t\tprivate session: MySqlSession,\n\t\tprivate dialect: MySqlDialect,\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, select, ignore };\n\t}\n\n\t/**\n\t * Adds an `on duplicate key update` clause to the query.\n\t *\n\t * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}\n\t *\n\t * @param config The `set` clause\n\t *\n\t * @example\n\t * ```ts\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW'})\n\t * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});\n\t * ```\n\t *\n\t * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:\n\t *\n\t * ```ts\n\t * import { sql } from 'drizzle-orm';\n\t *\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onDuplicateKeyUpdate({ set: { id: sql`id` } });\n\t * ```\n\t */\n\tonDuplicateKeyUpdate(\n\t\tconfig: MySqlInsertOnDuplicateKeyUpdateConfig<this>,\n\t): MySqlInsertWithout<this, TDynamic, 'onDuplicateKeyUpdate'> {\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict = sql`update ${setSql}`;\n\t\treturn this as any;\n\t}\n\n\t$returningId(): MySqlInsertWithout<\n\t\tMySqlInsertReturning<this, TDynamic>,\n\t\tTDynamic,\n\t\t'$returningId'\n\t> {\n\t\tconst returning: SelectedFieldsOrdered = [];\n\t\tfor (const [key, value] of Object.entries(this.config.table[Table.Symbol.Columns])) {\n\t\t\tif (value.primary) {\n\t\t\t\treturning.push({ field: value, path: [key] });\n\t\t\t}\n\t\t}\n\t\tthis.config.returning = returning;\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config).sql;\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tprepare(): MySqlInsertPrepare<this, TReturning> {\n\t\tconst { sql, generatedIds } = this.dialect.buildInsertQuery(this.config);\n\t\treturn this.session.prepareQuery(\n\t\t\tthis.dialect.sqlToQuery(sql),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tgeneratedIds,\n\t\t\tthis.config.returning,\n\t\t\t{\n\t\t\t\ttype: 'insert',\n\t\t\t\ttables: extractUsedTable(this.config.table),\n\t\t\t},\n\t\t\tthis.cacheConfig,\n\t\t) as MySqlInsertPrepare<this, TReturning>;\n\t}\n\n\toverride execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t};\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n\n\t$dynamic(): MySqlInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AACA,SAAS,YAAY,UAAU;AAa/B,SAAS,oBAAoB;AAG7B,SAAS,OAAO,KAAK,WAAW;AAEhC,SAAS,SAAS,aAAa;AAC/B,SAAS,cAAc,oBAAoB;AAE3C,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAyBtB,MAAM,mBAIX;AAAA,EAKD,YACS,OACA,SACA,SACP;AAHO;AACA;AACA;AAAA,EACN;AAAA,EARH,QAAiB,UAAU,IAAY;AAAA,EAE/B,eAAe;AAAA,EAQvB,SAAe;AACd,SAAK,eAAe;AACpB,WAAO;AAAA,EACR;AAAA,EAIA,OACC,QAC2D;AAC3D,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,MAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,WAAW,IAAI,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAED,WAAO,IAAI,gBAAgB,KAAK,OAAO,cAAc,KAAK,cAAc,KAAK,SAAS,KAAK,OAAO;AAAA,EACnG;AAAA,EAQA,OACC,aAI2D;AAC3D,UAAM,SAAS,OAAO,gBAAgB,aAAa,YAAY,IAAI,aAAa,CAAC,IAAI;AAErF,QACC,CAAC,GAAG,QAAQ,GAAG,KACZ,CAAC,aAAa,KAAK,MAAM,OAAO,GAAG,OAAO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AO;AAAA,EACR;AAAA,EAEA,UAAgD;AAC/C,UAAM,EAAE,KAAAA,MAAK,aAAa,IAAI,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AACvE,WAAO,KAAK,QAAQ;AAAA,MACnB,KAAK,QAAQ,WAAWA,IAAG;AAAA,MAC3B;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK,OAAO;AAAA,MACZ;AAAA,QACC,MAAM;AAAA,QACN,QAAQ,iBAAiB,KAAK,OAAO,KAAK;AAAA,MAC3C;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AAAA,EAES,UAAkD,CAAC,sBAAsB;AACjF,WAAO,KAAK,QAAQ,EAAE,QAAQ,iBAAiB;AAAA,EAChD;AAAA,EAEQ,iBAAiB,MAA+C;AACvE,UAAM,OAAO;AACb,WAAO,iBAAgB,mBAAmB;AACzC,aAAO,KAAK,QAAQ,EAAE,SAAS,iBAAiB;AAAA,IACjD;AAAA,EACD;AAAA,EAEA,WAAW,KAAK,eAAe;AAAA,EAE/B,WAAqC;AACpC,WAAO;AAAA,EACR;AACD;","names":["sql"]}
@@ -113,6 +113,8 @@ class MySqlSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder
113
113
  /** @internal */
114
114
  session;
115
115
  dialect;
116
+ cacheConfig = void 0;
117
+ usedTables = /* @__PURE__ */ new Set();
116
118
  constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }) {
117
119
  super();
118
120
  this.config = {
@@ -129,10 +131,17 @@ class MySqlSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder
129
131
  this.session = session;
130
132
  this.dialect = dialect;
131
133
  this._ = {
132
- selectedFields: fields
134
+ selectedFields: fields,
135
+ config: this.config
133
136
  };
134
137
  this.tableName = (0, import_utils.getTableLikeName)(table);
135
138
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
139
+ for (const item of (0, import_utils2.extractUsedTable)(table))
140
+ this.usedTables.add(item);
141
+ }
142
+ /** @internal */
143
+ getUsedTables() {
144
+ return [...this.usedTables];
136
145
  }
137
146
  createJoin(joinType, lateral) {
138
147
  return (table, a, b) => {
@@ -141,6 +150,8 @@ class MySqlSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder
141
150
  const onIndex = isCrossJoin ? a : b;
142
151
  const baseTableName = this.tableName;
143
152
  const tableName = (0, import_utils.getTableLikeName)(table);
153
+ for (const item of (0, import_utils2.extractUsedTable)(table))
154
+ this.usedTables.add(item);
144
155
  if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
145
156
  throw new Error(`Alias "${tableName}" is already used in this query`);
146
157
  }
@@ -784,8 +795,14 @@ class MySqlSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder
784
795
  return rest;
785
796
  }
786
797
  as(alias) {
798
+ const usedTables = [];
799
+ usedTables.push(...(0, import_utils2.extractUsedTable)(this.config.table));
800
+ if (this.config.joins) {
801
+ for (const it of this.config.joins)
802
+ usedTables.push(...(0, import_utils2.extractUsedTable)(it.table));
803
+ }
787
804
  return new Proxy(
788
- new import_subquery.Subquery(this.getSQL(), this.config.fields, alias),
805
+ new import_subquery.Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]),
789
806
  new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
790
807
  );
791
808
  }
@@ -799,6 +816,10 @@ class MySqlSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder
799
816
  $dynamic() {
800
817
  return this;
801
818
  }
819
+ $withCache(config) {
820
+ this.cacheConfig = config === void 0 ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
821
+ return this;
822
+ }
802
823
  }
803
824
  class MySqlSelectBase extends MySqlSelectQueryBuilderBase {
804
825
  static [import_entity.entityKind] = "MySqlSelect";
@@ -807,7 +828,10 @@ class MySqlSelectBase extends MySqlSelectQueryBuilderBase {
807
828
  throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
808
829
  }
809
830
  const fieldsList = (0, import_utils.orderSelectedFields)(this.config.fields);
810
- const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), fieldsList);
831
+ const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), fieldsList, void 0, void 0, void 0, {
832
+ type: "select",
833
+ tables: [...this.usedTables]
834
+ }, this.cacheConfig);
811
835
  query.joinsNotNullableMap = this.joinsNotNullableMap;
812
836
  return query;
813
837
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mysql-core/query-builders/select.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { MySqlColumn } from '~/mysql-core/columns/index.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type { MySqlPreparedQueryConfig, MySqlSession, PreparedQueryHKTBase } from '~/mysql-core/session.ts';\nimport type { SubqueryWithSelection } from '~/mysql-core/subquery.ts';\nimport { MySqlTable } from '~/mysql-core/table.ts';\nimport { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tGetSelectTableSelection,\n\tJoinNullability,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, Placeholder, Query } from '~/sql/sql.ts';\nimport { SQL, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport type { ValueOrArray } from '~/utils.ts';\nimport { applyMixins, getTableColumns, getTableLikeName, haveSameKeys, orderSelectedFields } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport type { IndexBuilder } from '../indexes.ts';\nimport { convertIndexToString, toArray } from '../utils.ts';\nimport { MySqlViewBase } from '../view-base.ts';\nimport type {\n\tAnyMySqlSelect,\n\tCreateMySqlSelectFromBuilderMode,\n\tGetMySqlSetOperators,\n\tLockConfig,\n\tLockStrength,\n\tMySqlCreateSetOperatorFn,\n\tMySqlJoinFn,\n\tMySqlJoinType,\n\tMySqlSelectConfig,\n\tMySqlSelectDynamic,\n\tMySqlSelectHKT,\n\tMySqlSelectHKTBase,\n\tMySqlSelectPrepare,\n\tMySqlSelectWithout,\n\tMySqlSetOperatorExcludedMethods,\n\tMySqlSetOperatorWithResult,\n\tSelectedFields,\n\tSetOperatorRightSelect,\n} from './select.types.ts';\n\nexport type IndexForHint = IndexBuilder | string;\n\nexport type IndexConfig = {\n\tuseIndex?: IndexForHint | IndexForHint[];\n\tforceIndex?: IndexForHint | IndexForHint[];\n\tignoreIndex?: IndexForHint | IndexForHint[];\n};\n\nexport class MySqlSelectBuilder<\n\tTSelection extends SelectedFields | undefined,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTBuilderMode extends 'db' | 'qb' = 'db',\n> {\n\tstatic readonly [entityKind]: string = 'MySqlSelectBuilder';\n\n\tprivate fields: TSelection;\n\tprivate session: MySqlSession | undefined;\n\tprivate dialect: MySqlDialect;\n\tprivate withList: Subquery[] = [];\n\tprivate distinct: boolean | undefined;\n\n\tconstructor(\n\t\tconfig: {\n\t\t\tfields: TSelection;\n\t\t\tsession: MySqlSession | undefined;\n\t\t\tdialect: MySqlDialect;\n\t\t\twithList?: Subquery[];\n\t\t\tdistinct?: boolean;\n\t\t},\n\t) {\n\t\tthis.fields = config.fields;\n\t\tthis.session = config.session;\n\t\tthis.dialect = config.dialect;\n\t\tif (config.withList) {\n\t\t\tthis.withList = config.withList;\n\t\t}\n\t\tthis.distinct = config.distinct;\n\t}\n\n\tfrom<TFrom extends MySqlTable | Subquery | MySqlViewBase | SQL>(\n\t\tsource: TFrom,\n\t\tonIndex?: TFrom extends MySqlTable ? IndexConfig\n\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views',\n\t): CreateMySqlSelectFromBuilderMode<\n\t\tTBuilderMode,\n\t\tGetSelectTableName<TFrom>,\n\t\tTSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,\n\t\tTSelection extends undefined ? 'single' : 'partial',\n\t\tTPreparedQueryHKT\n\t> {\n\t\tconst isPartialSelect = !!this.fields;\n\n\t\tlet fields: SelectedFields;\n\t\tif (this.fields) {\n\t\t\tfields = this.fields;\n\t\t} else if (is(source, Subquery)) {\n\t\t\t// This is required to use the proxy handler to get the correct field values from the subquery\n\t\t\tfields = Object.fromEntries(\n\t\t\t\tObject.keys(source._.selectedFields).map((\n\t\t\t\t\tkey,\n\t\t\t\t) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),\n\t\t\t);\n\t\t} else if (is(source, MySqlViewBase)) {\n\t\t\tfields = source[ViewBaseConfig].selectedFields as SelectedFields;\n\t\t} else if (is(source, SQL)) {\n\t\t\tfields = {};\n\t\t} else {\n\t\t\tfields = getTableColumns<MySqlTable>(source);\n\t\t}\n\n\t\tlet useIndex: string[] = [];\n\t\tlet forceIndex: string[] = [];\n\t\tlet ignoreIndex: string[] = [];\n\t\tif (is(source, MySqlTable) && onIndex && typeof onIndex !== 'string') {\n\t\t\tif (onIndex.useIndex) {\n\t\t\t\tuseIndex = convertIndexToString(toArray(onIndex.useIndex));\n\t\t\t}\n\t\t\tif (onIndex.forceIndex) {\n\t\t\t\tforceIndex = convertIndexToString(toArray(onIndex.forceIndex));\n\t\t\t}\n\t\t\tif (onIndex.ignoreIndex) {\n\t\t\t\tignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));\n\t\t\t}\n\t\t}\n\n\t\treturn new MySqlSelectBase(\n\t\t\t{\n\t\t\t\ttable: source,\n\t\t\t\tfields,\n\t\t\t\tisPartialSelect,\n\t\t\t\tsession: this.session,\n\t\t\t\tdialect: this.dialect,\n\t\t\t\twithList: this.withList,\n\t\t\t\tdistinct: this.distinct,\n\t\t\t\tuseIndex,\n\t\t\t\tforceIndex,\n\t\t\t\tignoreIndex,\n\t\t\t},\n\t\t) as any;\n\t}\n}\n\nexport abstract class MySqlSelectQueryBuilderBase<\n\tTHKT extends MySqlSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends TypedQueryBuilder<TSelectedFields, TResult> {\n\tstatic override readonly [entityKind]: string = 'MySqlSelectQueryBuilder';\n\n\toverride readonly _: {\n\t\treadonly hkt: THKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n\n\tprotected config: MySqlSelectConfig;\n\tprotected joinsNotNullableMap: Record<string, boolean>;\n\tprivate tableName: string | undefined;\n\tprivate isPartialSelect: boolean;\n\t/** @internal */\n\treadonly session: MySqlSession | undefined;\n\tprotected dialect: MySqlDialect;\n\n\tconstructor(\n\t\t{ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }: {\n\t\t\ttable: MySqlSelectConfig['table'];\n\t\t\tfields: MySqlSelectConfig['fields'];\n\t\t\tisPartialSelect: boolean;\n\t\t\tsession: MySqlSession | undefined;\n\t\t\tdialect: MySqlDialect;\n\t\t\twithList: Subquery[];\n\t\t\tdistinct: boolean | undefined;\n\t\t\tuseIndex?: string[];\n\t\t\tforceIndex?: string[];\n\t\t\tignoreIndex?: string[];\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.config = {\n\t\t\twithList,\n\t\t\ttable,\n\t\t\tfields: { ...fields },\n\t\t\tdistinct,\n\t\t\tsetOperators: [],\n\t\t\tuseIndex,\n\t\t\tforceIndex,\n\t\t\tignoreIndex,\n\t\t};\n\t\tthis.isPartialSelect = isPartialSelect;\n\t\tthis.session = session;\n\t\tthis.dialect = dialect;\n\t\tthis._ = {\n\t\t\tselectedFields: fields as TSelectedFields,\n\t\t} as this['_'];\n\t\tthis.tableName = getTableLikeName(table);\n\t\tthis.joinsNotNullableMap = typeof this.tableName === 'string' ? { [this.tableName]: true } : {};\n\t}\n\n\tprivate createJoin<\n\t\tTJoinType extends MySqlJoinType,\n\t\tTIsLateral extends (TJoinType extends 'full' | 'right' ? false : boolean),\n\t>(\n\t\tjoinType: TJoinType,\n\t\tlateral: TIsLateral,\n\t): MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral> {\n\t\treturn <\n\t\t\tTJoinedTable extends MySqlTable | Subquery | MySqlViewBase | SQL,\n\t\t>(\n\t\t\ttable: MySqlTable | Subquery | MySqlViewBase | SQL,\n\t\t\ta?:\n\t\t\t\t| ((aliases: TSelection) => SQL | undefined)\n\t\t\t\t| SQL\n\t\t\t\t| undefined\n\t\t\t\t| (TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views'),\n\t\t\tb?: TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views',\n\t\t) => {\n\t\t\tconst isCrossJoin = joinType === 'cross';\n\t\t\tlet on = (isCrossJoin ? undefined : a) as (\n\t\t\t\t| ((aliases: TSelection) => SQL | undefined)\n\t\t\t\t| SQL\n\t\t\t\t| undefined\n\t\t\t);\n\t\t\tconst onIndex = (isCrossJoin ? a : b) as TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views';\n\n\t\t\tconst baseTableName = this.tableName;\n\t\t\tconst tableName = getTableLikeName(table);\n\n\t\t\tif (typeof tableName === 'string' && this.config.joins?.some((join) => join.alias === tableName)) {\n\t\t\t\tthrow new Error(`Alias \"${tableName}\" is already used in this query`);\n\t\t\t}\n\n\t\t\tif (!this.isPartialSelect) {\n\t\t\t\t// If this is the first join and this is not a partial select and we're not selecting from raw SQL, \"move\" the fields from the main table to the nested object\n\t\t\t\tif (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === 'string') {\n\t\t\t\t\tthis.config.fields = {\n\t\t\t\t\t\t[baseTableName]: this.config.fields,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (typeof tableName === 'string' && !is(table, SQL)) {\n\t\t\t\t\tconst selection = is(table, Subquery)\n\t\t\t\t\t\t? table._.selectedFields\n\t\t\t\t\t\t: is(table, View)\n\t\t\t\t\t\t? table[ViewBaseConfig].selectedFields\n\t\t\t\t\t\t: table[Table.Symbol.Columns];\n\t\t\t\t\tthis.config.fields[tableName] = selection;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof on === 'function') {\n\t\t\t\ton = on(\n\t\t\t\t\tnew Proxy(\n\t\t\t\t\t\tthis.config.fields,\n\t\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t\t) as TSelection,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!this.config.joins) {\n\t\t\t\tthis.config.joins = [];\n\t\t\t}\n\n\t\t\tlet useIndex: string[] = [];\n\t\t\tlet forceIndex: string[] = [];\n\t\t\tlet ignoreIndex: string[] = [];\n\t\t\tif (is(table, MySqlTable) && onIndex && typeof onIndex !== 'string') {\n\t\t\t\tif (onIndex.useIndex) {\n\t\t\t\t\tuseIndex = convertIndexToString(toArray(onIndex.useIndex));\n\t\t\t\t}\n\t\t\t\tif (onIndex.forceIndex) {\n\t\t\t\t\tforceIndex = convertIndexToString(toArray(onIndex.forceIndex));\n\t\t\t\t}\n\t\t\t\tif (onIndex.ignoreIndex) {\n\t\t\t\t\tignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.config.joins.push({ on, table, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex, lateral });\n\n\t\t\tif (typeof tableName === 'string') {\n\t\t\t\tswitch (joinType) {\n\t\t\t\t\tcase 'left': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'right': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'cross':\n\t\t\t\t\tcase 'inner': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Executes a `left join` operation by adding another table to the current query.\n\t *\n\t * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tleftJoin = this.createJoin('left', false);\n\n\t/**\n\t * Executes a `left join lateral` operation by adding subquery to the current query.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tleftJoinLateral = this.createJoin('left', true);\n\n\t/**\n\t * Executes a `right join` operation by adding another table to the current query.\n\t *\n\t * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\trightJoin = this.createJoin('right', false);\n\n\t/**\n\t * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.\n\t *\n\t * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tinnerJoin = this.createJoin('inner', false);\n\n\t/**\n\t * Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tinnerJoinLateral = this.createJoin('inner', true);\n\n\t/**\n\t * Executes a `cross join` operation by combining rows from two tables into a new table.\n\t *\n\t * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}\n\t *\n\t * @param table the table to join.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users, each user with every pet\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .crossJoin(pets)\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .crossJoin(pets)\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .crossJoin(pets, {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tcrossJoin = this.createJoin('cross', false);\n\n\t/**\n\t * Executes a `cross join lateral` operation by combining rows from two queries into a new table.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}\n\t *\n\t * @param table the query to join.\n\t */\n\tcrossJoinLateral = this.createJoin('cross', true);\n\n\tprivate createSetOperator(\n\t\ttype: SetOperator,\n\t\tisAll: boolean,\n\t): <TValue extends MySqlSetOperatorWithResult<TResult>>(\n\t\trightSelection:\n\t\t\t| ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>)\n\t\t\t| SetOperatorRightSelect<TValue, TResult>,\n\t) => MySqlSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tMySqlSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\treturn (rightSelection) => {\n\t\t\tconst rightSelect = (typeof rightSelection === 'function'\n\t\t\t\t? rightSelection(getMySqlSetOperators())\n\t\t\t\t: rightSelection) as TypedQueryBuilder<\n\t\t\t\t\tany,\n\t\t\t\t\tTResult\n\t\t\t\t>;\n\n\t\t\tif (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.config.setOperators.push({ type, isAll, rightSelect });\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Adds `union` set operator to the query.\n\t *\n\t * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all unique names from customers and users tables\n\t * await db.select({ name: users.name })\n\t * .from(users)\n\t * .union(\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * // or\n\t * import { union } from 'drizzle-orm/mysql-core'\n\t *\n\t * await union(\n\t * db.select({ name: users.name }).from(users),\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * ```\n\t */\n\tunion = this.createSetOperator('union', false);\n\n\t/**\n\t * Adds `union all` set operator to the query.\n\t *\n\t * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all transaction ids from both online and in-store sales\n\t * await db.select({ transaction: onlineSales.transactionId })\n\t * .from(onlineSales)\n\t * .unionAll(\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * // or\n\t * import { unionAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await unionAll(\n\t * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * ```\n\t */\n\tunionAll = this.createSetOperator('union', true);\n\n\t/**\n\t * Adds `intersect` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select course names that are offered in both departments A and B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .intersect(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { intersect } from 'drizzle-orm/mysql-core'\n\t *\n\t * await intersect(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tintersect = this.createSetOperator('intersect', false);\n\n\t/**\n\t * Adds `intersect all` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets including all duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all products and quantities that are ordered by both regular and VIP customers\n\t * await db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders)\n\t * .intersectAll(\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * // or\n\t * import { intersectAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await intersectAll(\n\t * db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders),\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * ```\n\t */\n\tintersectAll = this.createSetOperator('intersect', true);\n\n\t/**\n\t * Adds `except` set operator to the query.\n\t *\n\t * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .except(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { except } from 'drizzle-orm/mysql-core'\n\t *\n\t * await except(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\texcept = this.createSetOperator('except', false);\n\n\t/**\n\t * Adds `except all` set operator to the query.\n\t *\n\t * Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all products that are ordered by regular customers but not by VIP customers\n\t * await db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered,\n\t * })\n\t * .from(regularCustomerOrders)\n\t * .exceptAll(\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered,\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * // or\n\t * import { exceptAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await exceptAll(\n\t * db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders),\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * ```\n\t */\n\texceptAll = this.createSetOperator('except', true);\n\n\t/** @internal */\n\taddSetOperators(setOperators: MySqlSelectConfig['setOperators']): MySqlSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tMySqlSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\tthis.config.setOperators.push(...setOperators);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#filtering}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be selected.\n\t *\n\t * ```ts\n\t * // Select all cars with green color\n\t * await db.select().from(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * await db.select().from(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Select all BMW cars with a green color\n\t * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Select all cars with the green or blue color\n\t * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(\n\t\twhere: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): MySqlSelectWithout<this, TDynamic, 'where'> {\n\t\tif (typeof where === 'function') {\n\t\t\twhere = where(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `having` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @param having the `having` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all brands with more than one car\n\t * await db.select({\n\t * \tbrand: cars.brand,\n\t * \tcount: sql<number>`cast(count(${cars.id}) as int)`,\n\t * })\n\t * .from(cars)\n\t * .groupBy(cars.brand)\n\t * .having(({ count }) => gt(count, 1));\n\t * ```\n\t */\n\thaving(\n\t\thaving: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): MySqlSelectWithout<this, TDynamic, 'having'> {\n\t\tif (typeof having === 'function') {\n\t\t\thaving = having(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.having = having;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `group by` clause to the query.\n\t *\n\t * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Group and count people by their last names\n\t * await db.select({\n\t * lastName: people.lastName,\n\t * count: sql<number>`cast(count(*) as int)`\n\t * })\n\t * .from(people)\n\t * .groupBy(people.lastName);\n\t * ```\n\t */\n\tgroupBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>,\n\t): MySqlSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>]\n\t\t\t| (MySqlColumn | SQL | SQL.Aliased)[]\n\t): MySqlSelectWithout<this, TDynamic, 'groupBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst groupBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t\tthis.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];\n\t\t} else {\n\t\t\tthis.config.groupBy = columns as (MySqlColumn | SQL | SQL.Aliased)[];\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `order by` clause to the query.\n\t *\n\t * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#order-by}\n\t *\n\t * @example\n\t *\n\t * ```\n\t * // Select cars ordered by year\n\t * await db.select().from(cars).orderBy(cars.year);\n\t * ```\n\t *\n\t * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.\n\t *\n\t * ```ts\n\t * // Select cars ordered by year in descending order\n\t * await db.select().from(cars).orderBy(desc(cars.year));\n\t *\n\t * // Select cars ordered by year and price\n\t * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));\n\t * ```\n\t */\n\torderBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>,\n\t): MySqlSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>]\n\t\t\t| (MySqlColumn | SQL | SQL.Aliased)[]\n\t): MySqlSelectWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t} else {\n\t\t\tconst orderByArray = columns as (MySqlColumn | SQL | SQL.Aliased)[];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `limit` clause to the query.\n\t *\n\t * Calling this method will set the maximum number of rows that will be returned by this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param limit the `limit` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the first 10 people from this query.\n\t * await db.select().from(people).limit(10);\n\t * ```\n\t */\n\tlimit(limit: number | Placeholder): MySqlSelectWithout<this, TDynamic, 'limit'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.limit = limit;\n\t\t} else {\n\t\t\tthis.config.limit = limit;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `offset` clause to the query.\n\t *\n\t * Calling this method will skip a number of rows when returning results from this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param offset the `offset` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the 10th-20th people from this query.\n\t * await db.select().from(people).offset(10).limit(10);\n\t * ```\n\t */\n\toffset(offset: number | Placeholder): MySqlSelectWithout<this, TDynamic, 'offset'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.offset = offset;\n\t\t} else {\n\t\t\tthis.config.offset = offset;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `for` clause to the query.\n\t *\n\t * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.\n\t *\n\t * See docs: {@link https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html}\n\t *\n\t * @param strength the lock strength.\n\t * @param config the lock configuration.\n\t */\n\tfor(strength: LockStrength, config: LockConfig = {}): MySqlSelectWithout<this, TDynamic, 'for'> {\n\t\tthis.config.lockingClause = { strength, config };\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildSelectQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tas<TAlias extends string>(\n\t\talias: TAlias,\n\t): SubqueryWithSelection<this['_']['selectedFields'], TAlias> {\n\t\treturn new Proxy(\n\t\t\tnew Subquery(this.getSQL(), this.config.fields, alias),\n\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as SubqueryWithSelection<this['_']['selectedFields'], TAlias>;\n\t}\n\n\t/** @internal */\n\toverride getSelectedFields(): this['_']['selectedFields'] {\n\t\treturn new Proxy(\n\t\t\tthis.config.fields,\n\t\t\tnew SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as this['_']['selectedFields'];\n\t}\n\n\t$dynamic(): MySqlSelectDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n\nexport interface MySqlSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends\n\tMySqlSelectQueryBuilderBase<\n\t\tMySqlSelectHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tQueryPromise<TResult>\n{}\n\nexport class MySqlSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends MySqlSelectQueryBuilderBase<\n\tMySqlSelectHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\tTDynamic,\n\tTExcludedMethods,\n\tTResult,\n\tTSelectedFields\n> {\n\tstatic override readonly [entityKind]: string = 'MySqlSelect';\n\n\tprepare(): MySqlSelectPrepare<this> {\n\t\tif (!this.session) {\n\t\t\tthrow new Error('Cannot execute a query on a query builder. Please use a database instance instead.');\n\t\t}\n\t\tconst fieldsList = orderSelectedFields<MySqlColumn>(this.config.fields);\n\t\tconst query = this.session.prepareQuery<\n\t\t\tMySqlPreparedQueryConfig & { execute: SelectResult<TSelection, TSelectMode, TNullabilityMap>[] },\n\t\t\tTPreparedQueryHKT\n\t\t>(this.dialect.sqlToQuery(this.getSQL()), fieldsList);\n\t\tquery.joinsNotNullableMap = this.joinsNotNullableMap;\n\t\treturn query as MySqlSelectPrepare<this>;\n\t}\n\n\texecute = ((placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t}) as ReturnType<this['prepare']>['execute'];\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n}\n\napplyMixins(MySqlSelectBase, [QueryPromise]);\n\nfunction createSetOperator(type: SetOperator, isAll: boolean): MySqlCreateSetOperatorFn {\n\treturn (leftSelect, rightSelect, ...restSelects) => {\n\t\tconst setOperators = [rightSelect, ...restSelects].map((select) => ({\n\t\t\ttype,\n\t\t\tisAll,\n\t\t\trightSelect: select as AnyMySqlSelect,\n\t\t}));\n\n\t\tfor (const setOperator of setOperators) {\n\t\t\tif (!haveSameKeys((leftSelect as any).getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (leftSelect as AnyMySqlSelect).addSetOperators(setOperators) as any;\n\t};\n}\n\nconst getMySqlSetOperators = () => ({\n\tunion,\n\tunionAll,\n\tintersect,\n\tintersectAll,\n\texcept,\n\texceptAll,\n});\n\n/**\n * Adds `union` set operator to the query.\n *\n * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n *\n * @example\n *\n * ```ts\n * // Select all unique names from customers and users tables\n * import { union } from 'drizzle-orm/mysql-core'\n *\n * await union(\n * db.select({ name: users.name }).from(users),\n * db.select({ name: customers.name }).from(customers)\n * );\n * // or\n * await db.select({ name: users.name })\n * .from(users)\n * .union(\n * db.select({ name: customers.name }).from(customers)\n * );\n * ```\n */\nexport const union = createSetOperator('union', false);\n\n/**\n * Adds `union all` set operator to the query.\n *\n * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n *\n * @example\n *\n * ```ts\n * // Select all transaction ids from both online and in-store sales\n * import { unionAll } from 'drizzle-orm/mysql-core'\n *\n * await unionAll(\n * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * // or\n * await db.select({ transaction: onlineSales.transactionId })\n * .from(onlineSales)\n * .unionAll(\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * ```\n */\nexport const unionAll = createSetOperator('union', true);\n\n/**\n * Adds `intersect` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n *\n * @example\n *\n * ```ts\n * // Select course names that are offered in both departments A and B\n * import { intersect } from 'drizzle-orm/mysql-core'\n *\n * await intersect(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .intersect(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const intersect = createSetOperator('intersect', false);\n\n/**\n * Adds `intersect all` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets including all duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}\n *\n * @example\n *\n * ```ts\n * // Select all products and quantities that are ordered by both regular and VIP customers\n * import { intersectAll } from 'drizzle-orm/mysql-core'\n *\n * await intersectAll(\n * db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders),\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * // or\n * await db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders)\n * .intersectAll(\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * ```\n */\nexport const intersectAll = createSetOperator('intersect', true);\n\n/**\n * Adds `except` set operator to the query.\n *\n * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { except } from 'drizzle-orm/mysql-core'\n *\n * await except(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .except(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const except = createSetOperator('except', false);\n\n/**\n * Adds `except all` set operator to the query.\n *\n * Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}\n *\n * @example\n *\n * ```ts\n * // Select all products that are ordered by regular customers but not by VIP customers\n * import { exceptAll } from 'drizzle-orm/mysql-core'\n *\n * await exceptAll(\n * db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders),\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * // or\n * await db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered,\n * })\n * .from(regularCustomerOrders)\n * .exceptAll(\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered,\n * })\n * .from(v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AkB,aAAa,IAAI;AA2BxD,MAAM,SAAS,kBAAkB,UAAU,KAAK;AA0ChD,MAAM,YAAY,kBAAkB,UAAU,IAAI;","names":["import_table","import_utils"]}
1
+ {"version":3,"sources":["../../../src/mysql-core/query-builders/select.ts"],"sourcesContent":["import type { CacheConfig, WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport type { MySqlColumn } from '~/mysql-core/columns/index.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type { MySqlPreparedQueryConfig, MySqlSession, PreparedQueryHKTBase } from '~/mysql-core/session.ts';\nimport type { SubqueryWithSelection } from '~/mysql-core/subquery.ts';\nimport { MySqlTable } from '~/mysql-core/table.ts';\nimport { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tGetSelectTableSelection,\n\tJoinNullability,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, Placeholder, Query } from '~/sql/sql.ts';\nimport { SQL, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport type { ValueOrArray } from '~/utils.ts';\nimport { applyMixins, getTableColumns, getTableLikeName, haveSameKeys, orderSelectedFields } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport type { IndexBuilder } from '../indexes.ts';\nimport { convertIndexToString, extractUsedTable, toArray } from '../utils.ts';\nimport { MySqlViewBase } from '../view-base.ts';\nimport type {\n\tAnyMySqlSelect,\n\tCreateMySqlSelectFromBuilderMode,\n\tGetMySqlSetOperators,\n\tLockConfig,\n\tLockStrength,\n\tMySqlCreateSetOperatorFn,\n\tMySqlJoinFn,\n\tMySqlJoinType,\n\tMySqlSelectConfig,\n\tMySqlSelectDynamic,\n\tMySqlSelectHKT,\n\tMySqlSelectHKTBase,\n\tMySqlSelectPrepare,\n\tMySqlSelectWithout,\n\tMySqlSetOperatorExcludedMethods,\n\tMySqlSetOperatorWithResult,\n\tSelectedFields,\n\tSetOperatorRightSelect,\n} from './select.types.ts';\n\nexport type IndexForHint = IndexBuilder | string;\n\nexport type IndexConfig = {\n\tuseIndex?: IndexForHint | IndexForHint[];\n\tforceIndex?: IndexForHint | IndexForHint[];\n\tignoreIndex?: IndexForHint | IndexForHint[];\n};\n\nexport class MySqlSelectBuilder<\n\tTSelection extends SelectedFields | undefined,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTBuilderMode extends 'db' | 'qb' = 'db',\n> {\n\tstatic readonly [entityKind]: string = 'MySqlSelectBuilder';\n\n\tprivate fields: TSelection;\n\tprivate session: MySqlSession | undefined;\n\tprivate dialect: MySqlDialect;\n\tprivate withList: Subquery[] = [];\n\tprivate distinct: boolean | undefined;\n\n\tconstructor(\n\t\tconfig: {\n\t\t\tfields: TSelection;\n\t\t\tsession: MySqlSession | undefined;\n\t\t\tdialect: MySqlDialect;\n\t\t\twithList?: Subquery[];\n\t\t\tdistinct?: boolean;\n\t\t},\n\t) {\n\t\tthis.fields = config.fields;\n\t\tthis.session = config.session;\n\t\tthis.dialect = config.dialect;\n\t\tif (config.withList) {\n\t\t\tthis.withList = config.withList;\n\t\t}\n\t\tthis.distinct = config.distinct;\n\t}\n\n\tfrom<TFrom extends MySqlTable | Subquery | MySqlViewBase | SQL>(\n\t\tsource: TFrom,\n\t\tonIndex?: TFrom extends MySqlTable ? IndexConfig\n\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views',\n\t): CreateMySqlSelectFromBuilderMode<\n\t\tTBuilderMode,\n\t\tGetSelectTableName<TFrom>,\n\t\tTSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,\n\t\tTSelection extends undefined ? 'single' : 'partial',\n\t\tTPreparedQueryHKT\n\t> {\n\t\tconst isPartialSelect = !!this.fields;\n\n\t\tlet fields: SelectedFields;\n\t\tif (this.fields) {\n\t\t\tfields = this.fields;\n\t\t} else if (is(source, Subquery)) {\n\t\t\t// This is required to use the proxy handler to get the correct field values from the subquery\n\t\t\tfields = Object.fromEntries(\n\t\t\t\tObject.keys(source._.selectedFields).map((\n\t\t\t\t\tkey,\n\t\t\t\t) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),\n\t\t\t);\n\t\t} else if (is(source, MySqlViewBase)) {\n\t\t\tfields = source[ViewBaseConfig].selectedFields as SelectedFields;\n\t\t} else if (is(source, SQL)) {\n\t\t\tfields = {};\n\t\t} else {\n\t\t\tfields = getTableColumns<MySqlTable>(source);\n\t\t}\n\n\t\tlet useIndex: string[] = [];\n\t\tlet forceIndex: string[] = [];\n\t\tlet ignoreIndex: string[] = [];\n\t\tif (is(source, MySqlTable) && onIndex && typeof onIndex !== 'string') {\n\t\t\tif (onIndex.useIndex) {\n\t\t\t\tuseIndex = convertIndexToString(toArray(onIndex.useIndex));\n\t\t\t}\n\t\t\tif (onIndex.forceIndex) {\n\t\t\t\tforceIndex = convertIndexToString(toArray(onIndex.forceIndex));\n\t\t\t}\n\t\t\tif (onIndex.ignoreIndex) {\n\t\t\t\tignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));\n\t\t\t}\n\t\t}\n\n\t\treturn new MySqlSelectBase(\n\t\t\t{\n\t\t\t\ttable: source,\n\t\t\t\tfields,\n\t\t\t\tisPartialSelect,\n\t\t\t\tsession: this.session,\n\t\t\t\tdialect: this.dialect,\n\t\t\t\twithList: this.withList,\n\t\t\t\tdistinct: this.distinct,\n\t\t\t\tuseIndex,\n\t\t\t\tforceIndex,\n\t\t\t\tignoreIndex,\n\t\t\t},\n\t\t) as any;\n\t}\n}\n\nexport abstract class MySqlSelectQueryBuilderBase<\n\tTHKT extends MySqlSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends TypedQueryBuilder<TSelectedFields, TResult> {\n\tstatic override readonly [entityKind]: string = 'MySqlSelectQueryBuilder';\n\n\toverride readonly _: {\n\t\treadonly hkt: THKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t\treadonly config: MySqlSelectConfig;\n\t};\n\n\tprotected config: MySqlSelectConfig;\n\tprotected joinsNotNullableMap: Record<string, boolean>;\n\tprivate tableName: string | undefined;\n\tprivate isPartialSelect: boolean;\n\t/** @internal */\n\treadonly session: MySqlSession | undefined;\n\tprotected dialect: MySqlDialect;\n\tprotected cacheConfig?: WithCacheConfig = undefined;\n\tprotected usedTables: Set<string> = new Set();\n\n\tconstructor(\n\t\t{ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }: {\n\t\t\ttable: MySqlSelectConfig['table'];\n\t\t\tfields: MySqlSelectConfig['fields'];\n\t\t\tisPartialSelect: boolean;\n\t\t\tsession: MySqlSession | undefined;\n\t\t\tdialect: MySqlDialect;\n\t\t\twithList: Subquery[];\n\t\t\tdistinct: boolean | undefined;\n\t\t\tuseIndex?: string[];\n\t\t\tforceIndex?: string[];\n\t\t\tignoreIndex?: string[];\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.config = {\n\t\t\twithList,\n\t\t\ttable,\n\t\t\tfields: { ...fields },\n\t\t\tdistinct,\n\t\t\tsetOperators: [],\n\t\t\tuseIndex,\n\t\t\tforceIndex,\n\t\t\tignoreIndex,\n\t\t};\n\t\tthis.isPartialSelect = isPartialSelect;\n\t\tthis.session = session;\n\t\tthis.dialect = dialect;\n\t\tthis._ = {\n\t\t\tselectedFields: fields as TSelectedFields,\n\t\t\tconfig: this.config,\n\t\t} as this['_'];\n\t\tthis.tableName = getTableLikeName(table);\n\t\tthis.joinsNotNullableMap = typeof this.tableName === 'string' ? { [this.tableName]: true } : {};\n\t\tfor (const item of extractUsedTable(table)) this.usedTables.add(item);\n\t}\n\n\t/** @internal */\n\tgetUsedTables() {\n\t\treturn [...this.usedTables];\n\t}\n\n\tprivate createJoin<\n\t\tTJoinType extends MySqlJoinType,\n\t\tTIsLateral extends (TJoinType extends 'full' | 'right' ? false : boolean),\n\t>(\n\t\tjoinType: TJoinType,\n\t\tlateral: TIsLateral,\n\t): MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral> {\n\t\treturn <\n\t\t\tTJoinedTable extends MySqlTable | Subquery | MySqlViewBase | SQL,\n\t\t>(\n\t\t\ttable: MySqlTable | Subquery | MySqlViewBase | SQL,\n\t\t\ta?:\n\t\t\t\t| ((aliases: TSelection) => SQL | undefined)\n\t\t\t\t| SQL\n\t\t\t\t| undefined\n\t\t\t\t| (TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views'),\n\t\t\tb?: TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views',\n\t\t) => {\n\t\t\tconst isCrossJoin = joinType === 'cross';\n\t\t\tlet on = (isCrossJoin ? undefined : a) as (\n\t\t\t\t| ((aliases: TSelection) => SQL | undefined)\n\t\t\t\t| SQL\n\t\t\t\t| undefined\n\t\t\t);\n\t\t\tconst onIndex = (isCrossJoin ? a : b) as TJoinedTable extends MySqlTable ? IndexConfig\n\t\t\t\t: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views';\n\n\t\t\tconst baseTableName = this.tableName;\n\t\t\tconst tableName = getTableLikeName(table);\n\n\t\t\t// store all tables used in a query\n\t\t\tfor (const item of extractUsedTable(table)) this.usedTables.add(item);\n\n\t\t\tif (typeof tableName === 'string' && this.config.joins?.some((join) => join.alias === tableName)) {\n\t\t\t\tthrow new Error(`Alias \"${tableName}\" is already used in this query`);\n\t\t\t}\n\n\t\t\tif (!this.isPartialSelect) {\n\t\t\t\t// If this is the first join and this is not a partial select and we're not selecting from raw SQL, \"move\" the fields from the main table to the nested object\n\t\t\t\tif (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === 'string') {\n\t\t\t\t\tthis.config.fields = {\n\t\t\t\t\t\t[baseTableName]: this.config.fields,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (typeof tableName === 'string' && !is(table, SQL)) {\n\t\t\t\t\tconst selection = is(table, Subquery)\n\t\t\t\t\t\t? table._.selectedFields\n\t\t\t\t\t\t: is(table, View)\n\t\t\t\t\t\t? table[ViewBaseConfig].selectedFields\n\t\t\t\t\t\t: table[Table.Symbol.Columns];\n\t\t\t\t\tthis.config.fields[tableName] = selection;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof on === 'function') {\n\t\t\t\ton = on(\n\t\t\t\t\tnew Proxy(\n\t\t\t\t\t\tthis.config.fields,\n\t\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t\t) as TSelection,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!this.config.joins) {\n\t\t\t\tthis.config.joins = [];\n\t\t\t}\n\n\t\t\tlet useIndex: string[] = [];\n\t\t\tlet forceIndex: string[] = [];\n\t\t\tlet ignoreIndex: string[] = [];\n\t\t\tif (is(table, MySqlTable) && onIndex && typeof onIndex !== 'string') {\n\t\t\t\tif (onIndex.useIndex) {\n\t\t\t\t\tuseIndex = convertIndexToString(toArray(onIndex.useIndex));\n\t\t\t\t}\n\t\t\t\tif (onIndex.forceIndex) {\n\t\t\t\t\tforceIndex = convertIndexToString(toArray(onIndex.forceIndex));\n\t\t\t\t}\n\t\t\t\tif (onIndex.ignoreIndex) {\n\t\t\t\t\tignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.config.joins.push({ on, table, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex, lateral });\n\n\t\t\tif (typeof tableName === 'string') {\n\t\t\t\tswitch (joinType) {\n\t\t\t\t\tcase 'left': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'right': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'cross':\n\t\t\t\t\tcase 'inner': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Executes a `left join` operation by adding another table to the current query.\n\t *\n\t * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tleftJoin = this.createJoin('left', false);\n\n\t/**\n\t * Executes a `left join lateral` operation by adding subquery to the current query.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tleftJoinLateral = this.createJoin('left', true);\n\n\t/**\n\t * Executes a `right join` operation by adding another table to the current query.\n\t *\n\t * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\trightJoin = this.createJoin('right', false);\n\n\t/**\n\t * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.\n\t *\n\t * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId), {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tinnerJoin = this.createJoin('inner', false);\n\n\t/**\n\t * Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tinnerJoinLateral = this.createJoin('inner', true);\n\n\t/**\n\t * Executes a `cross join` operation by combining rows from two tables into a new table.\n\t *\n\t * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}\n\t *\n\t * @param table the table to join.\n\t * @param onIndex index hint.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users, each user with every pet\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .crossJoin(pets)\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .crossJoin(pets)\n\t *\n\t * // Select userId and petId with use index hint\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .crossJoin(pets, {\n\t * useIndex: ['pets_owner_id_index']\n\t * })\n\t * ```\n\t */\n\tcrossJoin = this.createJoin('cross', false);\n\n\t/**\n\t * Executes a `cross join lateral` operation by combining rows from two queries into a new table.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}\n\t *\n\t * @param table the query to join.\n\t */\n\tcrossJoinLateral = this.createJoin('cross', true);\n\n\tprivate createSetOperator(\n\t\ttype: SetOperator,\n\t\tisAll: boolean,\n\t): <TValue extends MySqlSetOperatorWithResult<TResult>>(\n\t\trightSelection:\n\t\t\t| ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>)\n\t\t\t| SetOperatorRightSelect<TValue, TResult>,\n\t) => MySqlSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tMySqlSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\treturn (rightSelection) => {\n\t\t\tconst rightSelect = (typeof rightSelection === 'function'\n\t\t\t\t? rightSelection(getMySqlSetOperators())\n\t\t\t\t: rightSelection) as TypedQueryBuilder<\n\t\t\t\t\tany,\n\t\t\t\t\tTResult\n\t\t\t\t>;\n\n\t\t\tif (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.config.setOperators.push({ type, isAll, rightSelect });\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Adds `union` set operator to the query.\n\t *\n\t * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all unique names from customers and users tables\n\t * await db.select({ name: users.name })\n\t * .from(users)\n\t * .union(\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * // or\n\t * import { union } from 'drizzle-orm/mysql-core'\n\t *\n\t * await union(\n\t * db.select({ name: users.name }).from(users),\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * ```\n\t */\n\tunion = this.createSetOperator('union', false);\n\n\t/**\n\t * Adds `union all` set operator to the query.\n\t *\n\t * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all transaction ids from both online and in-store sales\n\t * await db.select({ transaction: onlineSales.transactionId })\n\t * .from(onlineSales)\n\t * .unionAll(\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * // or\n\t * import { unionAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await unionAll(\n\t * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * ```\n\t */\n\tunionAll = this.createSetOperator('union', true);\n\n\t/**\n\t * Adds `intersect` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select course names that are offered in both departments A and B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .intersect(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { intersect } from 'drizzle-orm/mysql-core'\n\t *\n\t * await intersect(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tintersect = this.createSetOperator('intersect', false);\n\n\t/**\n\t * Adds `intersect all` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets including all duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all products and quantities that are ordered by both regular and VIP customers\n\t * await db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders)\n\t * .intersectAll(\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * // or\n\t * import { intersectAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await intersectAll(\n\t * db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders),\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * ```\n\t */\n\tintersectAll = this.createSetOperator('intersect', true);\n\n\t/**\n\t * Adds `except` set operator to the query.\n\t *\n\t * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .except(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { except } from 'drizzle-orm/mysql-core'\n\t *\n\t * await except(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\texcept = this.createSetOperator('except', false);\n\n\t/**\n\t * Adds `except all` set operator to the query.\n\t *\n\t * Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all products that are ordered by regular customers but not by VIP customers\n\t * await db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered,\n\t * })\n\t * .from(regularCustomerOrders)\n\t * .exceptAll(\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered,\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * // or\n\t * import { exceptAll } from 'drizzle-orm/mysql-core'\n\t *\n\t * await exceptAll(\n\t * db.select({\n\t * productId: regularCustomerOrders.productId,\n\t * quantityOrdered: regularCustomerOrders.quantityOrdered\n\t * })\n\t * .from(regularCustomerOrders),\n\t * db.select({\n\t * productId: vipCustomerOrders.productId,\n\t * quantityOrdered: vipCustomerOrders.quantityOrdered\n\t * })\n\t * .from(vipCustomerOrders)\n\t * );\n\t * ```\n\t */\n\texceptAll = this.createSetOperator('except', true);\n\n\t/** @internal */\n\taddSetOperators(setOperators: MySqlSelectConfig['setOperators']): MySqlSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tMySqlSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\tthis.config.setOperators.push(...setOperators);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#filtering}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be selected.\n\t *\n\t * ```ts\n\t * // Select all cars with green color\n\t * await db.select().from(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * await db.select().from(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Select all BMW cars with a green color\n\t * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Select all cars with the green or blue color\n\t * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(\n\t\twhere: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): MySqlSelectWithout<this, TDynamic, 'where'> {\n\t\tif (typeof where === 'function') {\n\t\t\twhere = where(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `having` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @param having the `having` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all brands with more than one car\n\t * await db.select({\n\t * \tbrand: cars.brand,\n\t * \tcount: sql<number>`cast(count(${cars.id}) as int)`,\n\t * })\n\t * .from(cars)\n\t * .groupBy(cars.brand)\n\t * .having(({ count }) => gt(count, 1));\n\t * ```\n\t */\n\thaving(\n\t\thaving: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): MySqlSelectWithout<this, TDynamic, 'having'> {\n\t\tif (typeof having === 'function') {\n\t\t\thaving = having(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.having = having;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `group by` clause to the query.\n\t *\n\t * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Group and count people by their last names\n\t * await db.select({\n\t * lastName: people.lastName,\n\t * count: sql<number>`cast(count(*) as int)`\n\t * })\n\t * .from(people)\n\t * .groupBy(people.lastName);\n\t * ```\n\t */\n\tgroupBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>,\n\t): MySqlSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>]\n\t\t\t| (MySqlColumn | SQL | SQL.Aliased)[]\n\t): MySqlSelectWithout<this, TDynamic, 'groupBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst groupBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t\tthis.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];\n\t\t} else {\n\t\t\tthis.config.groupBy = columns as (MySqlColumn | SQL | SQL.Aliased)[];\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `order by` clause to the query.\n\t *\n\t * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#order-by}\n\t *\n\t * @example\n\t *\n\t * ```\n\t * // Select cars ordered by year\n\t * await db.select().from(cars).orderBy(cars.year);\n\t * ```\n\t *\n\t * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.\n\t *\n\t * ```ts\n\t * // Select cars ordered by year in descending order\n\t * await db.select().from(cars).orderBy(desc(cars.year));\n\t *\n\t * // Select cars ordered by year and price\n\t * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));\n\t * ```\n\t */\n\torderBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>,\n\t): MySqlSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>]\n\t\t\t| (MySqlColumn | SQL | SQL.Aliased)[]\n\t): MySqlSelectWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t} else {\n\t\t\tconst orderByArray = columns as (MySqlColumn | SQL | SQL.Aliased)[];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `limit` clause to the query.\n\t *\n\t * Calling this method will set the maximum number of rows that will be returned by this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param limit the `limit` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the first 10 people from this query.\n\t * await db.select().from(people).limit(10);\n\t * ```\n\t */\n\tlimit(limit: number | Placeholder): MySqlSelectWithout<this, TDynamic, 'limit'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.limit = limit;\n\t\t} else {\n\t\t\tthis.config.limit = limit;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `offset` clause to the query.\n\t *\n\t * Calling this method will skip a number of rows when returning results from this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param offset the `offset` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the 10th-20th people from this query.\n\t * await db.select().from(people).offset(10).limit(10);\n\t * ```\n\t */\n\toffset(offset: number | Placeholder): MySqlSelectWithout<this, TDynamic, 'offset'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.offset = offset;\n\t\t} else {\n\t\t\tthis.config.offset = offset;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `for` clause to the query.\n\t *\n\t * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.\n\t *\n\t * See docs: {@link https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html}\n\t *\n\t * @param strength the lock strength.\n\t * @param config the lock configuration.\n\t */\n\tfor(strength: LockStrength, config: LockConfig = {}): MySqlSelectWithout<this, TDynamic, 'for'> {\n\t\tthis.config.lockingClause = { strength, config };\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildSelectQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tas<TAlias extends string>(\n\t\talias: TAlias,\n\t): SubqueryWithSelection<this['_']['selectedFields'], TAlias> {\n\t\tconst usedTables: string[] = [];\n\t\tusedTables.push(...extractUsedTable(this.config.table));\n\t\tif (this.config.joins) { for (const it of this.config.joins) usedTables.push(...extractUsedTable(it.table)); }\n\n\t\treturn new Proxy(\n\t\t\tnew Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]),\n\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as SubqueryWithSelection<this['_']['selectedFields'], TAlias>;\n\t}\n\n\t/** @internal */\n\toverride getSelectedFields(): this['_']['selectedFields'] {\n\t\treturn new Proxy(\n\t\t\tthis.config.fields,\n\t\t\tnew SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as this['_']['selectedFields'];\n\t}\n\n\t$dynamic(): MySqlSelectDynamic<this> {\n\t\treturn this as any;\n\t}\n\n\t$withCache(config?: { config?: CacheConfig; tag?: string; autoInvalidate?: boolean } | false) {\n\t\tthis.cacheConfig = config === undefined\n\t\t\t? { config: {}, enable: true, autoInvalidate: true }\n\t\t\t: config === false\n\t\t\t? { enable: false }\n\t\t\t: { enable: true, autoInvalidate: true, ...config };\n\t\treturn this;\n\t}\n}\n\nexport interface MySqlSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends\n\tMySqlSelectQueryBuilderBase<\n\t\tMySqlSelectHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tQueryPromise<TResult>\n{}\n\nexport class MySqlSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends MySqlSelectQueryBuilderBase<\n\tMySqlSelectHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\tTDynamic,\n\tTExcludedMethods,\n\tTResult,\n\tTSelectedFields\n> {\n\tstatic override readonly [entityKind]: string = 'MySqlSelect';\n\n\tprepare(): MySqlSelectPrepare<this> {\n\t\tif (!this.session) {\n\t\t\tthrow new Error('Cannot execute a query on a query builder. Please use a database instance instead.');\n\t\t}\n\t\tconst fieldsList = orderSelectedFields<MySqlColumn>(this.config.fields);\n\t\tconst query = this.session.prepareQuery<\n\t\t\tMySqlPreparedQueryConfig & { execute: SelectResult<TSelection, TSelectMode, TNullabilityMap>[] },\n\t\t\tTPreparedQueryHKT\n\t\t>(this.dialect.sqlToQuery(this.getSQL()), fieldsList, undefined, undefined, undefined, {\n\t\t\ttype: 'select',\n\t\t\ttables: [...this.usedTables],\n\t\t}, this.cacheConfig);\n\t\tquery.joinsNotNullableMap = this.joinsNotNullableMap;\n\t\treturn query as MySqlSelectPrepare<this>;\n\t}\n\n\texecute = ((placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t}) as ReturnType<this['prepare']>['execute'];\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n}\n\napplyMixins(MySqlSelectBase, [QueryPromise]);\n\nfunction createSetOperator(type: SetOperator, isAll: boolean): MySqlCreateSetOperatorFn {\n\treturn (leftSelect, rightSelect, ...restSelects) => {\n\t\tconst setOperators = [rightSelect, ...restSelects].map((select) => ({\n\t\t\ttype,\n\t\t\tisAll,\n\t\t\trightSelect: select as AnyMySqlSelect,\n\t\t}));\n\n\t\tfor (const setOperator of setOperators) {\n\t\t\tif (!haveSameKeys((leftSelect as any).getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (leftSelect as AnyMySqlSelect).addSetOperators(setOperators) as any;\n\t};\n}\n\nconst getMySqlSetOperators = () => ({\n\tunion,\n\tunionAll,\n\tintersect,\n\tintersectAll,\n\texcept,\n\texceptAll,\n});\n\n/**\n * Adds `union` set operator to the query.\n *\n * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n *\n * @example\n *\n * ```ts\n * // Select all unique names from customers and users tables\n * import { union } from 'drizzle-orm/mysql-core'\n *\n * await union(\n * db.select({ name: users.name }).from(users),\n * db.select({ name: customers.name }).from(customers)\n * );\n * // or\n * await db.select({ name: users.name })\n * .from(users)\n * .union(\n * db.select({ name: customers.name }).from(customers)\n * );\n * ```\n */\nexport const union = createSetOperator('union', false);\n\n/**\n * Adds `union all` set operator to the query.\n *\n * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n *\n * @example\n *\n * ```ts\n * // Select all transaction ids from both online and in-store sales\n * import { unionAll } from 'drizzle-orm/mysql-core'\n *\n * await unionAll(\n * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * // or\n * await db.select({ transaction: onlineSales.transactionId })\n * .from(onlineSales)\n * .unionAll(\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * ```\n */\nexport const unionAll = createSetOperator('union', true);\n\n/**\n * Adds `intersect` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n *\n * @example\n *\n * ```ts\n * // Select course names that are offered in both departments A and B\n * import { intersect } from 'drizzle-orm/mysql-core'\n *\n * await intersect(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .intersect(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const intersect = createSetOperator('intersect', false);\n\n/**\n * Adds `intersect all` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets including all duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}\n *\n * @example\n *\n * ```ts\n * // Select all products and quantities that are ordered by both regular and VIP customers\n * import { intersectAll } from 'drizzle-orm/mysql-core'\n *\n * await intersectAll(\n * db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders),\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * // or\n * await db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders)\n * .intersectAll(\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * ```\n */\nexport const intersectAll = createSetOperator('intersect', true);\n\n/**\n * Adds `except` set operator to the query.\n *\n * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { except } from 'drizzle-orm/mysql-core'\n *\n * await except(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .except(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const except = createSetOperator('except', false);\n\n/**\n * Adds `except all` set operator to the query.\n *\n * Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}\n *\n * @example\n *\n * ```ts\n * // Select all products that are ordered by regular customers but not by VIP customers\n * import { exceptAll } from 'drizzle-orm/mysql-core'\n *\n * await exceptAll(\n * db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered\n * })\n * .from(regularCustomerOrders),\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered\n * })\n * .from(vipCustomerOrders)\n * );\n * // or\n * await db.select({\n * productId: regularCustomerOrders.productId,\n * quantityOrdered: regularCustomerOrders.quantityOrdered,\n * })\n * .from(regularCustomerOrders)\n * .exceptAll(\n * db.select({\n * productId: vipCustomerOrders.productId,\n * quantityOrdered: vipCustomerOrders.quantityOrdered,\n * })\n * .from(vipCustomerOrders)\n * );\n * ```\n */\nexport const exceptAll = createSetOperator('except', true);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAK/B,mBAA2B;AAC3B,2BAAkC;AAUlC,2BAA6B;AAC7B,6BAAsC;AAEtC,iBAA0B;AAC1B,sBAAyB;AACzB,IAAAA,gBAAsB;AAEtB,mBAAkG;AAClG,yBAA+B;AAE/B,IAAAC,gBAAgE;AAChE,uBAA8B;AA8BvB,MAAM,mBAIX;AAAA,EACD,QAAiB,wBAAU,IAAY;AAAA,EAE/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAuB,CAAC;AAAA,EACxB;AAAA,EAER,YACC,QAOC;AACD,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,QAAI,OAAO,UAAU;AACpB,WAAK,WAAW,OAAO;AAAA,IACxB;AACA,SAAK,WAAW,OAAO;AAAA,EACxB;AAAA,EAEA,KACC,QACA,SAQC;AACD,UAAM,kBAAkB,C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D;AA2BO,MAAM,QAAQ,kBAAkB,SAAS,KAAK;AA2B9C,MAAM,WAAW,kBAAkB,SAAS,IAAI;AA2BhD,MAAM,YAAY,kBAAkB,aAAa,KAAK;AA0CtD,MAAM,eAAe,kBAAkB,aAAa,IAAI;AA2BxD,MAAM,SAAS,kBAAkB,UAAU,KAAK;AA0ChD,MAAM,YAAY,kBAAkB,UAAU,IAAI;","names":["import_table","import_utils"]}
@@ -1,3 +1,4 @@
1
+ import type { CacheConfig, WithCacheConfig } from "../../cache/core/types.cjs";
1
2
  import { entityKind } from "../../entity.cjs";
2
3
  import type { MySqlColumn } from "../columns/index.cjs";
3
4
  import type { MySqlDialect } from "../dialect.cjs";
@@ -49,12 +50,15 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
49
50
  readonly excludedMethods: TExcludedMethods;
50
51
  readonly result: TResult;
51
52
  readonly selectedFields: TSelectedFields;
53
+ readonly config: MySqlSelectConfig;
52
54
  };
53
55
  protected config: MySqlSelectConfig;
54
56
  protected joinsNotNullableMap: Record<string, boolean>;
55
57
  private tableName;
56
58
  private isPartialSelect;
57
59
  protected dialect: MySqlDialect;
60
+ protected cacheConfig?: WithCacheConfig;
61
+ protected usedTables: Set<string>;
58
62
  constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }: {
59
63
  table: MySqlSelectConfig['table'];
60
64
  fields: MySqlSelectConfig['fields'];
@@ -596,6 +600,11 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
596
600
  toSQL(): Query;
597
601
  as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
598
602
  $dynamic(): MySqlSelectDynamic<this>;
603
+ $withCache(config?: {
604
+ config?: CacheConfig;
605
+ tag?: string;
606
+ autoInvalidate?: boolean;
607
+ } | false): this;
599
608
  }
600
609
  export interface MySqlSelectBase<TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TPreparedQueryHKT extends PreparedQueryHKTBase, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends MySqlSelectQueryBuilderBase<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, QueryPromise<TResult> {
601
610
  }
@@ -1,3 +1,4 @@
1
+ import type { CacheConfig, WithCacheConfig } from "../../cache/core/types.js";
1
2
  import { entityKind } from "../../entity.js";
2
3
  import type { MySqlColumn } from "../columns/index.js";
3
4
  import type { MySqlDialect } from "../dialect.js";
@@ -49,12 +50,15 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
49
50
  readonly excludedMethods: TExcludedMethods;
50
51
  readonly result: TResult;
51
52
  readonly selectedFields: TSelectedFields;
53
+ readonly config: MySqlSelectConfig;
52
54
  };
53
55
  protected config: MySqlSelectConfig;
54
56
  protected joinsNotNullableMap: Record<string, boolean>;
55
57
  private tableName;
56
58
  private isPartialSelect;
57
59
  protected dialect: MySqlDialect;
60
+ protected cacheConfig?: WithCacheConfig;
61
+ protected usedTables: Set<string>;
58
62
  constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }: {
59
63
  table: MySqlSelectConfig['table'];
60
64
  fields: MySqlSelectConfig['fields'];
@@ -596,6 +600,11 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
596
600
  toSQL(): Query;
597
601
  as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
598
602
  $dynamic(): MySqlSelectDynamic<this>;
603
+ $withCache(config?: {
604
+ config?: CacheConfig;
605
+ tag?: string;
606
+ autoInvalidate?: boolean;
607
+ } | false): this;
599
608
  }
600
609
  export interface MySqlSelectBase<TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TPreparedQueryHKT extends PreparedQueryHKTBase, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends MySqlSelectQueryBuilderBase<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, QueryPromise<TResult> {
601
610
  }
@@ -8,7 +8,7 @@ import { Subquery } from "../../subquery.js";
8
8
  import { Table } from "../../table.js";
9
9
  import { applyMixins, getTableColumns, getTableLikeName, haveSameKeys, orderSelectedFields } from "../../utils.js";
10
10
  import { ViewBaseConfig } from "../../view-common.js";
11
- import { convertIndexToString, toArray } from "../utils.js";
11
+ import { convertIndexToString, extractUsedTable, toArray } from "../utils.js";
12
12
  import { MySqlViewBase } from "../view-base.js";
13
13
  class MySqlSelectBuilder {
14
14
  static [entityKind] = "MySqlSelectBuilder";
@@ -82,6 +82,8 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
82
82
  /** @internal */
83
83
  session;
84
84
  dialect;
85
+ cacheConfig = void 0;
86
+ usedTables = /* @__PURE__ */ new Set();
85
87
  constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct, useIndex, forceIndex, ignoreIndex }) {
86
88
  super();
87
89
  this.config = {
@@ -98,10 +100,17 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
98
100
  this.session = session;
99
101
  this.dialect = dialect;
100
102
  this._ = {
101
- selectedFields: fields
103
+ selectedFields: fields,
104
+ config: this.config
102
105
  };
103
106
  this.tableName = getTableLikeName(table);
104
107
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
108
+ for (const item of extractUsedTable(table))
109
+ this.usedTables.add(item);
110
+ }
111
+ /** @internal */
112
+ getUsedTables() {
113
+ return [...this.usedTables];
105
114
  }
106
115
  createJoin(joinType, lateral) {
107
116
  return (table, a, b) => {
@@ -110,6 +119,8 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
110
119
  const onIndex = isCrossJoin ? a : b;
111
120
  const baseTableName = this.tableName;
112
121
  const tableName = getTableLikeName(table);
122
+ for (const item of extractUsedTable(table))
123
+ this.usedTables.add(item);
113
124
  if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
114
125
  throw new Error(`Alias "${tableName}" is already used in this query`);
115
126
  }
@@ -753,8 +764,14 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
753
764
  return rest;
754
765
  }
755
766
  as(alias) {
767
+ const usedTables = [];
768
+ usedTables.push(...extractUsedTable(this.config.table));
769
+ if (this.config.joins) {
770
+ for (const it of this.config.joins)
771
+ usedTables.push(...extractUsedTable(it.table));
772
+ }
756
773
  return new Proxy(
757
- new Subquery(this.getSQL(), this.config.fields, alias),
774
+ new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]),
758
775
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
759
776
  );
760
777
  }
@@ -768,6 +785,10 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
768
785
  $dynamic() {
769
786
  return this;
770
787
  }
788
+ $withCache(config) {
789
+ this.cacheConfig = config === void 0 ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
790
+ return this;
791
+ }
771
792
  }
772
793
  class MySqlSelectBase extends MySqlSelectQueryBuilderBase {
773
794
  static [entityKind] = "MySqlSelect";
@@ -776,7 +797,10 @@ class MySqlSelectBase extends MySqlSelectQueryBuilderBase {
776
797
  throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
777
798
  }
778
799
  const fieldsList = orderSelectedFields(this.config.fields);
779
- const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), fieldsList);
800
+ const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), fieldsList, void 0, void 0, void 0, {
801
+ type: "select",
802
+ tables: [...this.usedTables]
803
+ }, this.cacheConfig);
780
804
  query.joinsNotNullableMap = this.joinsNotNullableMap;
781
805
  return query;
782
806
  }