drizzle-orm 0.40.0 → 1.0.0-beta.1-cacd055

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 (735) hide show
  1. package/_relations.cjs +328 -0
  2. package/_relations.cjs.map +1 -0
  3. package/_relations.d.cts +215 -0
  4. package/_relations.d.ts +215 -0
  5. package/_relations.js +316 -0
  6. package/_relations.js.map +1 -0
  7. package/alias.cjs.map +1 -1
  8. package/alias.d.cts +3 -3
  9. package/alias.d.ts +3 -3
  10. package/alias.js.map +1 -1
  11. package/aws-data-api/pg/driver.cjs +19 -5
  12. package/aws-data-api/pg/driver.cjs.map +1 -1
  13. package/aws-data-api/pg/driver.d.cts +9 -8
  14. package/aws-data-api/pg/driver.d.ts +9 -8
  15. package/aws-data-api/pg/driver.js +9 -8
  16. package/aws-data-api/pg/driver.js.map +1 -1
  17. package/aws-data-api/pg/migrator.cjs.map +1 -1
  18. package/aws-data-api/pg/migrator.d.cts +2 -1
  19. package/aws-data-api/pg/migrator.d.ts +2 -1
  20. package/aws-data-api/pg/migrator.js.map +1 -1
  21. package/aws-data-api/pg/session.cjs +67 -4
  22. package/aws-data-api/pg/session.cjs.map +1 -1
  23. package/aws-data-api/pg/session.d.cts +13 -8
  24. package/aws-data-api/pg/session.d.ts +13 -8
  25. package/aws-data-api/pg/session.js +67 -4
  26. package/aws-data-api/pg/session.js.map +1 -1
  27. package/better-sqlite3/driver.cjs +12 -5
  28. package/better-sqlite3/driver.cjs.map +1 -1
  29. package/better-sqlite3/driver.d.cts +7 -6
  30. package/better-sqlite3/driver.d.ts +7 -6
  31. package/better-sqlite3/driver.js +12 -8
  32. package/better-sqlite3/driver.js.map +1 -1
  33. package/better-sqlite3/migrator.cjs.map +1 -1
  34. package/better-sqlite3/migrator.d.cts +2 -1
  35. package/better-sqlite3/migrator.d.ts +2 -1
  36. package/better-sqlite3/migrator.js.map +1 -1
  37. package/better-sqlite3/session.cjs +49 -4
  38. package/better-sqlite3/session.cjs.map +1 -1
  39. package/better-sqlite3/session.d.cts +14 -8
  40. package/better-sqlite3/session.d.ts +14 -8
  41. package/better-sqlite3/session.js +49 -4
  42. package/better-sqlite3/session.js.map +1 -1
  43. package/bun-sql/driver.cjs +16 -5
  44. package/bun-sql/driver.cjs.map +1 -1
  45. package/bun-sql/driver.d.cts +7 -6
  46. package/bun-sql/driver.d.ts +7 -6
  47. package/bun-sql/driver.js +6 -8
  48. package/bun-sql/driver.js.map +1 -1
  49. package/bun-sql/migrator.cjs.map +1 -1
  50. package/bun-sql/migrator.d.cts +2 -1
  51. package/bun-sql/migrator.d.ts +2 -1
  52. package/bun-sql/migrator.js.map +1 -1
  53. package/bun-sql/session.cjs +50 -6
  54. package/bun-sql/session.cjs.map +1 -1
  55. package/bun-sql/session.d.cts +14 -9
  56. package/bun-sql/session.d.ts +14 -9
  57. package/bun-sql/session.js +50 -6
  58. package/bun-sql/session.js.map +1 -1
  59. package/bun-sqlite/driver.cjs +22 -5
  60. package/bun-sqlite/driver.cjs.map +1 -1
  61. package/bun-sqlite/driver.d.cts +7 -6
  62. package/bun-sqlite/driver.d.ts +7 -6
  63. package/bun-sqlite/driver.js +12 -8
  64. package/bun-sqlite/driver.js.map +1 -1
  65. package/bun-sqlite/migrator.cjs.map +1 -1
  66. package/bun-sqlite/migrator.d.cts +2 -1
  67. package/bun-sqlite/migrator.d.ts +2 -1
  68. package/bun-sqlite/migrator.js.map +1 -1
  69. package/bun-sqlite/session.cjs +49 -4
  70. package/bun-sqlite/session.cjs.map +1 -1
  71. package/bun-sqlite/session.d.cts +14 -8
  72. package/bun-sqlite/session.d.ts +14 -8
  73. package/bun-sqlite/session.js +49 -4
  74. package/bun-sqlite/session.js.map +1 -1
  75. package/casing.cjs +3 -0
  76. package/casing.cjs.map +1 -1
  77. package/casing.d.cts +1 -1
  78. package/casing.d.ts +1 -1
  79. package/casing.js +4 -1
  80. package/casing.js.map +1 -1
  81. package/d1/driver.cjs +22 -5
  82. package/d1/driver.cjs.map +1 -1
  83. package/d1/driver.d.cts +3 -2
  84. package/d1/driver.d.ts +3 -2
  85. package/d1/driver.js +12 -8
  86. package/d1/driver.js.map +1 -1
  87. package/d1/migrator.cjs.map +1 -1
  88. package/d1/migrator.d.cts +2 -1
  89. package/d1/migrator.d.ts +2 -1
  90. package/d1/migrator.js.map +1 -1
  91. package/d1/session.cjs +50 -8
  92. package/d1/session.cjs.map +1 -1
  93. package/d1/session.d.cts +15 -8
  94. package/d1/session.d.ts +15 -8
  95. package/d1/session.js +50 -8
  96. package/d1/session.js.map +1 -1
  97. package/durable-sqlite/driver.cjs +16 -5
  98. package/durable-sqlite/driver.cjs.map +1 -1
  99. package/durable-sqlite/driver.d.cts +3 -2
  100. package/durable-sqlite/driver.d.ts +3 -2
  101. package/durable-sqlite/driver.js +6 -8
  102. package/durable-sqlite/driver.js.map +1 -1
  103. package/durable-sqlite/migrator.cjs.map +1 -1
  104. package/durable-sqlite/migrator.d.cts +2 -1
  105. package/durable-sqlite/migrator.d.ts +2 -1
  106. package/durable-sqlite/migrator.js.map +1 -1
  107. package/durable-sqlite/session.cjs +46 -4
  108. package/durable-sqlite/session.cjs.map +1 -1
  109. package/durable-sqlite/session.d.cts +14 -8
  110. package/durable-sqlite/session.d.ts +14 -8
  111. package/durable-sqlite/session.js +46 -4
  112. package/durable-sqlite/session.js.map +1 -1
  113. package/expo-sqlite/driver.cjs +22 -5
  114. package/expo-sqlite/driver.cjs.map +1 -1
  115. package/expo-sqlite/driver.d.cts +3 -2
  116. package/expo-sqlite/driver.d.ts +3 -2
  117. package/expo-sqlite/driver.js +12 -8
  118. package/expo-sqlite/driver.js.map +1 -1
  119. package/expo-sqlite/migrator.cjs.map +1 -1
  120. package/expo-sqlite/migrator.d.cts +3 -2
  121. package/expo-sqlite/migrator.d.ts +3 -2
  122. package/expo-sqlite/migrator.js.map +1 -1
  123. package/expo-sqlite/query.cjs +13 -2
  124. package/expo-sqlite/query.cjs.map +1 -1
  125. package/expo-sqlite/query.d.cts +2 -1
  126. package/expo-sqlite/query.d.ts +2 -1
  127. package/expo-sqlite/query.js +3 -2
  128. package/expo-sqlite/query.js.map +1 -1
  129. package/expo-sqlite/session.cjs +47 -4
  130. package/expo-sqlite/session.cjs.map +1 -1
  131. package/expo-sqlite/session.d.cts +14 -8
  132. package/expo-sqlite/session.d.ts +14 -8
  133. package/expo-sqlite/session.js +47 -4
  134. package/expo-sqlite/session.js.map +1 -1
  135. package/gel/driver.cjs +17 -6
  136. package/gel/driver.cjs.map +1 -1
  137. package/gel/driver.d.cts +8 -7
  138. package/gel/driver.d.ts +8 -7
  139. package/gel/driver.js +7 -9
  140. package/gel/driver.js.map +1 -1
  141. package/gel/migrator.cjs.map +1 -1
  142. package/gel/migrator.d.cts +1 -1
  143. package/gel/migrator.d.ts +1 -1
  144. package/gel/migrator.js.map +1 -1
  145. package/gel/session.cjs +46 -4
  146. package/gel/session.cjs.map +1 -1
  147. package/gel/session.d.cts +13 -8
  148. package/gel/session.d.ts +13 -8
  149. package/gel/session.js +46 -4
  150. package/gel/session.js.map +1 -1
  151. package/gel-core/columns/timestamptz.cjs +5 -0
  152. package/gel-core/columns/timestamptz.cjs.map +1 -1
  153. package/gel-core/columns/timestamptz.d.cts +1 -0
  154. package/gel-core/columns/timestamptz.d.ts +1 -0
  155. package/gel-core/columns/timestamptz.js +5 -0
  156. package/gel-core/columns/timestamptz.js.map +1 -1
  157. package/gel-core/db.cjs +28 -4
  158. package/gel-core/db.cjs.map +1 -1
  159. package/gel-core/db.d.cts +16 -9
  160. package/gel-core/db.d.ts +16 -9
  161. package/gel-core/db.js +27 -3
  162. package/gel-core/db.js.map +1 -1
  163. package/gel-core/dialect.cjs +172 -488
  164. package/gel-core/dialect.cjs.map +1 -1
  165. package/gel-core/dialect.d.cts +26 -8
  166. package/gel-core/dialect.d.ts +26 -8
  167. package/gel-core/dialect.js +170 -495
  168. package/gel-core/dialect.js.map +1 -1
  169. package/gel-core/query-builders/_query.cjs +149 -0
  170. package/gel-core/query-builders/_query.cjs.map +1 -0
  171. package/gel-core/query-builders/_query.d.cts +46 -0
  172. package/gel-core/query-builders/_query.d.ts +46 -0
  173. package/gel-core/query-builders/_query.js +114 -0
  174. package/gel-core/query-builders/_query.js.map +1 -0
  175. package/gel-core/query-builders/query.cjs +27 -24
  176. package/gel-core/query-builders/query.cjs.map +1 -1
  177. package/gel-core/query-builders/query.d.cts +9 -8
  178. package/gel-core/query-builders/query.d.ts +9 -8
  179. package/gel-core/query-builders/query.js +26 -23
  180. package/gel-core/query-builders/query.js.map +1 -1
  181. package/gel-core/session.cjs +3 -2
  182. package/gel-core/session.cjs.map +1 -1
  183. package/gel-core/session.d.cts +9 -6
  184. package/gel-core/session.d.ts +9 -6
  185. package/gel-core/session.js +3 -2
  186. package/gel-core/session.js.map +1 -1
  187. package/libsql/driver-core.cjs +22 -5
  188. package/libsql/driver-core.cjs.map +1 -1
  189. package/libsql/driver-core.d.cts +2 -1
  190. package/libsql/driver-core.d.ts +2 -1
  191. package/libsql/driver-core.js +12 -8
  192. package/libsql/driver-core.js.map +1 -1
  193. package/libsql/driver.cjs.map +1 -1
  194. package/libsql/driver.d.cts +6 -5
  195. package/libsql/driver.d.ts +6 -5
  196. package/libsql/driver.js.map +1 -1
  197. package/libsql/http/index.cjs.map +1 -1
  198. package/libsql/http/index.d.cts +6 -5
  199. package/libsql/http/index.d.ts +6 -5
  200. package/libsql/http/index.js.map +1 -1
  201. package/libsql/migrator.cjs.map +1 -1
  202. package/libsql/migrator.d.cts +2 -1
  203. package/libsql/migrator.d.ts +2 -1
  204. package/libsql/migrator.js.map +1 -1
  205. package/libsql/node/index.cjs.map +1 -1
  206. package/libsql/node/index.d.cts +6 -5
  207. package/libsql/node/index.d.ts +6 -5
  208. package/libsql/node/index.js.map +1 -1
  209. package/libsql/session.cjs +56 -4
  210. package/libsql/session.cjs.map +1 -1
  211. package/libsql/session.d.cts +15 -9
  212. package/libsql/session.d.ts +15 -9
  213. package/libsql/session.js +56 -4
  214. package/libsql/session.js.map +1 -1
  215. package/libsql/sqlite3/index.cjs.map +1 -1
  216. package/libsql/sqlite3/index.d.cts +6 -5
  217. package/libsql/sqlite3/index.d.ts +6 -5
  218. package/libsql/sqlite3/index.js.map +1 -1
  219. package/libsql/wasm/index.cjs.map +1 -1
  220. package/libsql/wasm/index.d.cts +6 -5
  221. package/libsql/wasm/index.d.ts +6 -5
  222. package/libsql/wasm/index.js.map +1 -1
  223. package/libsql/web/index.cjs.map +1 -1
  224. package/libsql/web/index.d.cts +6 -5
  225. package/libsql/web/index.d.ts +6 -5
  226. package/libsql/web/index.js.map +1 -1
  227. package/libsql/ws/index.cjs.map +1 -1
  228. package/libsql/ws/index.d.cts +6 -5
  229. package/libsql/ws/index.d.ts +6 -5
  230. package/libsql/ws/index.js.map +1 -1
  231. package/mysql-core/columns/binary.cjs +11 -0
  232. package/mysql-core/columns/binary.cjs.map +1 -1
  233. package/mysql-core/columns/binary.d.cts +1 -0
  234. package/mysql-core/columns/binary.d.ts +1 -0
  235. package/mysql-core/columns/binary.js +11 -0
  236. package/mysql-core/columns/binary.js.map +1 -1
  237. package/mysql-core/columns/decimal.cjs +5 -0
  238. package/mysql-core/columns/decimal.cjs.map +1 -1
  239. package/mysql-core/columns/decimal.d.cts +1 -0
  240. package/mysql-core/columns/decimal.d.ts +1 -0
  241. package/mysql-core/columns/decimal.js +5 -0
  242. package/mysql-core/columns/decimal.js.map +1 -1
  243. package/mysql-core/columns/float.cjs +6 -0
  244. package/mysql-core/columns/float.cjs.map +1 -1
  245. package/mysql-core/columns/float.d.cts +1 -0
  246. package/mysql-core/columns/float.d.ts +1 -0
  247. package/mysql-core/columns/float.js +6 -0
  248. package/mysql-core/columns/float.js.map +1 -1
  249. package/mysql-core/columns/varbinary.cjs +11 -0
  250. package/mysql-core/columns/varbinary.cjs.map +1 -1
  251. package/mysql-core/columns/varbinary.d.cts +1 -0
  252. package/mysql-core/columns/varbinary.d.ts +1 -0
  253. package/mysql-core/columns/varbinary.js +11 -0
  254. package/mysql-core/columns/varbinary.js.map +1 -1
  255. package/mysql-core/columns/varchar.cjs.map +1 -1
  256. package/mysql-core/columns/varchar.d.cts +1 -1
  257. package/mysql-core/columns/varchar.d.ts +1 -1
  258. package/mysql-core/columns/varchar.js.map +1 -1
  259. package/mysql-core/db.cjs +30 -6
  260. package/mysql-core/db.cjs.map +1 -1
  261. package/mysql-core/db.d.cts +15 -8
  262. package/mysql-core/db.d.ts +15 -8
  263. package/mysql-core/db.js +29 -5
  264. package/mysql-core/db.js.map +1 -1
  265. package/mysql-core/dialect.cjs +208 -15
  266. package/mysql-core/dialect.cjs.map +1 -1
  267. package/mysql-core/dialect.d.cts +36 -13
  268. package/mysql-core/dialect.d.ts +36 -13
  269. package/mysql-core/dialect.js +206 -22
  270. package/mysql-core/dialect.js.map +1 -1
  271. package/mysql-core/query-builders/_query.cjs +149 -0
  272. package/mysql-core/query-builders/_query.cjs.map +1 -0
  273. package/mysql-core/query-builders/_query.d.cts +44 -0
  274. package/mysql-core/query-builders/_query.d.ts +44 -0
  275. package/mysql-core/query-builders/_query.js +114 -0
  276. package/mysql-core/query-builders/_query.js.map +1 -0
  277. package/mysql-core/query-builders/count.cjs.map +1 -1
  278. package/mysql-core/query-builders/count.d.cts +1 -1
  279. package/mysql-core/query-builders/count.d.ts +1 -1
  280. package/mysql-core/query-builders/count.js.map +1 -1
  281. package/mysql-core/query-builders/query.cjs +18 -31
  282. package/mysql-core/query-builders/query.cjs.map +1 -1
  283. package/mysql-core/query-builders/query.d.cts +8 -10
  284. package/mysql-core/query-builders/query.d.ts +8 -10
  285. package/mysql-core/query-builders/query.js +18 -31
  286. package/mysql-core/query-builders/query.js.map +1 -1
  287. package/mysql-core/session.cjs +3 -2
  288. package/mysql-core/session.cjs.map +1 -1
  289. package/mysql-core/session.d.cts +10 -7
  290. package/mysql-core/session.d.ts +10 -7
  291. package/mysql-core/session.js +3 -2
  292. package/mysql-core/session.js.map +1 -1
  293. package/mysql-proxy/driver.cjs +22 -5
  294. package/mysql-proxy/driver.cjs.map +1 -1
  295. package/mysql-proxy/driver.d.cts +3 -2
  296. package/mysql-proxy/driver.d.ts +3 -2
  297. package/mysql-proxy/driver.js +12 -8
  298. package/mysql-proxy/driver.js.map +1 -1
  299. package/mysql-proxy/migrator.cjs.map +1 -1
  300. package/mysql-proxy/migrator.d.cts +2 -1
  301. package/mysql-proxy/migrator.d.ts +2 -1
  302. package/mysql-proxy/migrator.js.map +1 -1
  303. package/mysql-proxy/session.cjs +27 -2
  304. package/mysql-proxy/session.cjs.map +1 -1
  305. package/mysql-proxy/session.d.cts +13 -8
  306. package/mysql-proxy/session.d.ts +13 -8
  307. package/mysql-proxy/session.js +27 -2
  308. package/mysql-proxy/session.js.map +1 -1
  309. package/mysql2/driver.cjs +24 -7
  310. package/mysql2/driver.cjs.map +1 -1
  311. package/mysql2/driver.d.cts +10 -9
  312. package/mysql2/driver.d.ts +10 -9
  313. package/mysql2/driver.js +14 -10
  314. package/mysql2/driver.js.map +1 -1
  315. package/mysql2/migrator.cjs.map +1 -1
  316. package/mysql2/migrator.d.cts +2 -1
  317. package/mysql2/migrator.d.ts +2 -1
  318. package/mysql2/migrator.js.map +1 -1
  319. package/mysql2/session.cjs +30 -2
  320. package/mysql2/session.cjs.map +1 -1
  321. package/mysql2/session.d.cts +13 -8
  322. package/mysql2/session.d.ts +13 -8
  323. package/mysql2/session.js +30 -2
  324. package/mysql2/session.js.map +1 -1
  325. package/neon-http/driver.cjs +21 -7
  326. package/neon-http/driver.cjs.map +1 -1
  327. package/neon-http/driver.d.cts +10 -9
  328. package/neon-http/driver.d.ts +10 -9
  329. package/neon-http/driver.js +11 -7
  330. package/neon-http/driver.js.map +1 -1
  331. package/neon-http/migrator.cjs.map +1 -1
  332. package/neon-http/migrator.d.cts +2 -1
  333. package/neon-http/migrator.d.ts +2 -1
  334. package/neon-http/migrator.js.map +1 -1
  335. package/neon-http/session.cjs +32 -2
  336. package/neon-http/session.cjs.map +1 -1
  337. package/neon-http/session.d.cts +13 -8
  338. package/neon-http/session.d.ts +13 -8
  339. package/neon-http/session.js +32 -2
  340. package/neon-http/session.js.map +1 -1
  341. package/neon-serverless/driver.cjs +18 -7
  342. package/neon-serverless/driver.cjs.map +1 -1
  343. package/neon-serverless/driver.d.cts +9 -8
  344. package/neon-serverless/driver.d.ts +9 -8
  345. package/neon-serverless/driver.js +8 -10
  346. package/neon-serverless/driver.js.map +1 -1
  347. package/neon-serverless/migrator.cjs.map +1 -1
  348. package/neon-serverless/migrator.d.cts +2 -1
  349. package/neon-serverless/migrator.d.ts +2 -1
  350. package/neon-serverless/migrator.js.map +1 -1
  351. package/neon-serverless/session.cjs +64 -5
  352. package/neon-serverless/session.cjs.map +1 -1
  353. package/neon-serverless/session.d.cts +13 -8
  354. package/neon-serverless/session.d.ts +13 -8
  355. package/neon-serverless/session.js +64 -5
  356. package/neon-serverless/session.js.map +1 -1
  357. package/node-postgres/driver.cjs +13 -7
  358. package/node-postgres/driver.cjs.map +1 -1
  359. package/node-postgres/driver.d.cts +9 -8
  360. package/node-postgres/driver.d.ts +9 -8
  361. package/node-postgres/driver.js +13 -10
  362. package/node-postgres/driver.js.map +1 -1
  363. package/node-postgres/migrator.cjs.map +1 -1
  364. package/node-postgres/migrator.d.cts +2 -1
  365. package/node-postgres/migrator.d.ts +2 -1
  366. package/node-postgres/migrator.js.map +1 -1
  367. package/node-postgres/session.cjs +69 -4
  368. package/node-postgres/session.cjs.map +1 -1
  369. package/node-postgres/session.d.cts +13 -8
  370. package/node-postgres/session.d.ts +13 -8
  371. package/node-postgres/session.js +69 -4
  372. package/node-postgres/session.js.map +1 -1
  373. package/op-sqlite/driver.cjs +22 -5
  374. package/op-sqlite/driver.cjs.map +1 -1
  375. package/op-sqlite/driver.d.cts +3 -2
  376. package/op-sqlite/driver.d.ts +3 -2
  377. package/op-sqlite/driver.js +12 -8
  378. package/op-sqlite/driver.js.map +1 -1
  379. package/op-sqlite/migrator.cjs.map +1 -1
  380. package/op-sqlite/migrator.d.cts +3 -2
  381. package/op-sqlite/migrator.d.ts +3 -2
  382. package/op-sqlite/migrator.js.map +1 -1
  383. package/op-sqlite/session.cjs +47 -4
  384. package/op-sqlite/session.cjs.map +1 -1
  385. package/op-sqlite/session.d.cts +14 -8
  386. package/op-sqlite/session.d.ts +14 -8
  387. package/op-sqlite/session.js +47 -4
  388. package/op-sqlite/session.js.map +1 -1
  389. package/package.json +111 -51
  390. package/pg-core/columns/numeric.cjs +5 -0
  391. package/pg-core/columns/numeric.cjs.map +1 -1
  392. package/pg-core/columns/numeric.d.cts +1 -0
  393. package/pg-core/columns/numeric.d.ts +1 -0
  394. package/pg-core/columns/numeric.js +5 -0
  395. package/pg-core/columns/numeric.js.map +1 -1
  396. package/pg-core/columns/postgis_extension/geometry.cjs +2 -0
  397. package/pg-core/columns/postgis_extension/geometry.cjs.map +1 -1
  398. package/pg-core/columns/postgis_extension/geometry.d.cts +1 -1
  399. package/pg-core/columns/postgis_extension/geometry.d.ts +1 -1
  400. package/pg-core/columns/postgis_extension/geometry.js +2 -0
  401. package/pg-core/columns/postgis_extension/geometry.js.map +1 -1
  402. package/pg-core/db.cjs +32 -5
  403. package/pg-core/db.cjs.map +1 -1
  404. package/pg-core/db.d.cts +16 -9
  405. package/pg-core/db.d.ts +16 -9
  406. package/pg-core/db.js +31 -4
  407. package/pg-core/db.js.map +1 -1
  408. package/pg-core/dialect.cjs +190 -488
  409. package/pg-core/dialect.cjs.map +1 -1
  410. package/pg-core/dialect.d.cts +27 -8
  411. package/pg-core/dialect.d.ts +27 -8
  412. package/pg-core/dialect.js +189 -495
  413. package/pg-core/dialect.js.map +1 -1
  414. package/pg-core/query-builders/_query.cjs +155 -0
  415. package/pg-core/query-builders/_query.cjs.map +1 -0
  416. package/pg-core/query-builders/_query.d.cts +47 -0
  417. package/pg-core/query-builders/_query.d.ts +47 -0
  418. package/pg-core/query-builders/_query.js +120 -0
  419. package/pg-core/query-builders/_query.js.map +1 -0
  420. package/pg-core/query-builders/count.cjs.map +1 -1
  421. package/pg-core/query-builders/count.d.cts +1 -1
  422. package/pg-core/query-builders/count.d.ts +1 -1
  423. package/pg-core/query-builders/count.js.map +1 -1
  424. package/pg-core/query-builders/query.cjs +15 -18
  425. package/pg-core/query-builders/query.cjs.map +1 -1
  426. package/pg-core/query-builders/query.d.cts +6 -6
  427. package/pg-core/query-builders/query.d.ts +6 -6
  428. package/pg-core/query-builders/query.js +15 -18
  429. package/pg-core/query-builders/query.js.map +1 -1
  430. package/pg-core/session.cjs +3 -2
  431. package/pg-core/session.cjs.map +1 -1
  432. package/pg-core/session.d.cts +9 -6
  433. package/pg-core/session.d.ts +9 -6
  434. package/pg-core/session.js +3 -2
  435. package/pg-core/session.js.map +1 -1
  436. package/pg-proxy/driver.cjs +21 -5
  437. package/pg-proxy/driver.cjs.map +1 -1
  438. package/pg-proxy/driver.d.cts +3 -2
  439. package/pg-proxy/driver.d.ts +3 -2
  440. package/pg-proxy/driver.js +11 -8
  441. package/pg-proxy/driver.js.map +1 -1
  442. package/pg-proxy/migrator.cjs.map +1 -1
  443. package/pg-proxy/migrator.d.cts +2 -1
  444. package/pg-proxy/migrator.d.ts +2 -1
  445. package/pg-proxy/migrator.js.map +1 -1
  446. package/pg-proxy/session.cjs +37 -2
  447. package/pg-proxy/session.cjs.map +1 -1
  448. package/pg-proxy/session.d.cts +13 -8
  449. package/pg-proxy/session.d.ts +13 -8
  450. package/pg-proxy/session.js +37 -2
  451. package/pg-proxy/session.js.map +1 -1
  452. package/pglite/driver.cjs +23 -7
  453. package/pglite/driver.cjs.map +1 -1
  454. package/pglite/driver.d.cts +9 -8
  455. package/pglite/driver.d.ts +9 -8
  456. package/pglite/driver.js +13 -10
  457. package/pglite/driver.js.map +1 -1
  458. package/pglite/migrator.cjs.map +1 -1
  459. package/pglite/migrator.d.cts +2 -1
  460. package/pglite/migrator.d.ts +2 -1
  461. package/pglite/migrator.js.map +1 -1
  462. package/pglite/session.cjs +48 -5
  463. package/pglite/session.cjs.map +1 -1
  464. package/pglite/session.d.cts +13 -8
  465. package/pglite/session.d.ts +13 -8
  466. package/pglite/session.js +48 -5
  467. package/pglite/session.js.map +1 -1
  468. package/planetscale-serverless/driver.cjs +22 -5
  469. package/planetscale-serverless/driver.cjs.map +1 -1
  470. package/planetscale-serverless/driver.d.cts +7 -6
  471. package/planetscale-serverless/driver.d.ts +7 -6
  472. package/planetscale-serverless/driver.js +12 -8
  473. package/planetscale-serverless/driver.js.map +1 -1
  474. package/planetscale-serverless/migrator.cjs.map +1 -1
  475. package/planetscale-serverless/migrator.d.cts +2 -1
  476. package/planetscale-serverless/migrator.d.ts +2 -1
  477. package/planetscale-serverless/migrator.js.map +1 -1
  478. package/planetscale-serverless/session.cjs +45 -5
  479. package/planetscale-serverless/session.cjs.map +1 -1
  480. package/planetscale-serverless/session.d.cts +14 -9
  481. package/planetscale-serverless/session.d.ts +14 -9
  482. package/planetscale-serverless/session.js +45 -5
  483. package/planetscale-serverless/session.js.map +1 -1
  484. package/postgres-js/driver.cjs +7 -6
  485. package/postgres-js/driver.cjs.map +1 -1
  486. package/postgres-js/driver.d.cts +7 -6
  487. package/postgres-js/driver.d.ts +7 -6
  488. package/postgres-js/driver.js +7 -9
  489. package/postgres-js/driver.js.map +1 -1
  490. package/postgres-js/migrator.cjs.map +1 -1
  491. package/postgres-js/migrator.d.cts +2 -1
  492. package/postgres-js/migrator.d.ts +2 -1
  493. package/postgres-js/migrator.js.map +1 -1
  494. package/postgres-js/session.cjs +51 -6
  495. package/postgres-js/session.cjs.map +1 -1
  496. package/postgres-js/session.d.cts +15 -9
  497. package/postgres-js/session.d.ts +15 -9
  498. package/postgres-js/session.js +51 -6
  499. package/postgres-js/session.js.map +1 -1
  500. package/prisma/mysql/driver.cjs +1 -1
  501. package/prisma/mysql/driver.cjs.map +1 -1
  502. package/prisma/mysql/driver.js +1 -1
  503. package/prisma/mysql/driver.js.map +1 -1
  504. package/prisma/mysql/session.cjs +3 -0
  505. package/prisma/mysql/session.cjs.map +1 -1
  506. package/prisma/mysql/session.d.cts +3 -1
  507. package/prisma/mysql/session.d.ts +3 -1
  508. package/prisma/mysql/session.js +3 -0
  509. package/prisma/mysql/session.js.map +1 -1
  510. package/prisma/pg/driver.cjs +1 -1
  511. package/prisma/pg/driver.cjs.map +1 -1
  512. package/prisma/pg/driver.js +1 -1
  513. package/prisma/pg/driver.js.map +1 -1
  514. package/prisma/pg/session.cjs +3 -0
  515. package/prisma/pg/session.cjs.map +1 -1
  516. package/prisma/pg/session.d.cts +3 -1
  517. package/prisma/pg/session.d.ts +3 -1
  518. package/prisma/pg/session.js +3 -0
  519. package/prisma/pg/session.js.map +1 -1
  520. package/prisma/sqlite/driver.cjs +1 -1
  521. package/prisma/sqlite/driver.cjs.map +1 -1
  522. package/prisma/sqlite/driver.js +1 -1
  523. package/prisma/sqlite/driver.js.map +1 -1
  524. package/prisma/sqlite/session.cjs +3 -0
  525. package/prisma/sqlite/session.cjs.map +1 -1
  526. package/prisma/sqlite/session.d.cts +4 -2
  527. package/prisma/sqlite/session.d.ts +4 -2
  528. package/prisma/sqlite/session.js +3 -0
  529. package/prisma/sqlite/session.js.map +1 -1
  530. package/relations.cjs +657 -245
  531. package/relations.cjs.map +1 -1
  532. package/relations.d.cts +339 -140
  533. package/relations.d.ts +339 -140
  534. package/relations.js +643 -240
  535. package/relations.js.map +1 -1
  536. package/singlestore/driver.cjs +1 -1
  537. package/singlestore/driver.cjs.map +1 -1
  538. package/singlestore/driver.d.cts +1 -1
  539. package/singlestore/driver.d.ts +1 -1
  540. package/singlestore/driver.js +3 -3
  541. package/singlestore/driver.js.map +1 -1
  542. package/singlestore/session.cjs.map +1 -1
  543. package/singlestore/session.d.cts +4 -4
  544. package/singlestore/session.d.ts +4 -4
  545. package/singlestore/session.js.map +1 -1
  546. package/singlestore-core/db.cjs.map +1 -1
  547. package/singlestore-core/db.d.cts +3 -3
  548. package/singlestore-core/db.d.ts +3 -3
  549. package/singlestore-core/db.js.map +1 -1
  550. package/singlestore-core/dialect.cjs +16 -6
  551. package/singlestore-core/dialect.cjs.map +1 -1
  552. package/singlestore-core/dialect.d.cts +6 -6
  553. package/singlestore-core/dialect.d.ts +6 -6
  554. package/singlestore-core/dialect.js +6 -12
  555. package/singlestore-core/dialect.js.map +1 -1
  556. package/singlestore-core/query-builders/query.cjs +12 -2
  557. package/singlestore-core/query-builders/query.cjs.map +1 -1
  558. package/singlestore-core/query-builders/query.d.cts +6 -6
  559. package/singlestore-core/query-builders/query.d.ts +6 -6
  560. package/singlestore-core/query-builders/query.js +2 -4
  561. package/singlestore-core/query-builders/query.js.map +1 -1
  562. package/singlestore-core/session.cjs.map +1 -1
  563. package/singlestore-core/session.d.cts +5 -5
  564. package/singlestore-core/session.d.ts +5 -5
  565. package/singlestore-core/session.js.map +1 -1
  566. package/singlestore-proxy/driver.cjs +1 -1
  567. package/singlestore-proxy/driver.cjs.map +1 -1
  568. package/singlestore-proxy/driver.js +3 -3
  569. package/singlestore-proxy/driver.js.map +1 -1
  570. package/singlestore-proxy/session.cjs.map +1 -1
  571. package/singlestore-proxy/session.d.cts +4 -4
  572. package/singlestore-proxy/session.d.ts +4 -4
  573. package/singlestore-proxy/session.js.map +1 -1
  574. package/sql/expressions/conditions.cjs.map +1 -1
  575. package/sql/expressions/conditions.d.cts +4 -4
  576. package/sql/expressions/conditions.d.ts +4 -4
  577. package/sql/expressions/conditions.js.map +1 -1
  578. package/sql/sql.cjs +21 -0
  579. package/sql/sql.cjs.map +1 -1
  580. package/sql/sql.d.cts +8 -8
  581. package/sql/sql.d.ts +8 -8
  582. package/sql/sql.js +22 -1
  583. package/sql/sql.js.map +1 -1
  584. package/sql-js/driver.cjs +16 -5
  585. package/sql-js/driver.cjs.map +1 -1
  586. package/sql-js/driver.d.cts +3 -2
  587. package/sql-js/driver.d.ts +3 -2
  588. package/sql-js/driver.js +6 -8
  589. package/sql-js/driver.js.map +1 -1
  590. package/sql-js/migrator.cjs.map +1 -1
  591. package/sql-js/migrator.d.cts +2 -1
  592. package/sql-js/migrator.d.ts +2 -1
  593. package/sql-js/migrator.js.map +1 -1
  594. package/sql-js/session.cjs +71 -36
  595. package/sql-js/session.cjs.map +1 -1
  596. package/sql-js/session.d.cts +16 -13
  597. package/sql-js/session.d.ts +16 -13
  598. package/sql-js/session.js +71 -36
  599. package/sql-js/session.js.map +1 -1
  600. package/sqlite-core/columns/blob.cjs +12 -0
  601. package/sqlite-core/columns/blob.cjs.map +1 -1
  602. package/sqlite-core/columns/blob.d.cts +2 -1
  603. package/sqlite-core/columns/blob.d.ts +2 -1
  604. package/sqlite-core/columns/blob.js +12 -0
  605. package/sqlite-core/columns/blob.js.map +1 -1
  606. package/sqlite-core/db.cjs +39 -12
  607. package/sqlite-core/db.cjs.map +1 -1
  608. package/sqlite-core/db.d.cts +16 -8
  609. package/sqlite-core/db.d.ts +16 -8
  610. package/sqlite-core/db.js +38 -11
  611. package/sqlite-core/db.js.map +1 -1
  612. package/sqlite-core/dialect.cjs +193 -7
  613. package/sqlite-core/dialect.cjs.map +1 -1
  614. package/sqlite-core/dialect.d.cts +31 -9
  615. package/sqlite-core/dialect.d.ts +31 -9
  616. package/sqlite-core/dialect.js +191 -14
  617. package/sqlite-core/dialect.js.map +1 -1
  618. package/sqlite-core/query-builders/_query.cjs +187 -0
  619. package/sqlite-core/query-builders/_query.cjs.map +1 -0
  620. package/sqlite-core/query-builders/_query.d.cts +55 -0
  621. package/sqlite-core/query-builders/_query.d.ts +55 -0
  622. package/sqlite-core/query-builders/_query.js +151 -0
  623. package/sqlite-core/query-builders/_query.js.map +1 -0
  624. package/sqlite-core/query-builders/count.cjs.map +1 -1
  625. package/sqlite-core/query-builders/count.d.cts +1 -1
  626. package/sqlite-core/query-builders/count.d.ts +1 -1
  627. package/sqlite-core/query-builders/count.js.map +1 -1
  628. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  629. package/sqlite-core/query-builders/delete.d.cts +1 -1
  630. package/sqlite-core/query-builders/delete.d.ts +1 -1
  631. package/sqlite-core/query-builders/delete.js.map +1 -1
  632. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  633. package/sqlite-core/query-builders/insert.d.cts +3 -3
  634. package/sqlite-core/query-builders/insert.d.ts +3 -3
  635. package/sqlite-core/query-builders/insert.js.map +1 -1
  636. package/sqlite-core/query-builders/query.cjs +56 -35
  637. package/sqlite-core/query-builders/query.cjs.map +1 -1
  638. package/sqlite-core/query-builders/query.d.cts +18 -17
  639. package/sqlite-core/query-builders/query.d.ts +18 -17
  640. package/sqlite-core/query-builders/query.js +56 -35
  641. package/sqlite-core/query-builders/query.js.map +1 -1
  642. package/sqlite-core/query-builders/select.cjs.map +1 -1
  643. package/sqlite-core/query-builders/select.d.cts +3 -3
  644. package/sqlite-core/query-builders/select.d.ts +3 -3
  645. package/sqlite-core/query-builders/select.js.map +1 -1
  646. package/sqlite-core/query-builders/update.cjs.map +1 -1
  647. package/sqlite-core/query-builders/update.d.cts +3 -3
  648. package/sqlite-core/query-builders/update.d.ts +3 -3
  649. package/sqlite-core/query-builders/update.js.map +1 -1
  650. package/sqlite-core/session.cjs +6 -2
  651. package/sqlite-core/session.cjs.map +1 -1
  652. package/sqlite-core/session.d.cts +15 -7
  653. package/sqlite-core/session.d.ts +15 -7
  654. package/sqlite-core/session.js +6 -2
  655. package/sqlite-core/session.js.map +1 -1
  656. package/sqlite-proxy/driver.cjs +23 -5
  657. package/sqlite-proxy/driver.cjs.map +1 -1
  658. package/sqlite-proxy/driver.d.cts +4 -3
  659. package/sqlite-proxy/driver.d.ts +4 -3
  660. package/sqlite-proxy/driver.js +13 -5
  661. package/sqlite-proxy/driver.js.map +1 -1
  662. package/sqlite-proxy/migrator.cjs.map +1 -1
  663. package/sqlite-proxy/migrator.d.cts +2 -1
  664. package/sqlite-proxy/migrator.d.ts +2 -1
  665. package/sqlite-proxy/migrator.js.map +1 -1
  666. package/sqlite-proxy/session.cjs +50 -6
  667. package/sqlite-proxy/session.cjs.map +1 -1
  668. package/sqlite-proxy/session.d.cts +14 -8
  669. package/sqlite-proxy/session.d.ts +14 -8
  670. package/sqlite-proxy/session.js +50 -6
  671. package/sqlite-proxy/session.js.map +1 -1
  672. package/table.cjs.map +1 -1
  673. package/table.d.cts +2 -2
  674. package/table.d.ts +2 -2
  675. package/table.js.map +1 -1
  676. package/tidb-serverless/driver.cjs +22 -5
  677. package/tidb-serverless/driver.cjs.map +1 -1
  678. package/tidb-serverless/driver.d.cts +7 -6
  679. package/tidb-serverless/driver.d.ts +7 -6
  680. package/tidb-serverless/driver.js +12 -8
  681. package/tidb-serverless/driver.js.map +1 -1
  682. package/tidb-serverless/migrator.cjs.map +1 -1
  683. package/tidb-serverless/migrator.d.cts +2 -1
  684. package/tidb-serverless/migrator.d.ts +2 -1
  685. package/tidb-serverless/migrator.js.map +1 -1
  686. package/tidb-serverless/session.cjs +62 -5
  687. package/tidb-serverless/session.cjs.map +1 -1
  688. package/tidb-serverless/session.d.cts +14 -9
  689. package/tidb-serverless/session.d.ts +14 -9
  690. package/tidb-serverless/session.js +62 -5
  691. package/tidb-serverless/session.js.map +1 -1
  692. package/utils.cjs +2 -2
  693. package/utils.cjs.map +1 -1
  694. package/utils.d.cts +3 -1
  695. package/utils.d.ts +3 -1
  696. package/utils.js +2 -2
  697. package/utils.js.map +1 -1
  698. package/vercel-postgres/driver.cjs +23 -7
  699. package/vercel-postgres/driver.cjs.map +1 -1
  700. package/vercel-postgres/driver.d.cts +9 -8
  701. package/vercel-postgres/driver.d.ts +9 -8
  702. package/vercel-postgres/driver.js +13 -10
  703. package/vercel-postgres/driver.js.map +1 -1
  704. package/vercel-postgres/migrator.cjs.map +1 -1
  705. package/vercel-postgres/migrator.d.cts +2 -1
  706. package/vercel-postgres/migrator.d.ts +2 -1
  707. package/vercel-postgres/migrator.js.map +1 -1
  708. package/vercel-postgres/session.cjs +58 -4
  709. package/vercel-postgres/session.cjs.map +1 -1
  710. package/vercel-postgres/session.d.cts +13 -8
  711. package/vercel-postgres/session.d.ts +13 -8
  712. package/vercel-postgres/session.js +58 -4
  713. package/vercel-postgres/session.js.map +1 -1
  714. package/version.cjs +2 -2
  715. package/version.cjs.map +1 -1
  716. package/version.d.cts +2 -2
  717. package/version.d.ts +2 -2
  718. package/version.js +2 -2
  719. package/version.js.map +1 -1
  720. package/xata-http/driver.cjs +17 -5
  721. package/xata-http/driver.cjs.map +1 -1
  722. package/xata-http/driver.d.cts +5 -4
  723. package/xata-http/driver.d.ts +5 -4
  724. package/xata-http/driver.js +7 -5
  725. package/xata-http/driver.js.map +1 -1
  726. package/xata-http/migrator.cjs.map +1 -1
  727. package/xata-http/migrator.d.cts +2 -1
  728. package/xata-http/migrator.d.ts +2 -1
  729. package/xata-http/migrator.js.map +1 -1
  730. package/xata-http/session.cjs +30 -2
  731. package/xata-http/session.cjs.map +1 -1
  732. package/xata-http/session.d.cts +13 -8
  733. package/xata-http/session.d.ts +13 -8
  734. package/xata-http/session.js +30 -2
  735. package/xata-http/session.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { Placeholder, Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields, type ValueOrArray } from '~/utils.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\tlimit?: number | Placeholder;\n\torderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n\twithList?: Subquery[];\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, withList };\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t *\n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\torderBy(\n\t\tbuilder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>,\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>]\n\t\t\t| (SQLiteColumn | SQL | SQL.Aliased)[]\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.table[Table.Symbol.Columns],\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as any,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SQLiteColumn | SQL | SQL.Aliased)[];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\tlimit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'> {\n\t\tthis.config.limit = limit;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}\n\t *\n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t *\n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\tprepare(): SQLiteDeletePrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this._prepare().execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAE7B,SAAS,6BAA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,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAS,iBAAiB,MAAiC;AAC1D,WAAO,KAAK,QAAQ,iBAAiB,wBAAwB,cAAc;AAAA,MAC1E,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UAAqC;AACpC,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,QAAQ,mBAAiF;AACvG,WAAO,KAAK,SAAS,EAAE,QAAQ,iBAAiB;AAAA,EACjD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { Placeholder, Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields, type ValueOrArray } from '~/utils.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\tlimit?: number | Placeholder;\n\torderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n\twithList?: Subquery[];\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, withList };\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t *\n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\torderBy(\n\t\tbuilder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>,\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>]\n\t\t\t| (SQLiteColumn | SQL | SQL.Aliased)[]\n\t): SQLiteDeleteWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.table[Table.Symbol.Columns],\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as any,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SQLiteColumn | SQL | SQL.Aliased)[];\n\t\t\tthis.config.orderBy = orderByArray;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\tlimit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'> {\n\t\tthis.config.limit = limit;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}\n\t *\n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t *\n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\tprepare(): SQLiteDeletePrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this._prepare().execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAE7B,SAAS,6BAA6B;AAItC,SAAS,mBAAmB;AAE5B,SAAS,aAAa;AACtB,SAAgC,2BAA8C;AAuHvE,MAAM,yBASH,aAEV;AAAA,EAMC,YACS,OACA,SACA,SACR,UACC;AACD,UAAM;AALE;AACA;AACA;AAIR,SAAK,SAAS,EAAE,OAAO,SAAS;AAAA,EACjC;AAAA,EAbA,QAA0B,UAAU,IAAY;AAAA;AAAA,EAGhD;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,EAyCA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAMA,WACI,SAG8C;AACjD,QAAI,OAAO,QAAQ,CAAC,MAAM,YAAY;AACrC,YAAM,UAAU,QAAQ,CAAC;AAAA,QACxB,IAAI;AAAA,UACH,KAAK,OAAO,MAAM,MAAM,OAAO,OAAO;AAAA,UACtC,IAAI,sBAAsB,EAAE,oBAAoB,SAAS,aAAa,MAAM,CAAC;AAAA,QAC9E;AAAA,MACD;AAEA,YAAM,eAAe,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAChE,WAAK,OAAO,UAAU;AAAA,IACvB,OAAO;AACN,YAAM,eAAe;AACrB,WAAK,OAAO,UAAU;AAAA,IACvB;AACA,WAAO;AAAA,EACR;AAAA,EAEA,M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../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAG/B,2BAA6B;AAG7B,iBAAgC;AAIhC,mBAA4B;AAE5B,IAAAA,gBAA+B;AAC/B,mBAAsG;AAEtG,2BAA6B;AAuBtB,MAAM,oBAIX;AAAA,EAGD,YACW,OACA,SACA,SACF,UACP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D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":["import_table"]}
1
+ {"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B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AAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":["import_table"]}
@@ -31,11 +31,11 @@ export type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQu
31
31
  }>;
32
32
  export declare class SQLiteInsertBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
33
33
  protected table: TTable;
34
- protected session: SQLiteSession<any, any, any, any>;
34
+ protected session: SQLiteSession<any, any, any, any, any, any>;
35
35
  protected dialect: SQLiteDialect;
36
36
  private withList?;
37
37
  static readonly [entityKind]: string;
38
- constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
38
+ constructor(table: TTable, session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
39
39
  values(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
40
40
  values(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;
41
41
  select(selectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
@@ -82,7 +82,7 @@ export declare class SQLiteInsertBase<TTable extends SQLiteTable, TResultType ex
82
82
  private session;
83
83
  private dialect;
84
84
  static readonly [entityKind]: string;
85
- constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
85
+ constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
86
86
  /**
87
87
  * Adds a `returning` clause to the query.
88
88
  *
@@ -31,11 +31,11 @@ export type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQu
31
31
  }>;
32
32
  export declare class SQLiteInsertBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
33
33
  protected table: TTable;
34
- protected session: SQLiteSession<any, any, any, any>;
34
+ protected session: SQLiteSession<any, any, any, any, any, any>;
35
35
  protected dialect: SQLiteDialect;
36
36
  private withList?;
37
37
  static readonly [entityKind]: string;
38
- constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
38
+ constructor(table: TTable, session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
39
39
  values(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
40
40
  values(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;
41
41
  select(selectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
@@ -82,7 +82,7 @@ export declare class SQLiteInsertBase<TTable extends SQLiteTable, TResultType ex
82
82
  private session;
83
83
  private dialect;
84
84
  static readonly [entityKind]: string;
85
- constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
85
+ constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
86
86
  /**
87
87
  * Adds a `returning` clause to the query.
88
88
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAG/B,SAAS,oBAAoB;AAG7B,SAAS,OAAO,KAAK,WAAW;AAIhC,SAAS,mBAAmB;AAE5B,SAAS,SAAS,aAAa;AAC/B,SAAgC,cAAc,cAAc,2BAA0C;AAEtG,SAAS,oBAAoB;AAuBtB,MAAM,oBAIX;AAAA,EAGD,YACW,OACA,SACA,SACF,UACP;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,UAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACp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","names":[]}
1
+ {"version":3,"sources":["../../../src/sqlite-core/query-builders/insert.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Placeholder, Query, SQLWrapper } from '~/sql/sql.ts';\nimport { Param, SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { IndexColumn } from '~/sqlite-core/indexes.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport { Columns, Table } from '~/table.ts';\nimport { type DrizzleTypeError, haveSameKeys, mapUpdateSet, orderSelectedFields, type Simplify } from '~/utils.ts';\nimport type { AnySQLiteColumn, SQLiteColumn } from '../columns/common.ts';\nimport { QueryBuilder } from './query-builder.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteUpdateSetSource } from './update.ts';\n\nexport interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {\n\ttable: TTable;\n\tvalues: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;\n\twithList?: Subquery[];\n\tonConflict?: SQL[];\n\treturning?: SelectedFieldsOrdered;\n\tselect?: boolean;\n}\n\nexport type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<\n\t{\n\t\t[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;\n\t}\n>;\n\nexport type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<\n\t{ [K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K] }\n>;\n\nexport class SQLiteInsertBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteInsertBuilder';\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprivate withList?: Subquery[],\n\t) {}\n\n\tvalues(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tvalues(\n\t\tvalues: SQLiteInsertValue<TTable> | SQLiteInsertValue<TTable>[],\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tvalues = Array.isArray(values) ? values : [values];\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('values() must be called with at least one value');\n\t\t}\n\t\tconst mappedValues = values.map((entry) => {\n\t\t\tconst result: Record<string, Param | SQL> = {};\n\t\t\tconst cols = this.table[Table.Symbol.Columns];\n\t\t\tfor (const colKey of Object.keys(entry)) {\n\t\t\t\tconst colValue = entry[colKey as keyof typeof entry];\n\t\t\t\tresult[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\n\t\t// if (mappedValues.length > 1 && mappedValues.some((t) => Object.keys(t).length === 0)) {\n\t\t// \tthrow new Error(\n\t\t// \t\t`One of the values you want to insert is empty. In SQLite you can insert only one empty object per statement. For this case Drizzle with use \"INSERT INTO ... DEFAULT VALUES\" syntax`,\n\t\t// \t);\n\t\t// }\n\n\t\treturn new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);\n\t}\n\n\tselect(\n\t\tselectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>,\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| SQLiteInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable> | SQL),\n\t): SQLiteInsertBase<TTable, TResultType, TRunResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tSQLiteInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['resultType'],\n\t\t\t\tT['_']['runResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>;\n\nexport type SQLiteInsertReturning<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertReturningAll<\n\tT extends AnySQLiteInsert,\n\tTDynamic extends boolean,\n> = SQLiteInsertWithout<\n\tSQLiteInsertBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {\n\ttarget: IndexColumn | IndexColumn[];\n\t/** @deprecated - use either `targetWhere` or `setWhere` */\n\twhere?: SQL;\n\t// TODO: add tests for targetWhere and setWhere\n\ttargetWhere?: SQL;\n\tsetWhere?: SQL;\n\tset: SQLiteUpdateSetSource<T['_']['table']>;\n};\n\nexport type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteInsertExecute<T>;\n\t}\n>;\n\nexport type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;\n\nexport type SQLiteInsert<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = any,\n> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tSQLWrapper,\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>\n{\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteInsertBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteInsert';\n\n\t/** @internal */\n\tconfig: SQLiteInsertConfig<TTable>;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tvalues: SQLiteInsertConfig['values'],\n\t\tprivate session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t\twithList?: Subquery[],\n\t\tselect?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table, values: values as any, withList, select };\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and return all fields\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t *\n\t * // Insert one row and return only the id\n\t * const insertedCarId: { id: number }[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning({ id: cars.id });\n\t * ```\n\t */\n\treturning(): SQLiteInsertReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteInsertWithout<AnySQLiteInsert, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `on conflict do nothing` clause to the query.\n\t *\n\t * Calling this method simply avoids inserting a row as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}\n\t *\n\t * @param config The `target` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Insert one row and cancel the insert if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing();\n\t *\n\t * // Explicitly specify conflict target\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoNothing({ target: cars.id });\n\t * ```\n\t */\n\tonConflictDoNothing(config: { target?: IndexColumn | IndexColumn[]; where?: SQL } = {}): this {\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tif (config.target === undefined) {\n\t\t\tthis.config.onConflict.push(sql` on conflict do nothing`);\n\t\t} else {\n\t\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\t\tconst whereSql = config.where ? sql` where ${config.where}` : sql``;\n\t\t\tthis.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an `on conflict do update` clause to the query.\n\t *\n\t * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}\n\t *\n\t * @param config The `target`, `set` and `where` clauses.\n\t *\n\t * @example\n\t * ```ts\n\t * // Update the row if there's a conflict\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'Porsche' }\n\t * });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t * .values({ id: 1, brand: 'BMW' })\n\t * .onConflictDoUpdate({\n\t * target: cars.id,\n\t * set: { brand: 'newBMW' },\n\t * where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t * });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildInsertQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteInsertPrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t\ttrue,\n\t\t) as SQLiteInsertPrepare<this>;\n\t}\n\n\tprepare(): SQLiteInsertPrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteInsertExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteInsertExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteInsertDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAG/B,SAAS,oBAAoB;AAG7B,SAAS,OAAO,KAAK,WAAW;AAIhC,SAAS,mBAAmB;AAE5B,SAAS,SAAS,aAAa;AAC/B,SAAgC,cAAc,cAAc,2BAA0C;AAEtG,SAAS,oBAAoB;AAuBtB,MA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A,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -26,105 +26,112 @@ module.exports = __toCommonJS(query_exports);
26
26
  var import_entity = require("../../entity.cjs");
27
27
  var import_query_promise = require("../../query-promise.cjs");
28
28
  var import_relations = require("../../relations.cjs");
29
+ var import_sql = require("../../sql/sql.cjs");
29
30
  class RelationalQueryBuilder {
30
- constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
31
+ constructor(mode, tables, schema, tableNamesMap, table, tableConfig, dialect, session, rowMode) {
31
32
  this.mode = mode;
32
- this.fullSchema = fullSchema;
33
+ this.tables = tables;
33
34
  this.schema = schema;
34
35
  this.tableNamesMap = tableNamesMap;
35
36
  this.table = table;
36
37
  this.tableConfig = tableConfig;
37
38
  this.dialect = dialect;
38
39
  this.session = session;
40
+ this.rowMode = rowMode;
39
41
  }
40
- static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryBuilder";
42
+ static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryBuilderV2";
41
43
  findMany(config) {
42
44
  return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
43
- this.fullSchema,
45
+ this.tables,
44
46
  this.schema,
45
47
  this.tableNamesMap,
46
48
  this.table,
47
49
  this.tableConfig,
48
50
  this.dialect,
49
51
  this.session,
50
- config ? config : {},
51
- "many"
52
+ config ?? true,
53
+ "many",
54
+ this.rowMode
52
55
  ) : new SQLiteRelationalQuery(
53
- this.fullSchema,
56
+ this.tables,
54
57
  this.schema,
55
58
  this.tableNamesMap,
56
59
  this.table,
57
60
  this.tableConfig,
58
61
  this.dialect,
59
62
  this.session,
60
- config ? config : {},
61
- "many"
63
+ config ?? true,
64
+ "many",
65
+ this.rowMode
62
66
  );
63
67
  }
64
68
  findFirst(config) {
65
69
  return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
66
- this.fullSchema,
70
+ this.tables,
67
71
  this.schema,
68
72
  this.tableNamesMap,
69
73
  this.table,
70
74
  this.tableConfig,
71
75
  this.dialect,
72
76
  this.session,
73
- config ? { ...config, limit: 1 } : { limit: 1 },
74
- "first"
77
+ config ?? true,
78
+ "first",
79
+ this.rowMode
75
80
  ) : new SQLiteRelationalQuery(
76
- this.fullSchema,
81
+ this.tables,
77
82
  this.schema,
78
83
  this.tableNamesMap,
79
84
  this.table,
80
85
  this.tableConfig,
81
86
  this.dialect,
82
87
  this.session,
83
- config ? { ...config, limit: 1 } : { limit: 1 },
84
- "first"
88
+ config ?? true,
89
+ "first",
90
+ this.rowMode
85
91
  );
86
92
  }
87
93
  }
88
94
  class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
89
- constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
95
+ constructor(tables, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode, rowMode) {
90
96
  super();
91
- this.fullSchema = fullSchema;
97
+ this.tables = tables;
92
98
  this.schema = schema;
93
99
  this.tableNamesMap = tableNamesMap;
94
- this.table = table;
95
100
  this.tableConfig = tableConfig;
96
101
  this.dialect = dialect;
97
102
  this.session = session;
98
103
  this.config = config;
104
+ this.rowMode = rowMode;
99
105
  this.mode = mode;
106
+ this.table = table;
100
107
  }
101
- static [import_entity.entityKind] = "SQLiteAsyncRelationalQuery";
108
+ static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryV2";
102
109
  /** @internal */
103
110
  mode;
104
111
  /** @internal */
112
+ table;
113
+ /** @internal */
105
114
  getSQL() {
106
- return this.dialect.buildRelationalQuery({
107
- fullSchema: this.fullSchema,
115
+ const query = this.dialect.buildRelationalQuery({
108
116
  schema: this.schema,
109
117
  tableNamesMap: this.tableNamesMap,
110
118
  table: this.table,
111
119
  tableConfig: this.tableConfig,
112
120
  queryConfig: this.config,
113
- tableAlias: this.tableConfig.tsName
114
- }).sql;
121
+ tables: this.tables,
122
+ mode: this.mode
123
+ });
124
+ return query.sql;
115
125
  }
116
126
  /** @internal */
117
- _prepare(isOneTimeQuery = false) {
127
+ _prepare(isOneTimeQuery = true) {
118
128
  const { query, builtQuery } = this._toSQL();
119
- return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
129
+ return this.session[isOneTimeQuery ? "prepareOneTimeRelationalQuery" : "prepareRelationalQuery"](
120
130
  builtQuery,
121
131
  void 0,
122
132
  this.mode === "first" ? "get" : "all",
123
- true,
124
133
  (rawRows, mapColumnValue) => {
125
- const rows = rawRows.map(
126
- (row) => (0, import_relations.mapRelationalRow)(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
127
- );
134
+ const rows = rawRows.map((row) => (0, import_relations.mapRelationalRow)(row, query.selection, mapColumnValue, !this.rowMode));
128
135
  if (this.mode === "first") {
129
136
  return rows[0];
130
137
  }
@@ -135,16 +142,30 @@ class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
135
142
  prepare() {
136
143
  return this._prepare(false);
137
144
  }
138
- _toSQL() {
145
+ _getQuery() {
139
146
  const query = this.dialect.buildRelationalQuery({
140
- fullSchema: this.fullSchema,
141
147
  schema: this.schema,
142
148
  tableNamesMap: this.tableNamesMap,
143
149
  table: this.table,
144
150
  tableConfig: this.tableConfig,
145
151
  queryConfig: this.config,
146
- tableAlias: this.tableConfig.tsName
152
+ tables: this.tables,
153
+ mode: this.mode,
154
+ isNested: this.rowMode
147
155
  });
156
+ if (this.rowMode) {
157
+ const jsonColumns = import_sql.sql.join(
158
+ query.selection.map((s) => {
159
+ return import_sql.sql`${import_sql.sql.raw(this.dialect.escapeString(s.key))}, ${s.selection ? import_sql.sql`jsonb(${import_sql.sql.identifier(s.key)})` : import_sql.sql.identifier(s.key)}`;
160
+ }),
161
+ import_sql.sql`, `
162
+ );
163
+ query.sql = import_sql.sql`select json_object(${jsonColumns}) as ${import_sql.sql.identifier("r")} from (${query.sql}) as ${import_sql.sql.identifier("t")}`;
164
+ }
165
+ return query;
166
+ }
167
+ _toSQL() {
168
+ const query = this._getQuery();
148
169
  const builtQuery = this.dialect.sqlToQuery(query.sql);
149
170
  return { query, builtQuery };
150
171
  }
@@ -154,16 +175,16 @@ class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
154
175
  /** @internal */
155
176
  executeRaw() {
156
177
  if (this.mode === "first") {
157
- return this._prepare(false).get();
178
+ return this._prepare().get();
158
179
  }
159
- return this._prepare(false).all();
180
+ return this._prepare().all();
160
181
  }
161
182
  async execute() {
162
183
  return this.executeRaw();
163
184
  }
164
185
  }
165
186
  class SQLiteSyncRelationalQuery extends SQLiteRelationalQuery {
166
- static [import_entity.entityKind] = "SQLiteSyncRelationalQuery";
187
+ static [import_entity.entityKind] = "SQLiteSyncRelationalQueryV2";
167
188
  sync() {
168
189
  return this.executeRaw();
169
190
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/sqlite-core/query-builders/query.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport {\n\ttype BuildQueryResult,\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tmapRelationalRow,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Query, QueryWithTypings, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { KnownKeysOnly } from '~/utils.ts';\nimport type { SQLiteDialect } from '../dialect.ts';\nimport type { PreparedQueryConfig, SQLitePreparedQuery, SQLiteSession } from '../session.ts';\nimport type { SQLiteTable } from '../table.ts';\n\nexport type SQLiteRelationalQueryKind<TMode extends 'sync' | 'async', TResult> = TMode extends 'async'\n\t? SQLiteRelationalQuery<TMode, TResult>\n\t: SQLiteSyncRelationalQuery<TResult>;\n\nexport class RelationalQueryBuilder<\n\tTMode extends 'sync' | 'async',\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tTFields extends TableRelationalConfig,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteAsyncRelationalQueryBuilder';\n\n\tconstructor(\n\t\tprotected mode: TMode,\n\t\tprotected fullSchema: Record<string, unknown>,\n\t\tprotected schema: TSchema,\n\t\tprotected tableNamesMap: Record<string, string>,\n\t\tprotected table: SQLiteTable,\n\t\tprotected tableConfig: TableRelationalConfig,\n\t\tprotected dialect: SQLiteDialect,\n\t\tprotected session: SQLiteSession<'async', unknown, TFullSchema, TSchema>,\n\t) {}\n\n\tfindMany<TConfig extends DBQueryConfig<'many', true, TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, DBQueryConfig<'many', true, TSchema, TFields>>,\n\t): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]> {\n\t\treturn (this.mode === 'sync'\n\t\t\t? new SQLiteSyncRelationalQuery(\n\t\t\t\tthis.fullSchema,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig ? (config as DBQueryConfig<'many', true>) : {},\n\t\t\t\t'many',\n\t\t\t)\n\t\t\t: new SQLiteRelationalQuery(\n\t\t\t\tthis.fullSchema,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig ? (config as DBQueryConfig<'many', true>) : {},\n\t\t\t\t'many',\n\t\t\t)) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>;\n\t}\n\n\tfindFirst<TSelection extends Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(\n\t\tconfig?: KnownKeysOnly<TSelection, Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>,\n\t): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TSelection> | undefined> {\n\t\treturn (this.mode === 'sync'\n\t\t\t? new SQLiteSyncRelationalQuery(\n\t\t\t\tthis.fullSchema,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig ? { ...(config as DBQueryConfig<'many', true> | undefined), limit: 1 } : { limit: 1 },\n\t\t\t\t'first',\n\t\t\t)\n\t\t\t: new SQLiteRelationalQuery(\n\t\t\t\tthis.fullSchema,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig ? { ...(config as DBQueryConfig<'many', true> | undefined), limit: 1 } : { limit: 1 },\n\t\t\t\t'first',\n\t\t\t)) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TSelection> | undefined>;\n\t}\n}\n\nexport class SQLiteRelationalQuery<TType extends 'sync' | 'async', TResult> extends QueryPromise<TResult>\n\timplements RunnableQuery<TResult, 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteAsyncRelationalQuery';\n\n\tdeclare readonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly type: TType;\n\t\treadonly result: TResult;\n\t};\n\n\t/** @internal */\n\tmode: 'many' | 'first';\n\n\tconstructor(\n\t\tprivate fullSchema: Record<string, unknown>,\n\t\tprivate schema: TablesRelationalConfig,\n\t\tprivate tableNamesMap: Record<string, string>,\n\t\t/** @internal */\n\t\tpublic table: SQLiteTable,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SQLiteDialect,\n\t\tprivate session: SQLiteSession<'sync' | 'async', unknown, Record<string, unknown>, TablesRelationalConfig>,\n\t\tprivate config: DBQueryConfig<'many', true> | true,\n\t\tmode: 'many' | 'first',\n\t) {\n\t\tsuper();\n\t\tthis.mode = mode;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildRelationalQuery({\n\t\t\tfullSchema: this.fullSchema,\n\t\t\tschema: this.schema,\n\t\t\ttableNamesMap: this.tableNamesMap,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\ttableAlias: this.tableConfig.tsName,\n\t\t}).sql as SQL;\n\t}\n\n\t/** @internal */\n\t_prepare(\n\t\tisOneTimeQuery = false,\n\t): SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }> {\n\t\tconst { query, builtQuery } = this._toSQL();\n\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tbuiltQuery,\n\t\t\tundefined,\n\t\t\tthis.mode === 'first' ? 'get' : 'all',\n\t\t\ttrue,\n\t\t\t(rawRows, mapColumnValue) => {\n\t\t\t\tconst rows = rawRows.map((row) =>\n\t\t\t\t\tmapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue)\n\t\t\t\t);\n\t\t\t\tif (this.mode === 'first') {\n\t\t\t\t\treturn rows[0] as TResult;\n\t\t\t\t}\n\t\t\t\treturn rows as TResult;\n\t\t\t},\n\t\t) as SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }>;\n\t}\n\n\tprepare(): SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }> {\n\t\treturn this._prepare(false);\n\t}\n\n\tprivate _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {\n\t\tconst query = this.dialect.buildRelationalQuery({\n\t\t\tfullSchema: this.fullSchema,\n\t\t\tschema: this.schema,\n\t\t\ttableNamesMap: this.tableNamesMap,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\ttableAlias: this.tableConfig.tsName,\n\t\t});\n\n\t\tconst builtQuery = this.dialect.sqlToQuery(query.sql as SQL);\n\n\t\treturn { query, builtQuery };\n\t}\n\n\ttoSQL(): Query {\n\t\treturn this._toSQL().builtQuery;\n\t}\n\n\t/** @internal */\n\texecuteRaw(): TResult {\n\t\tif (this.mode === 'first') {\n\t\t\treturn this._prepare(false).get() as TResult;\n\t\t}\n\t\treturn this._prepare(false).all() as TResult;\n\t}\n\n\toverride async execute(): Promise<TResult> {\n\t\treturn this.executeRaw();\n\t}\n}\n\nexport class SQLiteSyncRelationalQuery<TResult> extends SQLiteRelationalQuery<'sync', TResult> {\n\tstatic override readonly [entityKind]: string = 'SQLiteSyncRelationalQuery';\n\n\tsync(): TResult {\n\t\treturn this.executeRaw();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,2BAA6B;AAC7B,uBAOO;AAYA,MAAM,uBAKX;AAAA,EAGD,YACW,MACA,YACA,QACA,eACA,OACA,aACA,SACA,SACT;AARS;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EACR;AAAA,EAXH,QAAiB,wBAAU,IAAY;AAAA,EAavC,SACC,QACkF;AAClF,WAAQ,KAAK,SAAS,SACnB,IAAI;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,SAAU,SAAyC,CAAC;AAAA,MACpD;AAAA,IACD,IACE,IAAI;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,SAAU,SAAyC,CAAC;AAAA,MACpD;AAAA,IACD;AAAA,EACF;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,SAAS,mBAAmB;AAC5B,cAAM,OAAO,QAAQ;AAAA,UAAI,CAAC,YACzB,mCAAiB,KAAK,QAAQ,KAAK,aAAa,KAAK,MAAM,WAAW,cAAc;AAAA,QACrF;AACA,YAAI,KAAK,SAAS,SAAS;AAC1B,iBAAO,KAAK,CAAC;AAAA,QACd;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UAAoH;AACnH,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEQ,SAA8E;AACrF,UAAM,QAAQ,KAAK,QAAQ,qBAAqB;AAAA,MAC/C,YAAY,KAAK;AAAA,MACjB,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,YAAY,KAAK,YAAY;AAAA,IAC9B,CAAC;AAED,UAAM,aAAa,KAAK,QAAQ,WAAW,MAAM,GAAU;AAE3D,WAAO,EAAE,OAAO,WAAW;AAAA,EAC5B;AAAA,EAEA,QAAe;AACd,WAAO,KAAK,OAAO,EAAE;AAAA,EACtB;AAAA;AAAA,EAGA,aAAsB;AACrB,QAAI,KAAK,SAAS,SAAS;AAC1B,aAAO,KAAK,SAAS,KAAK,EAAE,IAAI;AAAA,IACjC;AACA,WAAO,KAAK,SAAS,KAAK,EAAE,IAAI;AAAA,EACjC;AAAA,EAEA,MAAe,UAA4B;AAC1C,WAAO,KAAK,WAAW;AAAA,EACxB;AACD;AAEO,MAAM,kCAA2C,sBAAuC;AAAA,EAC9F,QAA0B,wBAAU,IAAY;AAAA,EAEhD,OAAgB;AACf,WAAO,KAAK,WAAW;AAAA,EACxB;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../src/sqlite-core/query-builders/query.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport {\n\ttype BuildQueryResult,\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tmapRelationalRow,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport { type Query, type QueryWithTypings, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { KnownKeysOnly } from '~/utils.ts';\nimport type { SQLiteDialect } from '../dialect.ts';\nimport type { PreparedQueryConfig, SQLitePreparedQuery, SQLiteSession } from '../session.ts';\nimport type { SQLiteTable } from '../table.ts';\n\nexport type SQLiteRelationalQueryKind<TMode extends 'sync' | 'async', TResult> = TMode extends 'async'\n\t? SQLiteRelationalQuery<TMode, TResult>\n\t: SQLiteSyncRelationalQuery<TResult>;\n\nexport class RelationalQueryBuilder<\n\tTMode extends 'sync' | 'async',\n\tTSchema extends TablesRelationalConfig,\n\tTFields extends TableRelationalConfig,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteAsyncRelationalQueryBuilderV2';\n\n\tconstructor(\n\t\tprivate mode: TMode,\n\t\tprivate tables: Record<string, SQLiteTable>,\n\t\tprivate schema: TSchema,\n\t\tprivate tableNamesMap: Record<string, string>,\n\t\tprivate table: SQLiteTable,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SQLiteDialect,\n\t\tprivate session: SQLiteSession<any, any, any, any, any, any>,\n\t\tprivate rowMode?: boolean,\n\t) {\n\t}\n\n\tfindMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>,\n\t): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]> {\n\t\treturn this.mode === 'sync'\n\t\t\t? new SQLiteSyncRelationalQuery(\n\t\t\t\tthis.tables,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig as DBQueryConfig<'many'> | undefined ?? true,\n\t\t\t\t'many',\n\t\t\t\tthis.rowMode,\n\t\t\t) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>\n\t\t\t: new SQLiteRelationalQuery(\n\t\t\t\tthis.tables,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig as DBQueryConfig<'many'> | undefined ?? true,\n\t\t\t\t'many',\n\t\t\t\tthis.rowMode,\n\t\t\t) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>;\n\t}\n\n\tfindFirst<TConfig extends DBQueryConfig<'one', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, DBQueryConfig<'one', TSchema, TFields>>,\n\t): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined> {\n\t\treturn this.mode === 'sync'\n\t\t\t? new SQLiteSyncRelationalQuery(\n\t\t\t\tthis.tables,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig as DBQueryConfig<'one'> | undefined ?? true,\n\t\t\t\t'first',\n\t\t\t\tthis.rowMode,\n\t\t\t) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined>\n\t\t\t: new SQLiteRelationalQuery(\n\t\t\t\tthis.tables,\n\t\t\t\tthis.schema,\n\t\t\t\tthis.tableNamesMap,\n\t\t\t\tthis.table,\n\t\t\t\tthis.tableConfig,\n\t\t\t\tthis.dialect,\n\t\t\t\tthis.session,\n\t\t\t\tconfig as DBQueryConfig<'one'> | undefined ?? true,\n\t\t\t\t'first',\n\t\t\t\tthis.rowMode,\n\t\t\t) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined>;\n\t}\n}\n\nexport class SQLiteRelationalQuery<TType extends 'sync' | 'async', TResult> extends QueryPromise<TResult>\n\timplements RunnableQuery<TResult, 'sqlite'>, SQLWrapper\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteAsyncRelationalQueryV2';\n\n\tdeclare readonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly type: TType;\n\t\treadonly result: TResult;\n\t};\n\n\t/** @internal */\n\tmode: 'many' | 'first';\n\t/** @internal */\n\ttable: SQLiteTable;\n\n\tconstructor(\n\t\tprivate tables: Record<string, SQLiteTable>,\n\t\tprivate schema: TablesRelationalConfig,\n\t\tprivate tableNamesMap: Record<string, string>,\n\t\ttable: SQLiteTable,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SQLiteDialect,\n\t\tprivate session: SQLiteSession<TType, any, any, any, any, any>,\n\t\tprivate config: DBQueryConfig<'many' | 'one'> | true,\n\t\tmode: 'many' | 'first',\n\t\tprivate rowMode?: boolean,\n\t) {\n\t\tsuper();\n\t\tthis.mode = mode;\n\t\tthis.table = table;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\tconst query = this.dialect.buildRelationalQuery({\n\t\t\tschema: this.schema,\n\t\t\ttableNamesMap: this.tableNamesMap,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\ttables: this.tables,\n\t\t\tmode: this.mode,\n\t\t});\n\n\t\treturn query.sql;\n\t}\n\n\t/** @internal */\n\t_prepare(\n\t\tisOneTimeQuery = true,\n\t): SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }> {\n\t\tconst { query, builtQuery } = this._toSQL();\n\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeRelationalQuery' : 'prepareRelationalQuery'](\n\t\t\tbuiltQuery,\n\t\t\tundefined,\n\t\t\tthis.mode === 'first' ? 'get' : 'all',\n\t\t\t(rawRows, mapColumnValue) => {\n\t\t\t\tconst rows = rawRows.map((row) => mapRelationalRow(row, query.selection, mapColumnValue, !this.rowMode));\n\t\t\t\tif (this.mode === 'first') {\n\t\t\t\t\treturn rows[0] as TResult;\n\t\t\t\t}\n\t\t\t\treturn rows as TResult;\n\t\t\t},\n\t\t) as SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }>;\n\t}\n\n\tprepare(): SQLitePreparedQuery<PreparedQueryConfig & { type: TType; all: TResult; get: TResult; execute: TResult }> {\n\t\treturn this._prepare(false);\n\t}\n\n\tprivate _getQuery() {\n\t\tconst query = this.dialect.buildRelationalQuery({\n\t\t\tschema: this.schema,\n\t\t\ttableNamesMap: this.tableNamesMap,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\ttables: this.tables,\n\t\t\tmode: this.mode,\n\t\t\tisNested: this.rowMode,\n\t\t});\n\n\t\tif (this.rowMode) {\n\t\t\tconst jsonColumns = sql.join(\n\t\t\t\tquery.selection.map((s) => {\n\t\t\t\t\treturn sql`${sql.raw(this.dialect.escapeString(s.key))}, ${\n\t\t\t\t\t\ts.selection ? sql`jsonb(${sql.identifier(s.key)})` : sql.identifier(s.key)\n\t\t\t\t\t}`;\n\t\t\t\t}),\n\t\t\t\tsql`, `,\n\t\t\t);\n\n\t\t\tquery.sql = sql`select json_object(${jsonColumns}) as ${sql.identifier('r')} from (${query.sql}) as ${\n\t\t\t\tsql.identifier('t')\n\t\t\t}`;\n\t\t}\n\n\t\treturn query;\n\t}\n\n\tprivate _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {\n\t\tconst query = this._getQuery();\n\n\t\tconst builtQuery = this.dialect.sqlToQuery(query.sql);\n\n\t\treturn { query, builtQuery };\n\t}\n\n\ttoSQL(): Query {\n\t\treturn this._toSQL().builtQuery;\n\t}\n\n\t/** @internal */\n\texecuteRaw(): TResult {\n\t\tif (this.mode === 'first') {\n\t\t\treturn this._prepare().get() as TResult;\n\t\t}\n\t\treturn this._prepare().all() as TResult;\n\t}\n\n\toverride async execute(): Promise<TResult> {\n\t\treturn this.executeRaw();\n\t}\n}\n\nexport class SQLiteSyncRelationalQuery<TResult> extends SQLiteRelationalQuery<'sync', TResult> {\n\tstatic override readonly [entityKind]: string = 'SQLiteSyncRelationalQueryV2';\n\n\tsync(): TResult {\n\t\treturn this.executeRaw();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,2BAA6B;AAC7B,uBAOO;AAEP,iBAAkF;AAU3E,MAAM,uBAIX;AAAA,EAGD,YACS,MACA,QACA,QACA,eACA,OACA,aACA,SACA,SACA,SACP;AATO;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EAET;AAAA,EAbA,QAAiB,wBAAU,IAAY;AAAA,EAevC,SACC,QACkF;AAClF,WAAO,KAAK,SAAS,SAClB,IAAI;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA+C;AAAA,MAC/C;AAAA,MACA,KAAK;AAAA,IACN,IACE,IAAI;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA+C;AAAA,MAC/C;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACF;AAAA,EAEA,UACC,QAC4F;AAC5F,WAAO,KAAK,SAAS,SAClB,IAAI;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAA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