drizzle-orm 0.39.0-b06bbcd → 0.39.0

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 (721) hide show
  1. package/alias.cjs.map +1 -1
  2. package/alias.d.cts +3 -3
  3. package/alias.d.ts +3 -3
  4. package/alias.js.map +1 -1
  5. package/aws-data-api/pg/driver.cjs +5 -19
  6. package/aws-data-api/pg/driver.cjs.map +1 -1
  7. package/aws-data-api/pg/driver.d.cts +8 -9
  8. package/aws-data-api/pg/driver.d.ts +8 -9
  9. package/aws-data-api/pg/driver.js +8 -9
  10. package/aws-data-api/pg/driver.js.map +1 -1
  11. package/aws-data-api/pg/migrator.cjs.map +1 -1
  12. package/aws-data-api/pg/migrator.d.cts +1 -2
  13. package/aws-data-api/pg/migrator.d.ts +1 -2
  14. package/aws-data-api/pg/migrator.js.map +1 -1
  15. package/aws-data-api/pg/session.cjs +4 -67
  16. package/aws-data-api/pg/session.cjs.map +1 -1
  17. package/aws-data-api/pg/session.d.cts +8 -13
  18. package/aws-data-api/pg/session.d.ts +8 -13
  19. package/aws-data-api/pg/session.js +4 -67
  20. package/aws-data-api/pg/session.js.map +1 -1
  21. package/better-sqlite3/driver.cjs +5 -12
  22. package/better-sqlite3/driver.cjs.map +1 -1
  23. package/better-sqlite3/driver.d.cts +6 -7
  24. package/better-sqlite3/driver.d.ts +6 -7
  25. package/better-sqlite3/driver.js +8 -12
  26. package/better-sqlite3/driver.js.map +1 -1
  27. package/better-sqlite3/migrator.cjs.map +1 -1
  28. package/better-sqlite3/migrator.d.cts +1 -2
  29. package/better-sqlite3/migrator.d.ts +1 -2
  30. package/better-sqlite3/migrator.js.map +1 -1
  31. package/better-sqlite3/session.cjs +4 -49
  32. package/better-sqlite3/session.cjs.map +1 -1
  33. package/better-sqlite3/session.d.cts +8 -14
  34. package/better-sqlite3/session.d.ts +8 -14
  35. package/better-sqlite3/session.js +4 -49
  36. package/better-sqlite3/session.js.map +1 -1
  37. package/bun-sql/driver.cjs +96 -0
  38. package/bun-sql/driver.cjs.map +1 -0
  39. package/bun-sql/driver.d.cts +30 -0
  40. package/bun-sql/driver.d.ts +30 -0
  41. package/bun-sql/driver.js +74 -0
  42. package/bun-sql/driver.js.map +1 -0
  43. package/bun-sql/index.cjs +25 -0
  44. package/bun-sql/index.cjs.map +1 -0
  45. package/bun-sql/index.d.cts +2 -0
  46. package/bun-sql/index.d.ts +2 -0
  47. package/bun-sql/index.js +3 -0
  48. package/bun-sql/index.js.map +1 -0
  49. package/bun-sql/migrator.cjs +33 -0
  50. package/bun-sql/migrator.cjs.map +1 -0
  51. package/bun-sql/migrator.d.cts +3 -0
  52. package/bun-sql/migrator.d.ts +3 -0
  53. package/bun-sql/migrator.js +9 -0
  54. package/bun-sql/migrator.js.map +1 -0
  55. package/bun-sql/session.cjs +162 -0
  56. package/bun-sql/session.cjs.map +1 -0
  57. package/bun-sql/session.d.cts +50 -0
  58. package/bun-sql/session.d.ts +50 -0
  59. package/bun-sql/session.js +136 -0
  60. package/bun-sql/session.js.map +1 -0
  61. package/bun-sqlite/driver.cjs +5 -22
  62. package/bun-sqlite/driver.cjs.map +1 -1
  63. package/bun-sqlite/driver.d.cts +6 -7
  64. package/bun-sqlite/driver.d.ts +6 -7
  65. package/bun-sqlite/driver.js +8 -12
  66. package/bun-sqlite/driver.js.map +1 -1
  67. package/bun-sqlite/migrator.cjs.map +1 -1
  68. package/bun-sqlite/migrator.d.cts +1 -2
  69. package/bun-sqlite/migrator.d.ts +1 -2
  70. package/bun-sqlite/migrator.js.map +1 -1
  71. package/bun-sqlite/session.cjs +4 -49
  72. package/bun-sqlite/session.cjs.map +1 -1
  73. package/bun-sqlite/session.d.cts +9 -15
  74. package/bun-sqlite/session.d.ts +9 -15
  75. package/bun-sqlite/session.js +4 -49
  76. package/bun-sqlite/session.js.map +1 -1
  77. package/d1/driver.cjs +5 -22
  78. package/d1/driver.cjs.map +1 -1
  79. package/d1/driver.d.cts +2 -3
  80. package/d1/driver.d.ts +2 -3
  81. package/d1/driver.js +8 -12
  82. package/d1/driver.js.map +1 -1
  83. package/d1/migrator.cjs.map +1 -1
  84. package/d1/migrator.d.cts +1 -2
  85. package/d1/migrator.d.ts +1 -2
  86. package/d1/migrator.js.map +1 -1
  87. package/d1/session.cjs +6 -48
  88. package/d1/session.cjs.map +1 -1
  89. package/d1/session.d.cts +8 -15
  90. package/d1/session.d.ts +8 -15
  91. package/d1/session.js +6 -48
  92. package/d1/session.js.map +1 -1
  93. package/durable-sqlite/driver.cjs +5 -16
  94. package/durable-sqlite/driver.cjs.map +1 -1
  95. package/durable-sqlite/driver.d.cts +2 -3
  96. package/durable-sqlite/driver.d.ts +2 -3
  97. package/durable-sqlite/driver.js +8 -6
  98. package/durable-sqlite/driver.js.map +1 -1
  99. package/durable-sqlite/migrator.cjs.map +1 -1
  100. package/durable-sqlite/migrator.d.cts +1 -2
  101. package/durable-sqlite/migrator.d.ts +1 -2
  102. package/durable-sqlite/migrator.js.map +1 -1
  103. package/durable-sqlite/session.cjs +4 -46
  104. package/durable-sqlite/session.cjs.map +1 -1
  105. package/durable-sqlite/session.d.cts +8 -14
  106. package/durable-sqlite/session.d.ts +8 -14
  107. package/durable-sqlite/session.js +4 -46
  108. package/durable-sqlite/session.js.map +1 -1
  109. package/expo-sqlite/driver.cjs +5 -22
  110. package/expo-sqlite/driver.cjs.map +1 -1
  111. package/expo-sqlite/driver.d.cts +2 -3
  112. package/expo-sqlite/driver.d.ts +2 -3
  113. package/expo-sqlite/driver.js +8 -12
  114. package/expo-sqlite/driver.js.map +1 -1
  115. package/expo-sqlite/migrator.cjs.map +1 -1
  116. package/expo-sqlite/migrator.d.cts +2 -3
  117. package/expo-sqlite/migrator.d.ts +2 -3
  118. package/expo-sqlite/migrator.js.map +1 -1
  119. package/expo-sqlite/query.cjs +2 -13
  120. package/expo-sqlite/query.cjs.map +1 -1
  121. package/expo-sqlite/query.d.cts +1 -2
  122. package/expo-sqlite/query.d.ts +1 -2
  123. package/expo-sqlite/query.js +2 -3
  124. package/expo-sqlite/query.js.map +1 -1
  125. package/expo-sqlite/session.cjs +4 -47
  126. package/expo-sqlite/session.cjs.map +1 -1
  127. package/expo-sqlite/session.d.cts +8 -14
  128. package/expo-sqlite/session.d.ts +8 -14
  129. package/expo-sqlite/session.js +4 -47
  130. package/expo-sqlite/session.js.map +1 -1
  131. package/libsql/driver-core.cjs +5 -22
  132. package/libsql/driver-core.cjs.map +1 -1
  133. package/libsql/driver-core.d.cts +1 -2
  134. package/libsql/driver-core.d.ts +1 -2
  135. package/libsql/driver-core.js +8 -12
  136. package/libsql/driver-core.js.map +1 -1
  137. package/libsql/driver.cjs.map +1 -1
  138. package/libsql/driver.d.cts +5 -6
  139. package/libsql/driver.d.ts +5 -6
  140. package/libsql/driver.js.map +1 -1
  141. package/libsql/http/index.cjs.map +1 -1
  142. package/libsql/http/index.d.cts +5 -6
  143. package/libsql/http/index.d.ts +5 -6
  144. package/libsql/http/index.js.map +1 -1
  145. package/libsql/migrator.cjs.map +1 -1
  146. package/libsql/migrator.d.cts +1 -2
  147. package/libsql/migrator.d.ts +1 -2
  148. package/libsql/migrator.js.map +1 -1
  149. package/libsql/node/index.cjs.map +1 -1
  150. package/libsql/node/index.d.cts +5 -6
  151. package/libsql/node/index.d.ts +5 -6
  152. package/libsql/node/index.js.map +1 -1
  153. package/libsql/session.cjs +4 -56
  154. package/libsql/session.cjs.map +1 -1
  155. package/libsql/session.d.cts +9 -15
  156. package/libsql/session.d.ts +9 -15
  157. package/libsql/session.js +4 -56
  158. package/libsql/session.js.map +1 -1
  159. package/libsql/sqlite3/index.cjs.map +1 -1
  160. package/libsql/sqlite3/index.d.cts +5 -6
  161. package/libsql/sqlite3/index.d.ts +5 -6
  162. package/libsql/sqlite3/index.js.map +1 -1
  163. package/libsql/wasm/index.cjs.map +1 -1
  164. package/libsql/wasm/index.d.cts +5 -6
  165. package/libsql/wasm/index.d.ts +5 -6
  166. package/libsql/wasm/index.js.map +1 -1
  167. package/libsql/web/index.cjs.map +1 -1
  168. package/libsql/web/index.d.cts +5 -6
  169. package/libsql/web/index.d.ts +5 -6
  170. package/libsql/web/index.js.map +1 -1
  171. package/libsql/ws/index.cjs.map +1 -1
  172. package/libsql/ws/index.d.cts +5 -6
  173. package/libsql/ws/index.d.ts +5 -6
  174. package/libsql/ws/index.js.map +1 -1
  175. package/mysql-core/db.cjs +25 -40
  176. package/mysql-core/db.cjs.map +1 -1
  177. package/mysql-core/db.d.cts +12 -22
  178. package/mysql-core/db.d.ts +12 -22
  179. package/mysql-core/db.js +24 -39
  180. package/mysql-core/db.js.map +1 -1
  181. package/mysql-core/dialect.cjs +15 -194
  182. package/mysql-core/dialect.cjs.map +1 -1
  183. package/mysql-core/dialect.d.cts +13 -33
  184. package/mysql-core/dialect.d.ts +13 -33
  185. package/mysql-core/dialect.js +21 -191
  186. package/mysql-core/dialect.js.map +1 -1
  187. package/mysql-core/query-builders/count.cjs.map +1 -1
  188. package/mysql-core/query-builders/count.d.cts +1 -1
  189. package/mysql-core/query-builders/count.d.ts +1 -1
  190. package/mysql-core/query-builders/count.js.map +1 -1
  191. package/mysql-core/query-builders/query-builder.cjs +15 -11
  192. package/mysql-core/query-builders/query-builder.cjs.map +1 -1
  193. package/mysql-core/query-builders/query-builder.d.cts +2 -6
  194. package/mysql-core/query-builders/query-builder.d.ts +2 -6
  195. package/mysql-core/query-builders/query-builder.js +15 -11
  196. package/mysql-core/query-builders/query-builder.js.map +1 -1
  197. package/mysql-core/query-builders/query.cjs +31 -18
  198. package/mysql-core/query-builders/query.cjs.map +1 -1
  199. package/mysql-core/query-builders/query.d.cts +10 -8
  200. package/mysql-core/query-builders/query.d.ts +10 -8
  201. package/mysql-core/query-builders/query.js +31 -18
  202. package/mysql-core/query-builders/query.js.map +1 -1
  203. package/mysql-core/session.cjs +2 -3
  204. package/mysql-core/session.cjs.map +1 -1
  205. package/mysql-core/session.d.cts +7 -10
  206. package/mysql-core/session.d.ts +7 -10
  207. package/mysql-core/session.js +2 -3
  208. package/mysql-core/session.js.map +1 -1
  209. package/mysql-core/subquery.cjs.map +1 -1
  210. package/mysql-core/subquery.d.cts +15 -2
  211. package/mysql-core/subquery.d.ts +15 -2
  212. package/mysql-proxy/driver.cjs +5 -22
  213. package/mysql-proxy/driver.cjs.map +1 -1
  214. package/mysql-proxy/driver.d.cts +2 -3
  215. package/mysql-proxy/driver.d.ts +2 -3
  216. package/mysql-proxy/driver.js +8 -12
  217. package/mysql-proxy/driver.js.map +1 -1
  218. package/mysql-proxy/migrator.cjs.map +1 -1
  219. package/mysql-proxy/migrator.d.cts +1 -2
  220. package/mysql-proxy/migrator.d.ts +1 -2
  221. package/mysql-proxy/migrator.js.map +1 -1
  222. package/mysql-proxy/session.cjs +2 -27
  223. package/mysql-proxy/session.cjs.map +1 -1
  224. package/mysql-proxy/session.d.cts +8 -13
  225. package/mysql-proxy/session.d.ts +8 -13
  226. package/mysql-proxy/session.js +2 -27
  227. package/mysql-proxy/session.js.map +1 -1
  228. package/mysql2/driver.cjs +7 -24
  229. package/mysql2/driver.cjs.map +1 -1
  230. package/mysql2/driver.d.cts +9 -10
  231. package/mysql2/driver.d.ts +9 -10
  232. package/mysql2/driver.js +10 -14
  233. package/mysql2/driver.js.map +1 -1
  234. package/mysql2/migrator.cjs.map +1 -1
  235. package/mysql2/migrator.d.cts +1 -2
  236. package/mysql2/migrator.d.ts +1 -2
  237. package/mysql2/migrator.js.map +1 -1
  238. package/mysql2/session.cjs +2 -30
  239. package/mysql2/session.cjs.map +1 -1
  240. package/mysql2/session.d.cts +8 -13
  241. package/mysql2/session.d.ts +8 -13
  242. package/mysql2/session.js +2 -30
  243. package/mysql2/session.js.map +1 -1
  244. package/neon/index.cjs +2 -0
  245. package/neon/index.cjs.map +1 -1
  246. package/neon/index.d.cts +1 -0
  247. package/neon/index.d.ts +1 -0
  248. package/neon/index.js +1 -0
  249. package/neon/index.js.map +1 -1
  250. package/neon/neon-identity.cjs +38 -0
  251. package/neon/neon-identity.cjs.map +1 -0
  252. package/neon/neon-identity.d.cts +116 -0
  253. package/neon/neon-identity.d.ts +116 -0
  254. package/neon/neon-identity.js +14 -0
  255. package/neon/neon-identity.js.map +1 -0
  256. package/neon-http/driver.cjs +7 -21
  257. package/neon-http/driver.cjs.map +1 -1
  258. package/neon-http/driver.d.cts +9 -10
  259. package/neon-http/driver.d.ts +9 -10
  260. package/neon-http/driver.js +7 -11
  261. package/neon-http/driver.js.map +1 -1
  262. package/neon-http/migrator.cjs.map +1 -1
  263. package/neon-http/migrator.d.cts +1 -2
  264. package/neon-http/migrator.d.ts +1 -2
  265. package/neon-http/migrator.js.map +1 -1
  266. package/neon-http/session.cjs +2 -32
  267. package/neon-http/session.cjs.map +1 -1
  268. package/neon-http/session.d.cts +8 -13
  269. package/neon-http/session.d.ts +8 -13
  270. package/neon-http/session.js +2 -32
  271. package/neon-http/session.js.map +1 -1
  272. package/neon-serverless/driver.cjs +7 -18
  273. package/neon-serverless/driver.cjs.map +1 -1
  274. package/neon-serverless/driver.d.cts +8 -9
  275. package/neon-serverless/driver.d.ts +8 -9
  276. package/neon-serverless/driver.js +10 -8
  277. package/neon-serverless/driver.js.map +1 -1
  278. package/neon-serverless/migrator.cjs.map +1 -1
  279. package/neon-serverless/migrator.d.cts +1 -2
  280. package/neon-serverless/migrator.d.ts +1 -2
  281. package/neon-serverless/migrator.js.map +1 -1
  282. package/neon-serverless/session.cjs +5 -40
  283. package/neon-serverless/session.cjs.map +1 -1
  284. package/neon-serverless/session.d.cts +8 -13
  285. package/neon-serverless/session.d.ts +8 -13
  286. package/neon-serverless/session.js +5 -40
  287. package/neon-serverless/session.js.map +1 -1
  288. package/node-postgres/driver.cjs +7 -13
  289. package/node-postgres/driver.cjs.map +1 -1
  290. package/node-postgres/driver.d.cts +8 -9
  291. package/node-postgres/driver.d.ts +8 -9
  292. package/node-postgres/driver.js +10 -13
  293. package/node-postgres/driver.js.map +1 -1
  294. package/node-postgres/migrator.cjs.map +1 -1
  295. package/node-postgres/migrator.d.cts +1 -2
  296. package/node-postgres/migrator.d.ts +1 -2
  297. package/node-postgres/migrator.js.map +1 -1
  298. package/node-postgres/session.cjs +4 -45
  299. package/node-postgres/session.cjs.map +1 -1
  300. package/node-postgres/session.d.cts +8 -13
  301. package/node-postgres/session.d.ts +8 -13
  302. package/node-postgres/session.js +4 -45
  303. package/node-postgres/session.js.map +1 -1
  304. package/op-sqlite/driver.cjs +5 -22
  305. package/op-sqlite/driver.cjs.map +1 -1
  306. package/op-sqlite/driver.d.cts +2 -3
  307. package/op-sqlite/driver.d.ts +2 -3
  308. package/op-sqlite/driver.js +8 -12
  309. package/op-sqlite/driver.js.map +1 -1
  310. package/op-sqlite/migrator.cjs.map +1 -1
  311. package/op-sqlite/migrator.d.cts +2 -3
  312. package/op-sqlite/migrator.d.ts +2 -3
  313. package/op-sqlite/migrator.js.map +1 -1
  314. package/op-sqlite/session.cjs +4 -47
  315. package/op-sqlite/session.cjs.map +1 -1
  316. package/op-sqlite/session.d.cts +8 -14
  317. package/op-sqlite/session.d.ts +8 -14
  318. package/op-sqlite/session.js +4 -47
  319. package/op-sqlite/session.js.map +1 -1
  320. package/package.json +64 -52
  321. package/pg-core/db.cjs +24 -42
  322. package/pg-core/db.cjs.map +1 -1
  323. package/pg-core/db.d.cts +13 -23
  324. package/pg-core/db.d.ts +13 -23
  325. package/pg-core/db.js +23 -41
  326. package/pg-core/db.js.map +1 -1
  327. package/pg-core/dialect.cjs +488 -161
  328. package/pg-core/dialect.cjs.map +1 -1
  329. package/pg-core/dialect.d.cts +7 -24
  330. package/pg-core/dialect.d.ts +7 -24
  331. package/pg-core/dialect.js +494 -158
  332. package/pg-core/dialect.js.map +1 -1
  333. package/pg-core/query-builders/count.cjs.map +1 -1
  334. package/pg-core/query-builders/count.d.cts +1 -1
  335. package/pg-core/query-builders/count.d.ts +1 -1
  336. package/pg-core/query-builders/count.js.map +1 -1
  337. package/pg-core/query-builders/delete.cjs +13 -0
  338. package/pg-core/query-builders/delete.cjs.map +1 -1
  339. package/pg-core/query-builders/delete.d.cts +13 -10
  340. package/pg-core/query-builders/delete.d.ts +13 -10
  341. package/pg-core/query-builders/delete.js +14 -1
  342. package/pg-core/query-builders/delete.js.map +1 -1
  343. package/pg-core/query-builders/insert.cjs +13 -0
  344. package/pg-core/query-builders/insert.cjs.map +1 -1
  345. package/pg-core/query-builders/insert.d.cts +10 -8
  346. package/pg-core/query-builders/insert.d.ts +10 -8
  347. package/pg-core/query-builders/insert.js +14 -1
  348. package/pg-core/query-builders/insert.js.map +1 -1
  349. package/pg-core/query-builders/query-builder.cjs +15 -11
  350. package/pg-core/query-builders/query-builder.cjs.map +1 -1
  351. package/pg-core/query-builders/query-builder.d.cts +3 -6
  352. package/pg-core/query-builders/query-builder.d.ts +3 -6
  353. package/pg-core/query-builders/query-builder.js +15 -11
  354. package/pg-core/query-builders/query-builder.js.map +1 -1
  355. package/pg-core/query-builders/query.cjs +18 -15
  356. package/pg-core/query-builders/query.cjs.map +1 -1
  357. package/pg-core/query-builders/query.d.cts +6 -6
  358. package/pg-core/query-builders/query.d.ts +6 -6
  359. package/pg-core/query-builders/query.js +18 -15
  360. package/pg-core/query-builders/query.js.map +1 -1
  361. package/pg-core/query-builders/select.cjs +8 -7
  362. package/pg-core/query-builders/select.cjs.map +1 -1
  363. package/pg-core/query-builders/select.d.cts +3 -3
  364. package/pg-core/query-builders/select.d.ts +3 -3
  365. package/pg-core/query-builders/select.js +8 -7
  366. package/pg-core/query-builders/select.js.map +1 -1
  367. package/pg-core/query-builders/select.types.cjs.map +1 -1
  368. package/pg-core/query-builders/select.types.d.cts +3 -2
  369. package/pg-core/query-builders/select.types.d.ts +3 -2
  370. package/pg-core/query-builders/update.cjs +15 -2
  371. package/pg-core/query-builders/update.cjs.map +1 -1
  372. package/pg-core/query-builders/update.d.cts +18 -13
  373. package/pg-core/query-builders/update.d.ts +18 -13
  374. package/pg-core/query-builders/update.js +16 -3
  375. package/pg-core/query-builders/update.js.map +1 -1
  376. package/pg-core/session.cjs +2 -3
  377. package/pg-core/session.cjs.map +1 -1
  378. package/pg-core/session.d.cts +6 -9
  379. package/pg-core/session.d.ts +6 -9
  380. package/pg-core/session.js +2 -3
  381. package/pg-core/session.js.map +1 -1
  382. package/pg-core/subquery.cjs.map +1 -1
  383. package/pg-core/subquery.d.cts +15 -2
  384. package/pg-core/subquery.d.ts +15 -2
  385. package/pg-proxy/driver.cjs +5 -21
  386. package/pg-proxy/driver.cjs.map +1 -1
  387. package/pg-proxy/driver.d.cts +2 -3
  388. package/pg-proxy/driver.d.ts +2 -3
  389. package/pg-proxy/driver.js +8 -11
  390. package/pg-proxy/driver.js.map +1 -1
  391. package/pg-proxy/migrator.cjs.map +1 -1
  392. package/pg-proxy/migrator.d.cts +1 -2
  393. package/pg-proxy/migrator.d.ts +1 -2
  394. package/pg-proxy/migrator.js.map +1 -1
  395. package/pg-proxy/session.cjs +2 -37
  396. package/pg-proxy/session.cjs.map +1 -1
  397. package/pg-proxy/session.d.cts +8 -13
  398. package/pg-proxy/session.d.ts +8 -13
  399. package/pg-proxy/session.js +2 -37
  400. package/pg-proxy/session.js.map +1 -1
  401. package/pglite/driver.cjs +7 -23
  402. package/pglite/driver.cjs.map +1 -1
  403. package/pglite/driver.d.cts +8 -9
  404. package/pglite/driver.d.ts +8 -9
  405. package/pglite/driver.js +10 -13
  406. package/pglite/driver.js.map +1 -1
  407. package/pglite/migrator.cjs.map +1 -1
  408. package/pglite/migrator.d.cts +1 -2
  409. package/pglite/migrator.d.ts +1 -2
  410. package/pglite/migrator.js.map +1 -1
  411. package/pglite/session.cjs +3 -34
  412. package/pglite/session.cjs.map +1 -1
  413. package/pglite/session.d.cts +8 -13
  414. package/pglite/session.d.ts +8 -13
  415. package/pglite/session.js +3 -34
  416. package/pglite/session.js.map +1 -1
  417. package/planetscale-serverless/driver.cjs +5 -22
  418. package/planetscale-serverless/driver.cjs.map +1 -1
  419. package/planetscale-serverless/driver.d.cts +6 -7
  420. package/planetscale-serverless/driver.d.ts +6 -7
  421. package/planetscale-serverless/driver.js +8 -12
  422. package/planetscale-serverless/driver.js.map +1 -1
  423. package/planetscale-serverless/migrator.cjs.map +1 -1
  424. package/planetscale-serverless/migrator.d.cts +1 -2
  425. package/planetscale-serverless/migrator.d.ts +1 -2
  426. package/planetscale-serverless/migrator.js.map +1 -1
  427. package/planetscale-serverless/session.cjs +5 -45
  428. package/planetscale-serverless/session.cjs.map +1 -1
  429. package/planetscale-serverless/session.d.cts +9 -14
  430. package/planetscale-serverless/session.d.ts +9 -14
  431. package/planetscale-serverless/session.js +5 -45
  432. package/planetscale-serverless/session.js.map +1 -1
  433. package/postgres-js/driver.cjs +5 -6
  434. package/postgres-js/driver.cjs.map +1 -1
  435. package/postgres-js/driver.d.cts +6 -7
  436. package/postgres-js/driver.d.ts +6 -7
  437. package/postgres-js/driver.js +8 -6
  438. package/postgres-js/driver.js.map +1 -1
  439. package/postgres-js/migrator.cjs.map +1 -1
  440. package/postgres-js/migrator.d.cts +1 -2
  441. package/postgres-js/migrator.d.ts +1 -2
  442. package/postgres-js/migrator.js.map +1 -1
  443. package/postgres-js/session.cjs +6 -51
  444. package/postgres-js/session.cjs.map +1 -1
  445. package/postgres-js/session.d.cts +9 -15
  446. package/postgres-js/session.d.ts +9 -15
  447. package/postgres-js/session.js +6 -51
  448. package/postgres-js/session.js.map +1 -1
  449. package/prisma/mysql/driver.cjs +1 -1
  450. package/prisma/mysql/driver.cjs.map +1 -1
  451. package/prisma/mysql/driver.js +1 -1
  452. package/prisma/mysql/driver.js.map +1 -1
  453. package/prisma/mysql/session.cjs +0 -3
  454. package/prisma/mysql/session.cjs.map +1 -1
  455. package/prisma/mysql/session.d.cts +1 -3
  456. package/prisma/mysql/session.d.ts +1 -3
  457. package/prisma/mysql/session.js +0 -3
  458. package/prisma/mysql/session.js.map +1 -1
  459. package/prisma/pg/driver.cjs +1 -1
  460. package/prisma/pg/driver.cjs.map +1 -1
  461. package/prisma/pg/driver.js +1 -1
  462. package/prisma/pg/driver.js.map +1 -1
  463. package/prisma/pg/session.cjs +0 -3
  464. package/prisma/pg/session.cjs.map +1 -1
  465. package/prisma/pg/session.d.cts +1 -3
  466. package/prisma/pg/session.d.ts +1 -3
  467. package/prisma/pg/session.js +0 -3
  468. package/prisma/pg/session.js.map +1 -1
  469. package/prisma/sqlite/driver.cjs +1 -1
  470. package/prisma/sqlite/driver.cjs.map +1 -1
  471. package/prisma/sqlite/driver.js +1 -1
  472. package/prisma/sqlite/driver.js.map +1 -1
  473. package/prisma/sqlite/session.cjs +0 -3
  474. package/prisma/sqlite/session.cjs.map +1 -1
  475. package/prisma/sqlite/session.d.cts +2 -4
  476. package/prisma/sqlite/session.d.ts +2 -4
  477. package/prisma/sqlite/session.js +0 -3
  478. package/prisma/sqlite/session.js.map +1 -1
  479. package/query-builders/select.types.cjs.map +1 -1
  480. package/query-builders/select.types.d.cts +1 -1
  481. package/query-builders/select.types.d.ts +1 -1
  482. package/relations.cjs +245 -595
  483. package/relations.cjs.map +1 -1
  484. package/relations.d.cts +131 -276
  485. package/relations.d.ts +131 -276
  486. package/relations.js +239 -589
  487. package/relations.js.map +1 -1
  488. package/singlestore/driver.cjs +1 -1
  489. package/singlestore/driver.cjs.map +1 -1
  490. package/singlestore/driver.d.cts +1 -1
  491. package/singlestore/driver.d.ts +1 -1
  492. package/singlestore/driver.js +3 -3
  493. package/singlestore/driver.js.map +1 -1
  494. package/singlestore/session.cjs.map +1 -1
  495. package/singlestore/session.d.cts +4 -4
  496. package/singlestore/session.d.ts +4 -4
  497. package/singlestore/session.js.map +1 -1
  498. package/singlestore-core/db.cjs +17 -11
  499. package/singlestore-core/db.cjs.map +1 -1
  500. package/singlestore-core/db.d.cts +7 -10
  501. package/singlestore-core/db.d.ts +7 -10
  502. package/singlestore-core/db.js +17 -11
  503. package/singlestore-core/db.js.map +1 -1
  504. package/singlestore-core/dialect.cjs +6 -16
  505. package/singlestore-core/dialect.cjs.map +1 -1
  506. package/singlestore-core/dialect.d.cts +6 -6
  507. package/singlestore-core/dialect.d.ts +6 -6
  508. package/singlestore-core/dialect.js +12 -6
  509. package/singlestore-core/dialect.js.map +1 -1
  510. package/singlestore-core/query-builders/query-builder.cjs +15 -11
  511. package/singlestore-core/query-builders/query-builder.cjs.map +1 -1
  512. package/singlestore-core/query-builders/query-builder.d.cts +2 -6
  513. package/singlestore-core/query-builders/query-builder.d.ts +2 -6
  514. package/singlestore-core/query-builders/query-builder.js +15 -11
  515. package/singlestore-core/query-builders/query-builder.js.map +1 -1
  516. package/singlestore-core/query-builders/query.cjs +2 -12
  517. package/singlestore-core/query-builders/query.cjs.map +1 -1
  518. package/singlestore-core/query-builders/query.d.cts +6 -6
  519. package/singlestore-core/query-builders/query.d.ts +6 -6
  520. package/singlestore-core/query-builders/query.js +4 -2
  521. package/singlestore-core/query-builders/query.js.map +1 -1
  522. package/singlestore-core/session.cjs.map +1 -1
  523. package/singlestore-core/session.d.cts +5 -5
  524. package/singlestore-core/session.d.ts +5 -5
  525. package/singlestore-core/session.js.map +1 -1
  526. package/singlestore-core/subquery.cjs.map +1 -1
  527. package/singlestore-core/subquery.d.cts +15 -2
  528. package/singlestore-core/subquery.d.ts +15 -2
  529. package/singlestore-core/table.cjs.map +1 -1
  530. package/singlestore-core/table.d.cts +12 -12
  531. package/singlestore-core/table.d.ts +12 -12
  532. package/singlestore-core/table.js.map +1 -1
  533. package/singlestore-proxy/driver.cjs +1 -1
  534. package/singlestore-proxy/driver.cjs.map +1 -1
  535. package/singlestore-proxy/driver.js +3 -3
  536. package/singlestore-proxy/driver.js.map +1 -1
  537. package/singlestore-proxy/session.cjs.map +1 -1
  538. package/singlestore-proxy/session.d.cts +4 -4
  539. package/singlestore-proxy/session.d.ts +4 -4
  540. package/singlestore-proxy/session.js.map +1 -1
  541. package/sql/sql.cjs +6 -1
  542. package/sql/sql.cjs.map +1 -1
  543. package/sql/sql.d.cts +9 -8
  544. package/sql/sql.d.ts +9 -8
  545. package/sql/sql.js +5 -1
  546. package/sql/sql.js.map +1 -1
  547. package/sql-js/driver.cjs +5 -16
  548. package/sql-js/driver.cjs.map +1 -1
  549. package/sql-js/driver.d.cts +2 -3
  550. package/sql-js/driver.d.ts +2 -3
  551. package/sql-js/driver.js +8 -6
  552. package/sql-js/driver.js.map +1 -1
  553. package/sql-js/migrator.cjs.map +1 -1
  554. package/sql-js/migrator.d.cts +1 -2
  555. package/sql-js/migrator.d.ts +1 -2
  556. package/sql-js/migrator.js.map +1 -1
  557. package/sql-js/session.cjs +4 -76
  558. package/sql-js/session.cjs.map +1 -1
  559. package/sql-js/session.d.cts +8 -15
  560. package/sql-js/session.d.ts +8 -15
  561. package/sql-js/session.js +4 -76
  562. package/sql-js/session.js.map +1 -1
  563. package/sqlite-core/db.cjs +31 -49
  564. package/sqlite-core/db.cjs.map +1 -1
  565. package/sqlite-core/db.d.cts +12 -23
  566. package/sqlite-core/db.d.ts +12 -23
  567. package/sqlite-core/db.js +30 -48
  568. package/sqlite-core/db.js.map +1 -1
  569. package/sqlite-core/dialect.cjs +7 -183
  570. package/sqlite-core/dialect.cjs.map +1 -1
  571. package/sqlite-core/dialect.d.cts +9 -28
  572. package/sqlite-core/dialect.d.ts +9 -28
  573. package/sqlite-core/dialect.js +13 -180
  574. package/sqlite-core/dialect.js.map +1 -1
  575. package/sqlite-core/query-builders/count.cjs.map +1 -1
  576. package/sqlite-core/query-builders/count.d.cts +1 -1
  577. package/sqlite-core/query-builders/count.d.ts +1 -1
  578. package/sqlite-core/query-builders/count.js.map +1 -1
  579. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  580. package/sqlite-core/query-builders/delete.d.cts +1 -1
  581. package/sqlite-core/query-builders/delete.d.ts +1 -1
  582. package/sqlite-core/query-builders/delete.js.map +1 -1
  583. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  584. package/sqlite-core/query-builders/insert.d.cts +3 -3
  585. package/sqlite-core/query-builders/insert.d.ts +3 -3
  586. package/sqlite-core/query-builders/insert.js.map +1 -1
  587. package/sqlite-core/query-builders/query-builder.cjs +15 -11
  588. package/sqlite-core/query-builders/query-builder.cjs.map +1 -1
  589. package/sqlite-core/query-builders/query-builder.d.cts +2 -6
  590. package/sqlite-core/query-builders/query-builder.d.ts +2 -6
  591. package/sqlite-core/query-builders/query-builder.js +15 -11
  592. package/sqlite-core/query-builders/query-builder.js.map +1 -1
  593. package/sqlite-core/query-builders/query.cjs +32 -53
  594. package/sqlite-core/query-builders/query.cjs.map +1 -1
  595. package/sqlite-core/query-builders/query.d.cts +17 -18
  596. package/sqlite-core/query-builders/query.d.ts +17 -18
  597. package/sqlite-core/query-builders/query.js +32 -53
  598. package/sqlite-core/query-builders/query.js.map +1 -1
  599. package/sqlite-core/query-builders/select.cjs.map +1 -1
  600. package/sqlite-core/query-builders/select.d.cts +3 -3
  601. package/sqlite-core/query-builders/select.d.ts +3 -3
  602. package/sqlite-core/query-builders/select.js.map +1 -1
  603. package/sqlite-core/query-builders/update.cjs.map +1 -1
  604. package/sqlite-core/query-builders/update.d.cts +3 -3
  605. package/sqlite-core/query-builders/update.d.ts +3 -3
  606. package/sqlite-core/query-builders/update.js.map +1 -1
  607. package/sqlite-core/session.cjs +2 -6
  608. package/sqlite-core/session.cjs.map +1 -1
  609. package/sqlite-core/session.d.cts +7 -15
  610. package/sqlite-core/session.d.ts +7 -15
  611. package/sqlite-core/session.js +2 -6
  612. package/sqlite-core/session.js.map +1 -1
  613. package/sqlite-core/subquery.cjs.map +1 -1
  614. package/sqlite-core/subquery.d.cts +15 -2
  615. package/sqlite-core/subquery.d.ts +15 -2
  616. package/sqlite-proxy/driver.cjs +5 -23
  617. package/sqlite-proxy/driver.cjs.map +1 -1
  618. package/sqlite-proxy/driver.d.cts +3 -4
  619. package/sqlite-proxy/driver.d.ts +3 -4
  620. package/sqlite-proxy/driver.js +5 -13
  621. package/sqlite-proxy/driver.js.map +1 -1
  622. package/sqlite-proxy/migrator.cjs.map +1 -1
  623. package/sqlite-proxy/migrator.d.cts +1 -2
  624. package/sqlite-proxy/migrator.d.ts +1 -2
  625. package/sqlite-proxy/migrator.js.map +1 -1
  626. package/sqlite-proxy/session.cjs +6 -50
  627. package/sqlite-proxy/session.cjs.map +1 -1
  628. package/sqlite-proxy/session.d.cts +8 -14
  629. package/sqlite-proxy/session.d.ts +8 -14
  630. package/sqlite-proxy/session.js +6 -50
  631. package/sqlite-proxy/session.js.map +1 -1
  632. package/subquery.cjs.map +1 -1
  633. package/subquery.d.cts +1 -0
  634. package/subquery.d.ts +1 -0
  635. package/subquery.js.map +1 -1
  636. package/table.cjs.map +1 -1
  637. package/table.d.cts +1 -1
  638. package/table.d.ts +1 -1
  639. package/table.js.map +1 -1
  640. package/tidb-serverless/driver.cjs +5 -22
  641. package/tidb-serverless/driver.cjs.map +1 -1
  642. package/tidb-serverless/driver.d.cts +6 -7
  643. package/tidb-serverless/driver.d.ts +6 -7
  644. package/tidb-serverless/driver.js +8 -12
  645. package/tidb-serverless/driver.js.map +1 -1
  646. package/tidb-serverless/migrator.cjs.map +1 -1
  647. package/tidb-serverless/migrator.d.cts +1 -2
  648. package/tidb-serverless/migrator.d.ts +1 -2
  649. package/tidb-serverless/migrator.js.map +1 -1
  650. package/tidb-serverless/session.cjs +5 -62
  651. package/tidb-serverless/session.cjs.map +1 -1
  652. package/tidb-serverless/session.d.cts +9 -14
  653. package/tidb-serverless/session.d.ts +9 -14
  654. package/tidb-serverless/session.js +5 -62
  655. package/tidb-serverless/session.js.map +1 -1
  656. package/utils.cjs +2 -2
  657. package/utils.cjs.map +1 -1
  658. package/utils.d.cts +1 -3
  659. package/utils.d.ts +1 -3
  660. package/utils.js +2 -2
  661. package/utils.js.map +1 -1
  662. package/vercel-postgres/driver.cjs +7 -23
  663. package/vercel-postgres/driver.cjs.map +1 -1
  664. package/vercel-postgres/driver.d.cts +8 -9
  665. package/vercel-postgres/driver.d.ts +8 -9
  666. package/vercel-postgres/driver.js +10 -13
  667. package/vercel-postgres/driver.js.map +1 -1
  668. package/vercel-postgres/migrator.cjs.map +1 -1
  669. package/vercel-postgres/migrator.d.cts +1 -2
  670. package/vercel-postgres/migrator.d.ts +1 -2
  671. package/vercel-postgres/migrator.js.map +1 -1
  672. package/vercel-postgres/session.cjs +8 -34
  673. package/vercel-postgres/session.cjs.map +1 -1
  674. package/vercel-postgres/session.d.cts +10 -14
  675. package/vercel-postgres/session.d.ts +10 -14
  676. package/vercel-postgres/session.js +8 -34
  677. package/vercel-postgres/session.js.map +1 -1
  678. package/version.cjs +1 -1
  679. package/version.d.cts +1 -1
  680. package/version.d.ts +1 -1
  681. package/version.js +1 -1
  682. package/xata-http/driver.cjs +5 -17
  683. package/xata-http/driver.cjs.map +1 -1
  684. package/xata-http/driver.d.cts +4 -5
  685. package/xata-http/driver.d.ts +4 -5
  686. package/xata-http/driver.js +5 -7
  687. package/xata-http/driver.js.map +1 -1
  688. package/xata-http/migrator.cjs.map +1 -1
  689. package/xata-http/migrator.d.cts +1 -2
  690. package/xata-http/migrator.d.ts +1 -2
  691. package/xata-http/migrator.js.map +1 -1
  692. package/xata-http/session.cjs +2 -30
  693. package/xata-http/session.cjs.map +1 -1
  694. package/xata-http/session.d.cts +8 -13
  695. package/xata-http/session.d.ts +8 -13
  696. package/xata-http/session.js +2 -30
  697. package/xata-http/session.js.map +1 -1
  698. package/_relations.cjs +0 -328
  699. package/_relations.cjs.map +0 -1
  700. package/_relations.d.cts +0 -215
  701. package/_relations.d.ts +0 -215
  702. package/_relations.js +0 -316
  703. package/_relations.js.map +0 -1
  704. package/mysql-core/query-builders/_query.cjs +0 -149
  705. package/mysql-core/query-builders/_query.cjs.map +0 -1
  706. package/mysql-core/query-builders/_query.d.cts +0 -44
  707. package/mysql-core/query-builders/_query.d.ts +0 -44
  708. package/mysql-core/query-builders/_query.js +0 -114
  709. package/mysql-core/query-builders/_query.js.map +0 -1
  710. package/pg-core/query-builders/_query.cjs +0 -155
  711. package/pg-core/query-builders/_query.cjs.map +0 -1
  712. package/pg-core/query-builders/_query.d.cts +0 -47
  713. package/pg-core/query-builders/_query.d.ts +0 -47
  714. package/pg-core/query-builders/_query.js +0 -120
  715. package/pg-core/query-builders/_query.js.map +0 -1
  716. package/sqlite-core/query-builders/_query.cjs +0 -187
  717. package/sqlite-core/query-builders/_query.cjs.map +0 -1
  718. package/sqlite-core/query-builders/_query.d.cts +0 -55
  719. package/sqlite-core/query-builders/_query.d.ts +0 -55
  720. package/sqlite-core/query-builders/_query.js +0 -151
  721. package/sqlite-core/query-builders/_query.js.map +0 -1
@@ -79,20 +79,24 @@ class SingleStoreDatabase {
79
79
  * const result = await db.with(sq).select({ name: sq.name }).from(sq);
80
80
  * ```
81
81
  */
82
- $with(alias) {
82
+ $with = (alias, selection) => {
83
83
  const self = this;
84
- return {
85
- as(qb) {
86
- if (typeof qb === "function") {
87
- qb = qb(new import_query_builders.QueryBuilder(self.dialect));
88
- }
89
- return new Proxy(
90
- new import_subquery.WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
91
- new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
92
- );
84
+ const as = (qb) => {
85
+ if (typeof qb === "function") {
86
+ qb = qb(new import_query_builders.QueryBuilder(self.dialect));
93
87
  }
88
+ return new Proxy(
89
+ new import_subquery.WithSubquery(
90
+ qb.getSQL(),
91
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
92
+ alias,
93
+ true
94
+ ),
95
+ new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
96
+ );
94
97
  };
95
- }
98
+ return { as };
99
+ };
96
100
  $count(source, filters) {
97
101
  return new import_count.SingleStoreCountBuilder({ source, filters, session: this.session });
98
102
  }
@@ -231,6 +235,7 @@ class SingleStoreDatabase {
231
235
  const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(Math.random() * replicas.length)]) => {
232
236
  const select = (...args) => getReplica(replicas).select(...args);
233
237
  const selectDistinct = (...args) => getReplica(replicas).selectDistinct(...args);
238
+ const $count = (...args) => getReplica(replicas).$count(...args);
234
239
  const $with = (...args) => getReplica(replicas).with(...args);
235
240
  const update = (...args) => primary.update(...args);
236
241
  const insert = (...args) => primary.insert(...args);
@@ -247,6 +252,7 @@ const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(
247
252
  $primary: primary,
248
253
  select,
249
254
  selectDistinct,
255
+ $count,
250
256
  with: $with,
251
257
  get query() {
252
258
  return getReplica(replicas).query;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport type * as V1 from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreDriverDatabase } from '~/singlestore/driver.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport { SingleStoreCountBuilder } from './query-builders/count.ts';\nimport {\n\tQueryBuilder,\n\tSingleStoreDeleteBase,\n\tSingleStoreInsertBuilder,\n\tSingleStoreSelectBuilder,\n\tSingleStoreUpdateBuilder,\n} from './query-builders/index.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStoreQueryResultHKT,\n\tSingleStoreQueryResultKind,\n\tSingleStoreSession,\n\tSingleStoreTransaction,\n\tSingleStoreTransactionConfig,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { SingleStoreTable } from './table.ts';\n\nexport class SingleStoreDatabase<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\t// We are waiting for SingleStore support for `json_array` function\n\t/**@inrernal */\n\tquery: unknown;\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: SingleStoreDialect,\n\t\t/** @internal */\n\t\treadonly session: SingleStoreSession<any, any, any, any>,\n\t\tschema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\t// this.queryNotSupported = true;\n\t\t// if (this._.schema) {\n\t\t// \tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t// \t\t(this.query as SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t// \t\t\tnew RelationalQueryBuilder(\n\t\t// \t\t\t\tschema!.fullSchema,\n\t\t// \t\t\t\tthis._.schema,\n\t\t// \t\t\t\tthis._.tableNamesMap,\n\t\t// \t\t\t\tschema!.fullSchema[tableName] as SingleStoreTable,\n\t\t// \t\t\t\tcolumns,\n\t\t// \t\t\t\tdialect,\n\t\t// \t\t\t\tsession,\n\t\t// \t\t\t);\n\t\t// \t}\n\t\t// }\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\tconst self = this;\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new SingleStoreCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<SingleStoreQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: SingleStoreTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SingleStoreWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tQ extends SingleStoreDriverDatabase,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SingleStoreWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,6BAAsC;AAEtC,iBAAsE;AACtE,sBAA6B;AAE7B,mBAAwC;AACxC,4BAMO;AAaA,MAAM,oBAKX;AAAA,EAaD,YAEU,SAEA,SACT,QACC;AAJQ;AAEA;AAGT,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AAAA,EAgBf;AAAA,EA9CA,QAAiB,wBAAU,IAAY;AAAA;AAAA;AAAA,EAUvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsEA,MAA6B,OAAe;AAC3C,UAAM,OAAO;AACb,WAAO;AAAA,MACN,GACC,IACgD;AAChD,YAAI,OAAO,OAAO,YAAY;AAC7B,eAAK,GAAG,IAAI,mCAAa,KAAK,OAAO,CAAC;AAAA,QACvC;AAEA,eAAO,IAAI;AAAA,UACV,IAAI,6BAAa,GAAG,OAAO,GAAG,GAAG,kBAAkB,GAAqB,OAAO,IAAI;AAAA,UACnF,IAAI,6C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,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,UAAwB,IAAI,SAAgB,QAAQ,QAAQ,GAAG,IAAI;AACzE,QAAM,cAAgC,IAAI,SAAqB,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/singlestore-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreDriverDatabase } from '~/singlestore/driver.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport { SingleStoreCountBuilder } from './query-builders/count.ts';\nimport {\n\tQueryBuilder,\n\tSingleStoreDeleteBase,\n\tSingleStoreInsertBuilder,\n\tSingleStoreSelectBuilder,\n\tSingleStoreUpdateBuilder,\n} from './query-builders/index.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStoreQueryResultHKT,\n\tSingleStoreQueryResultKind,\n\tSingleStoreSession,\n\tSingleStoreTransaction,\n\tSingleStoreTransactionConfig,\n} from './session.ts';\nimport type { WithBuilder } from './subquery.ts';\nimport type { SingleStoreTable } from './table.ts';\n\nexport class SingleStoreDatabase<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\t// We are waiting for SingleStore support for `json_array` function\n\t/**@inrernal */\n\tquery: unknown;\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: SingleStoreDialect,\n\t\t/** @internal */\n\t\treadonly session: SingleStoreSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\t// this.queryNotSupported = true;\n\t\t// if (this._.schema) {\n\t\t// \tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t// \t\t(this.query as SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t// \t\t\tnew RelationalQueryBuilder(\n\t\t// \t\t\t\tschema!.fullSchema,\n\t\t// \t\t\t\tthis._.schema,\n\t\t// \t\t\t\tthis._.tableNamesMap,\n\t\t// \t\t\t\tschema!.fullSchema[tableName] as SingleStoreTable,\n\t\t// \t\t\t\tcolumns,\n\t\t// \t\t\t\tdialect,\n\t\t// \t\t\t\tsession,\n\t\t// \t\t\t);\n\t\t// \t}\n\t\t// }\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with: WithBuilder = (alias: string, selection?: ColumnsSelection) => {\n\t\tconst self = this;\n\t\tconst as = (\n\t\t\tqb:\n\t\t\t\t| TypedQueryBuilder<ColumnsSelection | undefined>\n\t\t\t\t| SQL\n\t\t\t\t| ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection | undefined> | SQL),\n\t\t) => {\n\t\t\tif (typeof qb === 'function') {\n\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t}\n\n\t\t\treturn new Proxy(\n\t\t\t\tnew WithSubquery(\n\t\t\t\t\tqb.getSQL(),\n\t\t\t\t\tselection ?? ('getSelectedFields' in qb ? qb.getSelectedFields() ?? {} : {}) as SelectedFields,\n\t\t\t\t\talias,\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t);\n\t\t};\n\t\treturn { as };\n\t};\n\n\t$count(\n\t\tsource: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new SingleStoreCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<SingleStoreQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: SingleStoreTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SingleStoreWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tQ extends SingleStoreDriverDatabase,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SingleStoreWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $count: Q['$count'] = (...args: [any]) => getReplica(replicas).$count(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\t$count,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAG3B,6BAAsC;AAEtC,iBAAsE;AACtE,sBAA6B;AAE7B,mBAAwC;AACxC,4BAMO;AAaA,MAAM,oBAKX;AAAA,EAaD,YAEU,SAEA,SACT,QACC;AAJQ;AAEA;AAGT,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AAAA,EAgBf;AAAA,EA9CA,QAAiB,wBAAU,IAAY;AAAA;AAAA;AAAA,EAUvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AO,CAAC;AAAA,EACxF;AAAA,EAEA,YACC,aAIA,QACa;AACb,WAAO,KAAK,QAAQ,YAAY,aAAa,MAAM;AAAA,EACpD;AACD;AAIO,MAAM,eAAe,CAG3B,SACA,UACA,aAAmC,MAAM,SAAS,KAAK,MAAM,KAAK,OAAO,IAAI,SAAS,MAAM,CAAC,MAC7D;AAChC,QAAM,SAAsB,IAAI,SAAa,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AAChF,QAAM,iBAAsC,IAAI,SAAa,WAAW,QAAQ,EAAE,eAAe,GAAG,IAAI;AACxG,QAAM,SAAsB,IAAI,SAAgB,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AACnF,QAAM,QAAmB,IAAI,SAAa,WAAW,QAAQ,EAAE,KAAK,GAAG,IAAI;AAE3E,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,UAAwB,IAAI,SAAgB,QAAQ,QAAQ,GAAG,IAAI;AACzE,QAAM,cAAgC,IAAI,SAAqB,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
@@ -1,18 +1,17 @@
1
1
  import type { ResultSetHeader } from 'mysql2/promise';
2
- import type * as V1 from "../_relations.cjs";
3
2
  import { entityKind } from "../entity.cjs";
4
- import type { TypedQueryBuilder } from "../query-builders/query-builder.cjs";
3
+ import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
5
4
  import type { SingleStoreDriverDatabase } from "../singlestore/driver.cjs";
6
- import { type ColumnsSelection, type SQL, type SQLWrapper } from "../sql/sql.cjs";
5
+ import { type SQL, type SQLWrapper } from "../sql/sql.cjs";
7
6
  import { WithSubquery } from "../subquery.cjs";
8
7
  import type { SingleStoreDialect } from "./dialect.cjs";
9
8
  import { SingleStoreCountBuilder } from "./query-builders/count.cjs";
10
- import { QueryBuilder, SingleStoreDeleteBase, SingleStoreInsertBuilder, SingleStoreSelectBuilder, SingleStoreUpdateBuilder } from "./query-builders/index.cjs";
9
+ import { SingleStoreDeleteBase, SingleStoreInsertBuilder, SingleStoreSelectBuilder, SingleStoreUpdateBuilder } from "./query-builders/index.cjs";
11
10
  import type { SelectedFields } from "./query-builders/select.types.cjs";
12
11
  import type { PreparedQueryHKTBase, SingleStoreQueryResultHKT, SingleStoreQueryResultKind, SingleStoreSession, SingleStoreTransaction, SingleStoreTransactionConfig } from "./session.cjs";
13
- import type { WithSubqueryWithSelection } from "./subquery.cjs";
12
+ import type { WithBuilder } from "./subquery.cjs";
14
13
  import type { SingleStoreTable } from "./table.cjs";
15
- export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>> {
14
+ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
16
15
  static readonly [entityKind]: string;
17
16
  readonly _: {
18
17
  readonly schema: TSchema | undefined;
@@ -25,7 +24,7 @@ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryRe
25
24
  /** @internal */
26
25
  dialect: SingleStoreDialect,
27
26
  /** @internal */
28
- session: SingleStoreSession<any, any, any, any>, schema: V1.RelationalSchemaConfig<TSchema> | undefined);
27
+ session: SingleStoreSession<any, any, any, any>, schema: RelationalSchemaConfig<TSchema> | undefined);
29
28
  /**
30
29
  * Creates a subquery that defines a temporary named result set as a CTE.
31
30
  *
@@ -58,9 +57,7 @@ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryRe
58
57
  * const result = await db.with(sq).select({ name: sq.name }).from(sq);
59
58
  * ```
60
59
  */
61
- $with<TAlias extends string>(alias: TAlias): {
62
- as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
63
- };
60
+ $with: WithBuilder;
64
61
  $count(source: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |
65
62
  filters?: SQL<unknown>): SingleStoreCountBuilder<SingleStoreSession<any, any, any, any>>;
66
63
  /**
@@ -1,18 +1,17 @@
1
1
  import type { ResultSetHeader } from 'mysql2/promise';
2
- import type * as V1 from "../_relations.js";
3
2
  import { entityKind } from "../entity.js";
4
- import type { TypedQueryBuilder } from "../query-builders/query-builder.js";
3
+ import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
5
4
  import type { SingleStoreDriverDatabase } from "../singlestore/driver.js";
6
- import { type ColumnsSelection, type SQL, type SQLWrapper } from "../sql/sql.js";
5
+ import { type SQL, type SQLWrapper } from "../sql/sql.js";
7
6
  import { WithSubquery } from "../subquery.js";
8
7
  import type { SingleStoreDialect } from "./dialect.js";
9
8
  import { SingleStoreCountBuilder } from "./query-builders/count.js";
10
- import { QueryBuilder, SingleStoreDeleteBase, SingleStoreInsertBuilder, SingleStoreSelectBuilder, SingleStoreUpdateBuilder } from "./query-builders/index.js";
9
+ import { SingleStoreDeleteBase, SingleStoreInsertBuilder, SingleStoreSelectBuilder, SingleStoreUpdateBuilder } from "./query-builders/index.js";
11
10
  import type { SelectedFields } from "./query-builders/select.types.js";
12
11
  import type { PreparedQueryHKTBase, SingleStoreQueryResultHKT, SingleStoreQueryResultKind, SingleStoreSession, SingleStoreTransaction, SingleStoreTransactionConfig } from "./session.js";
13
- import type { WithSubqueryWithSelection } from "./subquery.js";
12
+ import type { WithBuilder } from "./subquery.js";
14
13
  import type { SingleStoreTable } from "./table.js";
15
- export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>> {
14
+ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
16
15
  static readonly [entityKind]: string;
17
16
  readonly _: {
18
17
  readonly schema: TSchema | undefined;
@@ -25,7 +24,7 @@ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryRe
25
24
  /** @internal */
26
25
  dialect: SingleStoreDialect,
27
26
  /** @internal */
28
- session: SingleStoreSession<any, any, any, any>, schema: V1.RelationalSchemaConfig<TSchema> | undefined);
27
+ session: SingleStoreSession<any, any, any, any>, schema: RelationalSchemaConfig<TSchema> | undefined);
29
28
  /**
30
29
  * Creates a subquery that defines a temporary named result set as a CTE.
31
30
  *
@@ -58,9 +57,7 @@ export declare class SingleStoreDatabase<TQueryResult extends SingleStoreQueryRe
58
57
  * const result = await db.with(sq).select({ name: sq.name }).from(sq);
59
58
  * ```
60
59
  */
61
- $with<TAlias extends string>(alias: TAlias): {
62
- as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
63
- };
60
+ $with: WithBuilder;
64
61
  $count(source: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |
65
62
  filters?: SQL<unknown>): SingleStoreCountBuilder<SingleStoreSession<any, any, any, any>>;
66
63
  /**
@@ -61,20 +61,24 @@ class SingleStoreDatabase {
61
61
  * const result = await db.with(sq).select({ name: sq.name }).from(sq);
62
62
  * ```
63
63
  */
64
- $with(alias) {
64
+ $with = (alias, selection) => {
65
65
  const self = this;
66
- return {
67
- as(qb) {
68
- if (typeof qb === "function") {
69
- qb = qb(new QueryBuilder(self.dialect));
70
- }
71
- return new Proxy(
72
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
73
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
74
- );
66
+ const as = (qb) => {
67
+ if (typeof qb === "function") {
68
+ qb = qb(new QueryBuilder(self.dialect));
75
69
  }
70
+ return new Proxy(
71
+ new WithSubquery(
72
+ qb.getSQL(),
73
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
74
+ alias,
75
+ true
76
+ ),
77
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
78
+ );
76
79
  };
77
- }
80
+ return { as };
81
+ };
78
82
  $count(source, filters) {
79
83
  return new SingleStoreCountBuilder({ source, filters, session: this.session });
80
84
  }
@@ -213,6 +217,7 @@ class SingleStoreDatabase {
213
217
  const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(Math.random() * replicas.length)]) => {
214
218
  const select = (...args) => getReplica(replicas).select(...args);
215
219
  const selectDistinct = (...args) => getReplica(replicas).selectDistinct(...args);
220
+ const $count = (...args) => getReplica(replicas).$count(...args);
216
221
  const $with = (...args) => getReplica(replicas).with(...args);
217
222
  const update = (...args) => primary.update(...args);
218
223
  const insert = (...args) => primary.insert(...args);
@@ -229,6 +234,7 @@ const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(
229
234
  $primary: primary,
230
235
  select,
231
236
  selectDistinct,
237
+ $count,
232
238
  with: $with,
233
239
  get query() {
234
240
  return getReplica(replicas).query;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport type * as V1 from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreDriverDatabase } from '~/singlestore/driver.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport { SingleStoreCountBuilder } from './query-builders/count.ts';\nimport {\n\tQueryBuilder,\n\tSingleStoreDeleteBase,\n\tSingleStoreInsertBuilder,\n\tSingleStoreSelectBuilder,\n\tSingleStoreUpdateBuilder,\n} from './query-builders/index.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStoreQueryResultHKT,\n\tSingleStoreQueryResultKind,\n\tSingleStoreSession,\n\tSingleStoreTransaction,\n\tSingleStoreTransactionConfig,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { SingleStoreTable } from './table.ts';\n\nexport class SingleStoreDatabase<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends V1.TablesRelationalConfig = V1.ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\t// We are waiting for SingleStore support for `json_array` function\n\t/**@inrernal */\n\tquery: unknown;\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: SingleStoreDialect,\n\t\t/** @internal */\n\t\treadonly session: SingleStoreSession<any, any, any, any>,\n\t\tschema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\t// this.queryNotSupported = true;\n\t\t// if (this._.schema) {\n\t\t// \tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t// \t\t(this.query as SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t// \t\t\tnew RelationalQueryBuilder(\n\t\t// \t\t\t\tschema!.fullSchema,\n\t\t// \t\t\t\tthis._.schema,\n\t\t// \t\t\t\tthis._.tableNamesMap,\n\t\t// \t\t\t\tschema!.fullSchema[tableName] as SingleStoreTable,\n\t\t// \t\t\t\tcolumns,\n\t\t// \t\t\t\tdialect,\n\t\t// \t\t\t\tsession,\n\t\t// \t\t\t);\n\t\t// \t}\n\t\t// }\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\tconst self = this;\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new SingleStoreCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<SingleStoreQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: SingleStoreTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SingleStoreWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tQ extends SingleStoreDriverDatabase,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SingleStoreWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AAEA,SAAS,kBAAkB;AAE3B,SAAS,6BAA6B;AAEtC,SAA0C,WAA4B;AACt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AAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/singlestore-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreDriverDatabase } from '~/singlestore/driver.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport { SingleStoreCountBuilder } from './query-builders/count.ts';\nimport {\n\tQueryBuilder,\n\tSingleStoreDeleteBase,\n\tSingleStoreInsertBuilder,\n\tSingleStoreSelectBuilder,\n\tSingleStoreUpdateBuilder,\n} from './query-builders/index.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStoreQueryResultHKT,\n\tSingleStoreQueryResultKind,\n\tSingleStoreSession,\n\tSingleStoreTransaction,\n\tSingleStoreTransactionConfig,\n} from './session.ts';\nimport type { WithBuilder } from './subquery.ts';\nimport type { SingleStoreTable } from './table.ts';\n\nexport class SingleStoreDatabase<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\t// We are waiting for SingleStore support for `json_array` function\n\t/**@inrernal */\n\tquery: unknown;\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: SingleStoreDialect,\n\t\t/** @internal */\n\t\treadonly session: SingleStoreSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\t// this.queryNotSupported = true;\n\t\t// if (this._.schema) {\n\t\t// \tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t// \t\t(this.query as SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t// \t\t\tnew RelationalQueryBuilder(\n\t\t// \t\t\t\tschema!.fullSchema,\n\t\t// \t\t\t\tthis._.schema,\n\t\t// \t\t\t\tthis._.tableNamesMap,\n\t\t// \t\t\t\tschema!.fullSchema[tableName] as SingleStoreTable,\n\t\t// \t\t\t\tcolumns,\n\t\t// \t\t\t\tdialect,\n\t\t// \t\t\t\tsession,\n\t\t// \t\t\t);\n\t\t// \t}\n\t\t// }\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with: WithBuilder = (alias: string, selection?: ColumnsSelection) => {\n\t\tconst self = this;\n\t\tconst as = (\n\t\t\tqb:\n\t\t\t\t| TypedQueryBuilder<ColumnsSelection | undefined>\n\t\t\t\t| SQL\n\t\t\t\t| ((qb: QueryBuilder) => TypedQueryBuilder<ColumnsSelection | undefined> | SQL),\n\t\t) => {\n\t\t\tif (typeof qb === 'function') {\n\t\t\t\tqb = qb(new QueryBuilder(self.dialect));\n\t\t\t}\n\n\t\t\treturn new Proxy(\n\t\t\t\tnew WithSubquery(\n\t\t\t\t\tqb.getSQL(),\n\t\t\t\t\tselection ?? ('getSelectedFields' in qb ? qb.getSelectedFields() ?? {} : {}) as SelectedFields,\n\t\t\t\t\talias,\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t);\n\t\t};\n\t\treturn { as };\n\t};\n\n\t$count(\n\t\tsource: SingleStoreTable | SQL | SQLWrapper, // SingleStoreViewBase |\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new SingleStoreCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends SingleStoreTable>(\n\t\t\ttable: TTable,\n\t\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new SingleStoreDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SingleStoreSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SingleStoreSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): SingleStoreSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new SingleStoreSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends SingleStoreTable>(\n\t\ttable: TTable,\n\t): SingleStoreDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new SingleStoreDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<SingleStoreQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: SingleStoreTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SingleStoreWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tQ extends SingleStoreDriverDatabase,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SingleStoreWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $count: Q['$count'] = (...args: [any]) => getReplica(replicas).$count(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\t$count,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AAEtC,SAA0C,WAA4B;AACtE,SAAS,oBAAoB;AAE7B,SAAS,+BAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAaA,MAAM,oBAKX;AAAA,EAaD,YAEU,SAEA,SACT,QACC;AAJQ;AAEA;AAGT,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AAAA,EAgBf;AAAA,EA9CA,QAAiB,UAAU,IAAY;AAAA;AAAA;AAAA,EAUvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsEA,QAAqB,CAAC,OAAe,cAAiC;AACrE,UAAM,OAAO;AACb,UAAM,KAAK,CACV,OAII;AACJ,UAAI,OAAO,OAAO,YAAY;AAC7B,aAAK,GAAG,IAAI,aAAa,KAAK,OAAO,CAAC;AAAA,MACvC;AAEA,aAAO,IAAI;AAAA,QACV,IAAI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AO,GAAG,IAAI;AAChF,QAAM,iBAAsC,IAAI,SAAa,WAAW,QAAQ,EAAE,eAAe,GAAG,IAAI;AACxG,QAAM,SAAsB,IAAI,SAAgB,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AACnF,QAAM,QAAmB,IAAI,SAAa,WAAW,QAAQ,EAAE,KAAK,GAAG,IAAI;AAE3E,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,UAAwB,IAAI,SAAgB,QAAQ,QAAQ,GAAG,IAAI;AACzE,QAAM,cAAgC,IAAI,SAAqB,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,27 +15,19 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var dialect_exports = {};
30
20
  __export(dialect_exports, {
31
21
  SingleStoreDialect: () => SingleStoreDialect
32
22
  });
33
23
  module.exports = __toCommonJS(dialect_exports);
34
- var V1 = __toESM(require("../_relations.cjs"), 1);
35
24
  var import_alias = require("../alias.cjs");
36
25
  var import_casing = require("../casing.cjs");
37
26
  var import_column = require("../column.cjs");
38
27
  var import_entity = require("../entity.cjs");
39
28
  var import_errors = require("../errors.cjs");
40
29
  var import_expressions = require("../expressions.cjs");
30
+ var import_relations = require("../relations.cjs");
41
31
  var import_sql = require("../sql/sql.cjs");
42
32
  var import_subquery = require("../subquery.cjs");
43
33
  var import_table = require("../table.cjs");
@@ -413,7 +403,7 @@ class SingleStoreDialect {
413
403
  Object.entries(tableConfig.columns).map(([key, value]) => [key, (0, import_alias.aliasedTableColumn)(value, tableAlias)])
414
404
  );
415
405
  if (config.where) {
416
- const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, V1.getOperators()) : config.where;
406
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0, import_relations.getOperators)()) : config.where;
417
407
  where = whereSql && (0, import_alias.mapColumnsInSQLToAlias)(whereSql, tableAlias);
418
408
  }
419
409
  const fieldsSelection = [];
@@ -465,7 +455,7 @@ class SingleStoreDialect {
465
455
  selection: []
466
456
  });
467
457
  }
468
- let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, V1.getOrderByOperators()) : config.orderBy ?? [];
458
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0, import_relations.getOrderByOperators)()) : config.orderBy ?? [];
469
459
  if (!Array.isArray(orderByOrig)) {
470
460
  orderByOrig = [orderByOrig];
471
461
  }
@@ -482,7 +472,7 @@ class SingleStoreDialect {
482
472
  queryConfig: selectedRelationConfigValue,
483
473
  relation
484
474
  } of selectedRelations) {
485
- const normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);
475
+ const normalizedRelation = (0, import_relations.normalizeRelation)(schema, tableNamesMap, relation);
486
476
  const relationTableName = (0, import_table.getTableUniqueName)(relation.referencedTable);
487
477
  const relationTableTsName = tableNamesMap[relationTableName];
488
478
  const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
@@ -500,7 +490,7 @@ class SingleStoreDialect {
500
490
  tableNamesMap,
501
491
  table: fullSchema[relationTableTsName],
502
492
  tableConfig: schema[relationTableTsName],
503
- queryConfig: (0, import_entity.is)(relation, V1.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
493
+ queryConfig: (0, import_entity.is)(relation, import_relations.One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
504
494
  tableAlias: relationTableAlias,
505
495
  joinOn: joinOn2,
506
496
  nestedQueryRelation: relation
@@ -535,7 +525,7 @@ class SingleStoreDialect {
535
525
  ),
536
526
  import_sql.sql`, `
537
527
  )})`;
538
- if ((0, import_entity.is)(nestedQueryRelation, V1.Many)) {
528
+ if ((0, import_entity.is)(nestedQueryRelation, import_relations.Many)) {
539
529
  field = import_sql.sql`json_agg(${field})`;
540
530
  }
541
531
  const nestedSelection = [{