drizzle-orm 0.39.2-aaa57ff → 0.39.2-dc3b366

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (629) hide show
  1. package/alias.cjs.map +1 -1
  2. package/alias.d.cts +3 -3
  3. package/alias.d.ts +3 -3
  4. package/alias.js.map +1 -1
  5. package/aws-data-api/pg/driver.cjs +5 -19
  6. package/aws-data-api/pg/driver.cjs.map +1 -1
  7. package/aws-data-api/pg/driver.d.cts +8 -9
  8. package/aws-data-api/pg/driver.d.ts +8 -9
  9. package/aws-data-api/pg/driver.js +8 -9
  10. package/aws-data-api/pg/driver.js.map +1 -1
  11. package/aws-data-api/pg/migrator.cjs.map +1 -1
  12. package/aws-data-api/pg/migrator.d.cts +1 -2
  13. package/aws-data-api/pg/migrator.d.ts +1 -2
  14. package/aws-data-api/pg/migrator.js.map +1 -1
  15. package/aws-data-api/pg/session.cjs +4 -67
  16. package/aws-data-api/pg/session.cjs.map +1 -1
  17. package/aws-data-api/pg/session.d.cts +8 -13
  18. package/aws-data-api/pg/session.d.ts +8 -13
  19. package/aws-data-api/pg/session.js +4 -67
  20. package/aws-data-api/pg/session.js.map +1 -1
  21. package/better-sqlite3/driver.cjs +5 -12
  22. package/better-sqlite3/driver.cjs.map +1 -1
  23. package/better-sqlite3/driver.d.cts +6 -7
  24. package/better-sqlite3/driver.d.ts +6 -7
  25. package/better-sqlite3/driver.js +8 -12
  26. package/better-sqlite3/driver.js.map +1 -1
  27. package/better-sqlite3/migrator.cjs.map +1 -1
  28. package/better-sqlite3/migrator.d.cts +1 -2
  29. package/better-sqlite3/migrator.d.ts +1 -2
  30. package/better-sqlite3/migrator.js.map +1 -1
  31. package/better-sqlite3/session.cjs +4 -49
  32. package/better-sqlite3/session.cjs.map +1 -1
  33. package/better-sqlite3/session.d.cts +8 -14
  34. package/better-sqlite3/session.d.ts +8 -14
  35. package/better-sqlite3/session.js +4 -49
  36. package/better-sqlite3/session.js.map +1 -1
  37. package/bun-sql/driver.cjs +5 -16
  38. package/bun-sql/driver.cjs.map +1 -1
  39. package/bun-sql/driver.d.cts +6 -7
  40. package/bun-sql/driver.d.ts +6 -7
  41. package/bun-sql/driver.js +8 -6
  42. package/bun-sql/driver.js.map +1 -1
  43. package/bun-sql/migrator.cjs.map +1 -1
  44. package/bun-sql/migrator.d.cts +1 -2
  45. package/bun-sql/migrator.d.ts +1 -2
  46. package/bun-sql/migrator.js.map +1 -1
  47. package/bun-sql/session.cjs +6 -50
  48. package/bun-sql/session.cjs.map +1 -1
  49. package/bun-sql/session.d.cts +9 -14
  50. package/bun-sql/session.d.ts +9 -14
  51. package/bun-sql/session.js +6 -50
  52. package/bun-sql/session.js.map +1 -1
  53. package/bun-sqlite/driver.cjs +5 -22
  54. package/bun-sqlite/driver.cjs.map +1 -1
  55. package/bun-sqlite/driver.d.cts +6 -7
  56. package/bun-sqlite/driver.d.ts +6 -7
  57. package/bun-sqlite/driver.js +8 -12
  58. package/bun-sqlite/driver.js.map +1 -1
  59. package/bun-sqlite/migrator.cjs.map +1 -1
  60. package/bun-sqlite/migrator.d.cts +1 -2
  61. package/bun-sqlite/migrator.d.ts +1 -2
  62. package/bun-sqlite/migrator.js.map +1 -1
  63. package/bun-sqlite/session.cjs +4 -49
  64. package/bun-sqlite/session.cjs.map +1 -1
  65. package/bun-sqlite/session.d.cts +8 -14
  66. package/bun-sqlite/session.d.ts +8 -14
  67. package/bun-sqlite/session.js +4 -49
  68. package/bun-sqlite/session.js.map +1 -1
  69. package/d1/driver.cjs +5 -22
  70. package/d1/driver.cjs.map +1 -1
  71. package/d1/driver.d.cts +2 -3
  72. package/d1/driver.d.ts +2 -3
  73. package/d1/driver.js +8 -12
  74. package/d1/driver.js.map +1 -1
  75. package/d1/migrator.cjs.map +1 -1
  76. package/d1/migrator.d.cts +1 -2
  77. package/d1/migrator.d.ts +1 -2
  78. package/d1/migrator.js.map +1 -1
  79. package/d1/session.cjs +8 -50
  80. package/d1/session.cjs.map +1 -1
  81. package/d1/session.d.cts +8 -15
  82. package/d1/session.d.ts +8 -15
  83. package/d1/session.js +8 -50
  84. package/d1/session.js.map +1 -1
  85. package/durable-sqlite/driver.cjs +5 -16
  86. package/durable-sqlite/driver.cjs.map +1 -1
  87. package/durable-sqlite/driver.d.cts +2 -3
  88. package/durable-sqlite/driver.d.ts +2 -3
  89. package/durable-sqlite/driver.js +8 -6
  90. package/durable-sqlite/driver.js.map +1 -1
  91. package/durable-sqlite/migrator.cjs.map +1 -1
  92. package/durable-sqlite/migrator.d.cts +1 -2
  93. package/durable-sqlite/migrator.d.ts +1 -2
  94. package/durable-sqlite/migrator.js.map +1 -1
  95. package/durable-sqlite/session.cjs +4 -46
  96. package/durable-sqlite/session.cjs.map +1 -1
  97. package/durable-sqlite/session.d.cts +8 -14
  98. package/durable-sqlite/session.d.ts +8 -14
  99. package/durable-sqlite/session.js +4 -46
  100. package/durable-sqlite/session.js.map +1 -1
  101. package/expo-sqlite/driver.cjs +5 -22
  102. package/expo-sqlite/driver.cjs.map +1 -1
  103. package/expo-sqlite/driver.d.cts +2 -3
  104. package/expo-sqlite/driver.d.ts +2 -3
  105. package/expo-sqlite/driver.js +8 -12
  106. package/expo-sqlite/driver.js.map +1 -1
  107. package/expo-sqlite/migrator.cjs.map +1 -1
  108. package/expo-sqlite/migrator.d.cts +2 -3
  109. package/expo-sqlite/migrator.d.ts +2 -3
  110. package/expo-sqlite/migrator.js.map +1 -1
  111. package/expo-sqlite/query.cjs +2 -13
  112. package/expo-sqlite/query.cjs.map +1 -1
  113. package/expo-sqlite/query.d.cts +1 -2
  114. package/expo-sqlite/query.d.ts +1 -2
  115. package/expo-sqlite/query.js +2 -3
  116. package/expo-sqlite/query.js.map +1 -1
  117. package/expo-sqlite/session.cjs +4 -47
  118. package/expo-sqlite/session.cjs.map +1 -1
  119. package/expo-sqlite/session.d.cts +8 -14
  120. package/expo-sqlite/session.d.ts +8 -14
  121. package/expo-sqlite/session.js +4 -47
  122. package/expo-sqlite/session.js.map +1 -1
  123. package/libsql/driver-core.cjs +5 -22
  124. package/libsql/driver-core.cjs.map +1 -1
  125. package/libsql/driver-core.d.cts +1 -2
  126. package/libsql/driver-core.d.ts +1 -2
  127. package/libsql/driver-core.js +8 -12
  128. package/libsql/driver-core.js.map +1 -1
  129. package/libsql/driver.cjs.map +1 -1
  130. package/libsql/driver.d.cts +5 -6
  131. package/libsql/driver.d.ts +5 -6
  132. package/libsql/driver.js.map +1 -1
  133. package/libsql/http/index.cjs.map +1 -1
  134. package/libsql/http/index.d.cts +5 -6
  135. package/libsql/http/index.d.ts +5 -6
  136. package/libsql/http/index.js.map +1 -1
  137. package/libsql/migrator.cjs.map +1 -1
  138. package/libsql/migrator.d.cts +1 -2
  139. package/libsql/migrator.d.ts +1 -2
  140. package/libsql/migrator.js.map +1 -1
  141. package/libsql/node/index.cjs.map +1 -1
  142. package/libsql/node/index.d.cts +5 -6
  143. package/libsql/node/index.d.ts +5 -6
  144. package/libsql/node/index.js.map +1 -1
  145. package/libsql/session.cjs +4 -56
  146. package/libsql/session.cjs.map +1 -1
  147. package/libsql/session.d.cts +9 -15
  148. package/libsql/session.d.ts +9 -15
  149. package/libsql/session.js +4 -56
  150. package/libsql/session.js.map +1 -1
  151. package/libsql/sqlite3/index.cjs.map +1 -1
  152. package/libsql/sqlite3/index.d.cts +5 -6
  153. package/libsql/sqlite3/index.d.ts +5 -6
  154. package/libsql/sqlite3/index.js.map +1 -1
  155. package/libsql/wasm/index.cjs.map +1 -1
  156. package/libsql/wasm/index.d.cts +5 -6
  157. package/libsql/wasm/index.d.ts +5 -6
  158. package/libsql/wasm/index.js.map +1 -1
  159. package/libsql/web/index.cjs.map +1 -1
  160. package/libsql/web/index.d.cts +5 -6
  161. package/libsql/web/index.d.ts +5 -6
  162. package/libsql/web/index.js.map +1 -1
  163. package/libsql/ws/index.cjs.map +1 -1
  164. package/libsql/ws/index.d.cts +5 -6
  165. package/libsql/ws/index.d.ts +5 -6
  166. package/libsql/ws/index.js.map +1 -1
  167. package/mysql-core/db.cjs +6 -30
  168. package/mysql-core/db.cjs.map +1 -1
  169. package/mysql-core/db.d.cts +8 -15
  170. package/mysql-core/db.d.ts +8 -15
  171. package/mysql-core/db.js +5 -29
  172. package/mysql-core/db.js.map +1 -1
  173. package/mysql-core/dialect.cjs +15 -197
  174. package/mysql-core/dialect.cjs.map +1 -1
  175. package/mysql-core/dialect.d.cts +13 -36
  176. package/mysql-core/dialect.d.ts +13 -36
  177. package/mysql-core/dialect.js +22 -196
  178. package/mysql-core/dialect.js.map +1 -1
  179. package/mysql-core/query-builders/count.cjs.map +1 -1
  180. package/mysql-core/query-builders/count.d.cts +1 -1
  181. package/mysql-core/query-builders/count.d.ts +1 -1
  182. package/mysql-core/query-builders/count.js.map +1 -1
  183. package/mysql-core/query-builders/query.cjs +31 -18
  184. package/mysql-core/query-builders/query.cjs.map +1 -1
  185. package/mysql-core/query-builders/query.d.cts +10 -8
  186. package/mysql-core/query-builders/query.d.ts +10 -8
  187. package/mysql-core/query-builders/query.js +31 -18
  188. package/mysql-core/query-builders/query.js.map +1 -1
  189. package/mysql-core/session.cjs +2 -3
  190. package/mysql-core/session.cjs.map +1 -1
  191. package/mysql-core/session.d.cts +7 -10
  192. package/mysql-core/session.d.ts +7 -10
  193. package/mysql-core/session.js +2 -3
  194. package/mysql-core/session.js.map +1 -1
  195. package/mysql-proxy/driver.cjs +5 -22
  196. package/mysql-proxy/driver.cjs.map +1 -1
  197. package/mysql-proxy/driver.d.cts +2 -3
  198. package/mysql-proxy/driver.d.ts +2 -3
  199. package/mysql-proxy/driver.js +8 -12
  200. package/mysql-proxy/driver.js.map +1 -1
  201. package/mysql-proxy/migrator.cjs.map +1 -1
  202. package/mysql-proxy/migrator.d.cts +1 -2
  203. package/mysql-proxy/migrator.d.ts +1 -2
  204. package/mysql-proxy/migrator.js.map +1 -1
  205. package/mysql-proxy/session.cjs +2 -27
  206. package/mysql-proxy/session.cjs.map +1 -1
  207. package/mysql-proxy/session.d.cts +8 -13
  208. package/mysql-proxy/session.d.ts +8 -13
  209. package/mysql-proxy/session.js +2 -27
  210. package/mysql-proxy/session.js.map +1 -1
  211. package/mysql2/driver.cjs +7 -24
  212. package/mysql2/driver.cjs.map +1 -1
  213. package/mysql2/driver.d.cts +9 -10
  214. package/mysql2/driver.d.ts +9 -10
  215. package/mysql2/driver.js +10 -14
  216. package/mysql2/driver.js.map +1 -1
  217. package/mysql2/migrator.cjs.map +1 -1
  218. package/mysql2/migrator.d.cts +1 -2
  219. package/mysql2/migrator.d.ts +1 -2
  220. package/mysql2/migrator.js.map +1 -1
  221. package/mysql2/session.cjs +2 -30
  222. package/mysql2/session.cjs.map +1 -1
  223. package/mysql2/session.d.cts +8 -13
  224. package/mysql2/session.d.ts +8 -13
  225. package/mysql2/session.js +2 -30
  226. package/mysql2/session.js.map +1 -1
  227. package/neon-http/driver.cjs +7 -21
  228. package/neon-http/driver.cjs.map +1 -1
  229. package/neon-http/driver.d.cts +9 -10
  230. package/neon-http/driver.d.ts +9 -10
  231. package/neon-http/driver.js +7 -11
  232. package/neon-http/driver.js.map +1 -1
  233. package/neon-http/migrator.cjs.map +1 -1
  234. package/neon-http/migrator.d.cts +1 -2
  235. package/neon-http/migrator.d.ts +1 -2
  236. package/neon-http/migrator.js.map +1 -1
  237. package/neon-http/session.cjs +2 -32
  238. package/neon-http/session.cjs.map +1 -1
  239. package/neon-http/session.d.cts +8 -13
  240. package/neon-http/session.d.ts +8 -13
  241. package/neon-http/session.js +2 -32
  242. package/neon-http/session.js.map +1 -1
  243. package/neon-serverless/driver.cjs +7 -18
  244. package/neon-serverless/driver.cjs.map +1 -1
  245. package/neon-serverless/driver.d.cts +8 -9
  246. package/neon-serverless/driver.d.ts +8 -9
  247. package/neon-serverless/driver.js +10 -8
  248. package/neon-serverless/driver.js.map +1 -1
  249. package/neon-serverless/migrator.cjs.map +1 -1
  250. package/neon-serverless/migrator.d.cts +1 -2
  251. package/neon-serverless/migrator.d.ts +1 -2
  252. package/neon-serverless/migrator.js.map +1 -1
  253. package/neon-serverless/session.cjs +5 -40
  254. package/neon-serverless/session.cjs.map +1 -1
  255. package/neon-serverless/session.d.cts +8 -13
  256. package/neon-serverless/session.d.ts +8 -13
  257. package/neon-serverless/session.js +5 -40
  258. package/neon-serverless/session.js.map +1 -1
  259. package/node-postgres/driver.cjs +7 -13
  260. package/node-postgres/driver.cjs.map +1 -1
  261. package/node-postgres/driver.d.cts +8 -9
  262. package/node-postgres/driver.d.ts +8 -9
  263. package/node-postgres/driver.js +10 -13
  264. package/node-postgres/driver.js.map +1 -1
  265. package/node-postgres/migrator.cjs.map +1 -1
  266. package/node-postgres/migrator.d.cts +1 -2
  267. package/node-postgres/migrator.d.ts +1 -2
  268. package/node-postgres/migrator.js.map +1 -1
  269. package/node-postgres/session.cjs +4 -45
  270. package/node-postgres/session.cjs.map +1 -1
  271. package/node-postgres/session.d.cts +8 -13
  272. package/node-postgres/session.d.ts +8 -13
  273. package/node-postgres/session.js +4 -45
  274. package/node-postgres/session.js.map +1 -1
  275. package/op-sqlite/driver.cjs +5 -22
  276. package/op-sqlite/driver.cjs.map +1 -1
  277. package/op-sqlite/driver.d.cts +2 -3
  278. package/op-sqlite/driver.d.ts +2 -3
  279. package/op-sqlite/driver.js +8 -12
  280. package/op-sqlite/driver.js.map +1 -1
  281. package/op-sqlite/migrator.cjs.map +1 -1
  282. package/op-sqlite/migrator.d.cts +2 -3
  283. package/op-sqlite/migrator.d.ts +2 -3
  284. package/op-sqlite/migrator.js.map +1 -1
  285. package/op-sqlite/session.cjs +4 -47
  286. package/op-sqlite/session.cjs.map +1 -1
  287. package/op-sqlite/session.d.cts +8 -14
  288. package/op-sqlite/session.d.ts +8 -14
  289. package/op-sqlite/session.js +4 -47
  290. package/op-sqlite/session.js.map +1 -1
  291. package/package.json +51 -99
  292. package/pg-core/db.cjs +5 -32
  293. package/pg-core/db.cjs.map +1 -1
  294. package/pg-core/db.d.cts +9 -16
  295. package/pg-core/db.d.ts +9 -16
  296. package/pg-core/db.js +4 -31
  297. package/pg-core/db.js.map +1 -1
  298. package/pg-core/dialect.cjs +488 -173
  299. package/pg-core/dialect.cjs.map +1 -1
  300. package/pg-core/dialect.d.cts +8 -27
  301. package/pg-core/dialect.d.ts +8 -27
  302. package/pg-core/dialect.js +495 -172
  303. package/pg-core/dialect.js.map +1 -1
  304. package/pg-core/query-builders/count.cjs.map +1 -1
  305. package/pg-core/query-builders/count.d.cts +1 -1
  306. package/pg-core/query-builders/count.d.ts +1 -1
  307. package/pg-core/query-builders/count.js.map +1 -1
  308. package/pg-core/query-builders/query.cjs +18 -15
  309. package/pg-core/query-builders/query.cjs.map +1 -1
  310. package/pg-core/query-builders/query.d.cts +6 -6
  311. package/pg-core/query-builders/query.d.ts +6 -6
  312. package/pg-core/query-builders/query.js +18 -15
  313. package/pg-core/query-builders/query.js.map +1 -1
  314. package/pg-core/session.cjs +2 -3
  315. package/pg-core/session.cjs.map +1 -1
  316. package/pg-core/session.d.cts +6 -9
  317. package/pg-core/session.d.ts +6 -9
  318. package/pg-core/session.js +2 -3
  319. package/pg-core/session.js.map +1 -1
  320. package/pg-proxy/driver.cjs +5 -21
  321. package/pg-proxy/driver.cjs.map +1 -1
  322. package/pg-proxy/driver.d.cts +2 -3
  323. package/pg-proxy/driver.d.ts +2 -3
  324. package/pg-proxy/driver.js +8 -11
  325. package/pg-proxy/driver.js.map +1 -1
  326. package/pg-proxy/migrator.cjs.map +1 -1
  327. package/pg-proxy/migrator.d.cts +1 -2
  328. package/pg-proxy/migrator.d.ts +1 -2
  329. package/pg-proxy/migrator.js.map +1 -1
  330. package/pg-proxy/session.cjs +2 -37
  331. package/pg-proxy/session.cjs.map +1 -1
  332. package/pg-proxy/session.d.cts +8 -13
  333. package/pg-proxy/session.d.ts +8 -13
  334. package/pg-proxy/session.js +2 -37
  335. package/pg-proxy/session.js.map +1 -1
  336. package/pglite/driver.cjs +7 -23
  337. package/pglite/driver.cjs.map +1 -1
  338. package/pglite/driver.d.cts +8 -9
  339. package/pglite/driver.d.ts +8 -9
  340. package/pglite/driver.js +10 -13
  341. package/pglite/driver.js.map +1 -1
  342. package/pglite/migrator.cjs.map +1 -1
  343. package/pglite/migrator.d.cts +1 -2
  344. package/pglite/migrator.d.ts +1 -2
  345. package/pglite/migrator.js.map +1 -1
  346. package/pglite/session.cjs +3 -34
  347. package/pglite/session.cjs.map +1 -1
  348. package/pglite/session.d.cts +8 -13
  349. package/pglite/session.d.ts +8 -13
  350. package/pglite/session.js +3 -34
  351. package/pglite/session.js.map +1 -1
  352. package/planetscale-serverless/driver.cjs +5 -22
  353. package/planetscale-serverless/driver.cjs.map +1 -1
  354. package/planetscale-serverless/driver.d.cts +6 -7
  355. package/planetscale-serverless/driver.d.ts +6 -7
  356. package/planetscale-serverless/driver.js +8 -12
  357. package/planetscale-serverless/driver.js.map +1 -1
  358. package/planetscale-serverless/migrator.cjs.map +1 -1
  359. package/planetscale-serverless/migrator.d.cts +1 -2
  360. package/planetscale-serverless/migrator.d.ts +1 -2
  361. package/planetscale-serverless/migrator.js.map +1 -1
  362. package/planetscale-serverless/session.cjs +5 -45
  363. package/planetscale-serverless/session.cjs.map +1 -1
  364. package/planetscale-serverless/session.d.cts +9 -14
  365. package/planetscale-serverless/session.d.ts +9 -14
  366. package/planetscale-serverless/session.js +5 -45
  367. package/planetscale-serverless/session.js.map +1 -1
  368. package/postgres-js/driver.cjs +5 -6
  369. package/postgres-js/driver.cjs.map +1 -1
  370. package/postgres-js/driver.d.cts +6 -7
  371. package/postgres-js/driver.d.ts +6 -7
  372. package/postgres-js/driver.js +8 -6
  373. package/postgres-js/driver.js.map +1 -1
  374. package/postgres-js/migrator.cjs.map +1 -1
  375. package/postgres-js/migrator.d.cts +1 -2
  376. package/postgres-js/migrator.d.ts +1 -2
  377. package/postgres-js/migrator.js.map +1 -1
  378. package/postgres-js/session.cjs +6 -51
  379. package/postgres-js/session.cjs.map +1 -1
  380. package/postgres-js/session.d.cts +9 -15
  381. package/postgres-js/session.d.ts +9 -15
  382. package/postgres-js/session.js +6 -51
  383. package/postgres-js/session.js.map +1 -1
  384. package/prisma/mysql/driver.cjs +1 -1
  385. package/prisma/mysql/driver.cjs.map +1 -1
  386. package/prisma/mysql/driver.js +1 -1
  387. package/prisma/mysql/driver.js.map +1 -1
  388. package/prisma/mysql/session.cjs +0 -3
  389. package/prisma/mysql/session.cjs.map +1 -1
  390. package/prisma/mysql/session.d.cts +1 -3
  391. package/prisma/mysql/session.d.ts +1 -3
  392. package/prisma/mysql/session.js +0 -3
  393. package/prisma/mysql/session.js.map +1 -1
  394. package/prisma/pg/driver.cjs +1 -1
  395. package/prisma/pg/driver.cjs.map +1 -1
  396. package/prisma/pg/driver.js +1 -1
  397. package/prisma/pg/driver.js.map +1 -1
  398. package/prisma/pg/session.cjs +0 -3
  399. package/prisma/pg/session.cjs.map +1 -1
  400. package/prisma/pg/session.d.cts +1 -3
  401. package/prisma/pg/session.d.ts +1 -3
  402. package/prisma/pg/session.js +0 -3
  403. package/prisma/pg/session.js.map +1 -1
  404. package/prisma/sqlite/driver.cjs +1 -1
  405. package/prisma/sqlite/driver.cjs.map +1 -1
  406. package/prisma/sqlite/driver.js +1 -1
  407. package/prisma/sqlite/driver.js.map +1 -1
  408. package/prisma/sqlite/session.cjs +0 -3
  409. package/prisma/sqlite/session.cjs.map +1 -1
  410. package/prisma/sqlite/session.d.cts +2 -4
  411. package/prisma/sqlite/session.d.ts +2 -4
  412. package/prisma/sqlite/session.js +0 -3
  413. package/prisma/sqlite/session.js.map +1 -1
  414. package/relations.cjs +245 -596
  415. package/relations.cjs.map +1 -1
  416. package/relations.d.cts +140 -292
  417. package/relations.d.ts +140 -292
  418. package/relations.js +240 -589
  419. package/relations.js.map +1 -1
  420. package/singlestore/driver.cjs +1 -1
  421. package/singlestore/driver.cjs.map +1 -1
  422. package/singlestore/driver.d.cts +1 -1
  423. package/singlestore/driver.d.ts +1 -1
  424. package/singlestore/driver.js +3 -3
  425. package/singlestore/driver.js.map +1 -1
  426. package/singlestore/session.cjs.map +1 -1
  427. package/singlestore/session.d.cts +4 -4
  428. package/singlestore/session.d.ts +4 -4
  429. package/singlestore/session.js.map +1 -1
  430. package/singlestore-core/db.cjs.map +1 -1
  431. package/singlestore-core/db.d.cts +3 -3
  432. package/singlestore-core/db.d.ts +3 -3
  433. package/singlestore-core/db.js.map +1 -1
  434. package/singlestore-core/dialect.cjs +6 -16
  435. package/singlestore-core/dialect.cjs.map +1 -1
  436. package/singlestore-core/dialect.d.cts +6 -6
  437. package/singlestore-core/dialect.d.ts +6 -6
  438. package/singlestore-core/dialect.js +12 -6
  439. package/singlestore-core/dialect.js.map +1 -1
  440. package/singlestore-core/query-builders/query.cjs +2 -12
  441. package/singlestore-core/query-builders/query.cjs.map +1 -1
  442. package/singlestore-core/query-builders/query.d.cts +6 -6
  443. package/singlestore-core/query-builders/query.d.ts +6 -6
  444. package/singlestore-core/query-builders/query.js +4 -2
  445. package/singlestore-core/query-builders/query.js.map +1 -1
  446. package/singlestore-core/session.cjs.map +1 -1
  447. package/singlestore-core/session.d.cts +5 -5
  448. package/singlestore-core/session.d.ts +5 -5
  449. package/singlestore-core/session.js.map +1 -1
  450. package/singlestore-proxy/driver.cjs +1 -1
  451. package/singlestore-proxy/driver.cjs.map +1 -1
  452. package/singlestore-proxy/driver.js +3 -3
  453. package/singlestore-proxy/driver.js.map +1 -1
  454. package/singlestore-proxy/session.cjs.map +1 -1
  455. package/singlestore-proxy/session.d.cts +4 -4
  456. package/singlestore-proxy/session.d.ts +4 -4
  457. package/singlestore-proxy/session.js.map +1 -1
  458. package/sql/expressions/conditions.cjs.map +1 -1
  459. package/sql/expressions/conditions.d.cts +4 -4
  460. package/sql/expressions/conditions.d.ts +4 -4
  461. package/sql/expressions/conditions.js.map +1 -1
  462. package/sql/sql.cjs +0 -21
  463. package/sql/sql.cjs.map +1 -1
  464. package/sql/sql.d.cts +8 -8
  465. package/sql/sql.d.ts +8 -8
  466. package/sql/sql.js +1 -22
  467. package/sql/sql.js.map +1 -1
  468. package/sql-js/driver.cjs +5 -16
  469. package/sql-js/driver.cjs.map +1 -1
  470. package/sql-js/driver.d.cts +2 -3
  471. package/sql-js/driver.d.ts +2 -3
  472. package/sql-js/driver.js +8 -6
  473. package/sql-js/driver.js.map +1 -1
  474. package/sql-js/migrator.cjs.map +1 -1
  475. package/sql-js/migrator.d.cts +1 -2
  476. package/sql-js/migrator.d.ts +1 -2
  477. package/sql-js/migrator.js.map +1 -1
  478. package/sql-js/session.cjs +36 -71
  479. package/sql-js/session.cjs.map +1 -1
  480. package/sql-js/session.d.cts +13 -16
  481. package/sql-js/session.d.ts +13 -16
  482. package/sql-js/session.js +36 -71
  483. package/sql-js/session.js.map +1 -1
  484. package/sqlite-core/db.cjs +12 -39
  485. package/sqlite-core/db.cjs.map +1 -1
  486. package/sqlite-core/db.d.cts +8 -16
  487. package/sqlite-core/db.d.ts +8 -16
  488. package/sqlite-core/db.js +11 -38
  489. package/sqlite-core/db.js.map +1 -1
  490. package/sqlite-core/dialect.cjs +7 -186
  491. package/sqlite-core/dialect.cjs.map +1 -1
  492. package/sqlite-core/dialect.d.cts +9 -31
  493. package/sqlite-core/dialect.d.ts +9 -31
  494. package/sqlite-core/dialect.js +14 -185
  495. package/sqlite-core/dialect.js.map +1 -1
  496. package/sqlite-core/query-builders/count.cjs.map +1 -1
  497. package/sqlite-core/query-builders/count.d.cts +1 -1
  498. package/sqlite-core/query-builders/count.d.ts +1 -1
  499. package/sqlite-core/query-builders/count.js.map +1 -1
  500. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  501. package/sqlite-core/query-builders/delete.d.cts +1 -1
  502. package/sqlite-core/query-builders/delete.d.ts +1 -1
  503. package/sqlite-core/query-builders/delete.js.map +1 -1
  504. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  505. package/sqlite-core/query-builders/insert.d.cts +3 -3
  506. package/sqlite-core/query-builders/insert.d.ts +3 -3
  507. package/sqlite-core/query-builders/insert.js.map +1 -1
  508. package/sqlite-core/query-builders/query.cjs +35 -56
  509. package/sqlite-core/query-builders/query.cjs.map +1 -1
  510. package/sqlite-core/query-builders/query.d.cts +17 -18
  511. package/sqlite-core/query-builders/query.d.ts +17 -18
  512. package/sqlite-core/query-builders/query.js +35 -56
  513. package/sqlite-core/query-builders/query.js.map +1 -1
  514. package/sqlite-core/query-builders/select.cjs.map +1 -1
  515. package/sqlite-core/query-builders/select.d.cts +3 -3
  516. package/sqlite-core/query-builders/select.d.ts +3 -3
  517. package/sqlite-core/query-builders/select.js.map +1 -1
  518. package/sqlite-core/query-builders/update.cjs.map +1 -1
  519. package/sqlite-core/query-builders/update.d.cts +3 -3
  520. package/sqlite-core/query-builders/update.d.ts +3 -3
  521. package/sqlite-core/query-builders/update.js.map +1 -1
  522. package/sqlite-core/session.cjs +2 -6
  523. package/sqlite-core/session.cjs.map +1 -1
  524. package/sqlite-core/session.d.cts +7 -15
  525. package/sqlite-core/session.d.ts +7 -15
  526. package/sqlite-core/session.js +2 -6
  527. package/sqlite-core/session.js.map +1 -1
  528. package/sqlite-proxy/driver.cjs +5 -23
  529. package/sqlite-proxy/driver.cjs.map +1 -1
  530. package/sqlite-proxy/driver.d.cts +3 -4
  531. package/sqlite-proxy/driver.d.ts +3 -4
  532. package/sqlite-proxy/driver.js +5 -13
  533. package/sqlite-proxy/driver.js.map +1 -1
  534. package/sqlite-proxy/migrator.cjs.map +1 -1
  535. package/sqlite-proxy/migrator.d.cts +1 -2
  536. package/sqlite-proxy/migrator.d.ts +1 -2
  537. package/sqlite-proxy/migrator.js.map +1 -1
  538. package/sqlite-proxy/session.cjs +6 -50
  539. package/sqlite-proxy/session.cjs.map +1 -1
  540. package/sqlite-proxy/session.d.cts +8 -14
  541. package/sqlite-proxy/session.d.ts +8 -14
  542. package/sqlite-proxy/session.js +6 -50
  543. package/sqlite-proxy/session.js.map +1 -1
  544. package/table.cjs.map +1 -1
  545. package/table.d.cts +2 -2
  546. package/table.d.ts +2 -2
  547. package/table.js.map +1 -1
  548. package/tidb-serverless/driver.cjs +5 -22
  549. package/tidb-serverless/driver.cjs.map +1 -1
  550. package/tidb-serverless/driver.d.cts +6 -7
  551. package/tidb-serverless/driver.d.ts +6 -7
  552. package/tidb-serverless/driver.js +8 -12
  553. package/tidb-serverless/driver.js.map +1 -1
  554. package/tidb-serverless/migrator.cjs.map +1 -1
  555. package/tidb-serverless/migrator.d.cts +1 -2
  556. package/tidb-serverless/migrator.d.ts +1 -2
  557. package/tidb-serverless/migrator.js.map +1 -1
  558. package/tidb-serverless/session.cjs +5 -62
  559. package/tidb-serverless/session.cjs.map +1 -1
  560. package/tidb-serverless/session.d.cts +9 -14
  561. package/tidb-serverless/session.d.ts +9 -14
  562. package/tidb-serverless/session.js +5 -62
  563. package/tidb-serverless/session.js.map +1 -1
  564. package/utils.cjs +2 -2
  565. package/utils.cjs.map +1 -1
  566. package/utils.d.cts +1 -3
  567. package/utils.d.ts +1 -3
  568. package/utils.js +2 -2
  569. package/utils.js.map +1 -1
  570. package/vercel-postgres/driver.cjs +7 -23
  571. package/vercel-postgres/driver.cjs.map +1 -1
  572. package/vercel-postgres/driver.d.cts +8 -9
  573. package/vercel-postgres/driver.d.ts +8 -9
  574. package/vercel-postgres/driver.js +10 -13
  575. package/vercel-postgres/driver.js.map +1 -1
  576. package/vercel-postgres/migrator.cjs.map +1 -1
  577. package/vercel-postgres/migrator.d.cts +1 -2
  578. package/vercel-postgres/migrator.d.ts +1 -2
  579. package/vercel-postgres/migrator.js.map +1 -1
  580. package/vercel-postgres/session.cjs +4 -34
  581. package/vercel-postgres/session.cjs.map +1 -1
  582. package/vercel-postgres/session.d.cts +8 -13
  583. package/vercel-postgres/session.d.ts +8 -13
  584. package/vercel-postgres/session.js +4 -34
  585. package/vercel-postgres/session.js.map +1 -1
  586. package/version.cjs +1 -1
  587. package/version.d.cts +1 -1
  588. package/version.d.ts +1 -1
  589. package/version.js +1 -1
  590. package/xata-http/driver.cjs +5 -17
  591. package/xata-http/driver.cjs.map +1 -1
  592. package/xata-http/driver.d.cts +4 -5
  593. package/xata-http/driver.d.ts +4 -5
  594. package/xata-http/driver.js +5 -7
  595. package/xata-http/driver.js.map +1 -1
  596. package/xata-http/migrator.cjs.map +1 -1
  597. package/xata-http/migrator.d.cts +1 -2
  598. package/xata-http/migrator.d.ts +1 -2
  599. package/xata-http/migrator.js.map +1 -1
  600. package/xata-http/session.cjs +2 -30
  601. package/xata-http/session.cjs.map +1 -1
  602. package/xata-http/session.d.cts +8 -13
  603. package/xata-http/session.d.ts +8 -13
  604. package/xata-http/session.js +2 -30
  605. package/xata-http/session.js.map +1 -1
  606. package/_relations.cjs +0 -328
  607. package/_relations.cjs.map +0 -1
  608. package/_relations.d.cts +0 -215
  609. package/_relations.d.ts +0 -215
  610. package/_relations.js +0 -316
  611. package/_relations.js.map +0 -1
  612. package/mysql-core/query-builders/_query.cjs +0 -149
  613. package/mysql-core/query-builders/_query.cjs.map +0 -1
  614. package/mysql-core/query-builders/_query.d.cts +0 -44
  615. package/mysql-core/query-builders/_query.d.ts +0 -44
  616. package/mysql-core/query-builders/_query.js +0 -114
  617. package/mysql-core/query-builders/_query.js.map +0 -1
  618. package/pg-core/query-builders/_query.cjs +0 -155
  619. package/pg-core/query-builders/_query.cjs.map +0 -1
  620. package/pg-core/query-builders/_query.d.cts +0 -47
  621. package/pg-core/query-builders/_query.d.ts +0 -47
  622. package/pg-core/query-builders/_query.js +0 -120
  623. package/pg-core/query-builders/_query.js.map +0 -1
  624. package/sqlite-core/query-builders/_query.cjs +0 -187
  625. package/sqlite-core/query-builders/_query.cjs.map +0 -1
  626. package/sqlite-core/query-builders/_query.d.cts +0 -55
  627. package/sqlite-core/query-builders/_query.d.ts +0 -55
  628. package/sqlite-core/query-builders/_query.js +0 -151
  629. package/sqlite-core/query-builders/_query.js.map +0 -1
@@ -1 +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, 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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAE3B,2BAA6B;AAE7B,6BAAsC;AAItC,mBAA4B;AAE5B,IAAAA,gBAAsB;AACtB,mBAA8E;AAuHvE,MAAM,yBASH,kCAEV;AAAA,EAMC,YACS,OACA,SACA,SACR,UACC;AACD,UAAM;AALE;AACA;AACA;AAIR,SAAK,SAAS,EAAE,OAAO,SAAS;AAAA,EACjC;AAAA,EAbA,QAA0B,wBAAU,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,oBAAM,OAAO,OAAO;A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AAA,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":["import_table"]}
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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAE3B,2BAA6B;AAE7B,6BAAsC;AAItC,mBAA4B;AAE5B,IAAAA,gBAAsB;AACtB,mBAA8E;AAuHvE,MAAM,yBASH,kCAEV;AAAA,EAMC,YACS,OACA,SACA,SACR,UACC;AACD,UAAM;AALE;AACA;AACA;AAIR,SAAK,SAAS,EAAE,OAAO,SAAS;AAAA,EACjC;AAAA,EAbA,QAA0B,wBAAU,IAAY;AAAA;AAAA,EAGhD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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A,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":["import_table"]}
@@ -50,7 +50,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
50
50
  private session;
51
51
  private dialect;
52
52
  static readonly [entityKind]: string;
53
- constructor(table: TTable, session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
53
+ constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
54
54
  /**
55
55
  * Adds a `where` clause to the query.
56
56
  *
@@ -50,7 +50,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
50
50
  private session;
51
51
  private dialect;
52
52
  static readonly [entityKind]: string;
53
- constructor(table: TTable, session: SQLiteSession<any, any, any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
53
+ constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
54
54
  /**
55
55
  * Adds a `where` clause to the query.
56
56
  *
@@ -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, 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,sBA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,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>,\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;AAA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A,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 +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, 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;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;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,wBAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,oBAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,QAAI,kBAAG,UAAU,cAAG,IAAI,WAAW,IAAI,iBAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAQD,WAAO,IAAI,iBAAiB,KAAK,OAAO,cAAc,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ;AAAA,EAChG;AAAA,EAQA,OACC,aAIoD;AACpD,UAAM,SAAS,O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AA,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,UAA8C;AAC5D,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>,\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;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,wBAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,oBAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,QAAI,kBAAG,UAAU,cAAG,IAAI,WAAW,IAAI,iBAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA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A,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,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, any, any>;
34
+ protected session: SQLiteSession<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, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
38
+ constructor(table: TTable, session: SQLiteSession<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, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
85
+ constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<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, any, any>;
34
+ protected session: SQLiteSession<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, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
38
+ constructor(table: TTable, session: SQLiteSession<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, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
85
+ constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<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, 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,MAAM,oBAIX;AAAA,EAGD,YACW,OACA,SACA,SACF,UACP;AAJS;AACA;AACA;AACF;AAAA,EACN;AAAA,EAPH,QAAiB,UAAU,IAAY;AAAA,EAWvC,OACC,QACoD;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,MAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,WAAW,IAAI,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAQD,WAAO,IAAI,iBAAiB,KAAK,OAAO,cAAc,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ;AAAA,EAChG;AAAA,EAQA,OACC,aAIoD;AACpD,UAAM,SAAS,OAAO,gBAAgB,aAAa,YAAY,IAAI,aAAa,CAAC,IAAI;AAErF,QACC,CAAC,GAAG,QAAQ,GAAG,KACZ,CAAC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,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,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","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>,\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;AACpD,aAAS,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD,QAAI,OAAO,WAAW,GAAG;AACxB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AACA,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU;AAC1C,YAAM,SAAsC,CAAC;AAC7C,YAAM,OAAO,KAAK,MAAM,MAAM,OAAO,OAAO;AAC5C,iBAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACxC,cAAM,WAAW,MAAM,MAA4B;AACnD,eAAO,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,WAAW,IAAI,MAAM,UAAU,KAAK,MAAM,CAAC;AAAA,MACjF;AACA,aAAO;AAAA,IACR,CAAC;AAQD,WAAO,IAAI,iBAAiB,KAAK,OAAO,cAAc,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ;AAAA,EAChG;AAAA,EAQA,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O,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,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -26,112 +26,105 @@ 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");
30
29
  class RelationalQueryBuilder {
31
- constructor(mode, tables, schema, tableNamesMap, table, tableConfig, dialect, session, rowMode) {
30
+ constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
32
31
  this.mode = mode;
33
- this.tables = tables;
32
+ this.fullSchema = fullSchema;
34
33
  this.schema = schema;
35
34
  this.tableNamesMap = tableNamesMap;
36
35
  this.table = table;
37
36
  this.tableConfig = tableConfig;
38
37
  this.dialect = dialect;
39
38
  this.session = session;
40
- this.rowMode = rowMode;
41
39
  }
42
- static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryBuilderV2";
40
+ static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryBuilder";
43
41
  findMany(config) {
44
42
  return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
45
- this.tables,
43
+ this.fullSchema,
46
44
  this.schema,
47
45
  this.tableNamesMap,
48
46
  this.table,
49
47
  this.tableConfig,
50
48
  this.dialect,
51
49
  this.session,
52
- config ?? true,
53
- "many",
54
- this.rowMode
50
+ config ? config : {},
51
+ "many"
55
52
  ) : new SQLiteRelationalQuery(
56
- this.tables,
53
+ this.fullSchema,
57
54
  this.schema,
58
55
  this.tableNamesMap,
59
56
  this.table,
60
57
  this.tableConfig,
61
58
  this.dialect,
62
59
  this.session,
63
- config ?? true,
64
- "many",
65
- this.rowMode
60
+ config ? config : {},
61
+ "many"
66
62
  );
67
63
  }
68
64
  findFirst(config) {
69
65
  return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
70
- this.tables,
66
+ this.fullSchema,
71
67
  this.schema,
72
68
  this.tableNamesMap,
73
69
  this.table,
74
70
  this.tableConfig,
75
71
  this.dialect,
76
72
  this.session,
77
- config ?? true,
78
- "first",
79
- this.rowMode
73
+ config ? { ...config, limit: 1 } : { limit: 1 },
74
+ "first"
80
75
  ) : new SQLiteRelationalQuery(
81
- this.tables,
76
+ this.fullSchema,
82
77
  this.schema,
83
78
  this.tableNamesMap,
84
79
  this.table,
85
80
  this.tableConfig,
86
81
  this.dialect,
87
82
  this.session,
88
- config ?? true,
89
- "first",
90
- this.rowMode
83
+ config ? { ...config, limit: 1 } : { limit: 1 },
84
+ "first"
91
85
  );
92
86
  }
93
87
  }
94
88
  class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
95
- constructor(tables, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode, rowMode) {
89
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
96
90
  super();
97
- this.tables = tables;
91
+ this.fullSchema = fullSchema;
98
92
  this.schema = schema;
99
93
  this.tableNamesMap = tableNamesMap;
94
+ this.table = table;
100
95
  this.tableConfig = tableConfig;
101
96
  this.dialect = dialect;
102
97
  this.session = session;
103
98
  this.config = config;
104
- this.rowMode = rowMode;
105
99
  this.mode = mode;
106
- this.table = table;
107
100
  }
108
- static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryV2";
101
+ static [import_entity.entityKind] = "SQLiteAsyncRelationalQuery";
109
102
  /** @internal */
110
103
  mode;
111
104
  /** @internal */
112
- table;
113
- /** @internal */
114
105
  getSQL() {
115
- const query = this.dialect.buildRelationalQuery({
106
+ return this.dialect.buildRelationalQuery({
107
+ fullSchema: this.fullSchema,
116
108
  schema: this.schema,
117
109
  tableNamesMap: this.tableNamesMap,
118
110
  table: this.table,
119
111
  tableConfig: this.tableConfig,
120
112
  queryConfig: this.config,
121
- tables: this.tables,
122
- mode: this.mode
123
- });
124
- return query.sql;
113
+ tableAlias: this.tableConfig.tsName
114
+ }).sql;
125
115
  }
126
116
  /** @internal */
127
- _prepare(isOneTimeQuery = true) {
117
+ _prepare(isOneTimeQuery = false) {
128
118
  const { query, builtQuery } = this._toSQL();
129
- return this.session[isOneTimeQuery ? "prepareOneTimeRelationalQuery" : "prepareRelationalQuery"](
119
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
130
120
  builtQuery,
131
121
  void 0,
132
122
  this.mode === "first" ? "get" : "all",
123
+ true,
133
124
  (rawRows, mapColumnValue) => {
134
- const rows = rawRows.map((row) => (0, import_relations.mapRelationalRow)(row, query.selection, mapColumnValue, !this.rowMode));
125
+ const rows = rawRows.map(
126
+ (row) => (0, import_relations.mapRelationalRow)(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
127
+ );
135
128
  if (this.mode === "first") {
136
129
  return rows[0];
137
130
  }
@@ -142,30 +135,16 @@ class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
142
135
  prepare() {
143
136
  return this._prepare(false);
144
137
  }
145
- _getQuery() {
138
+ _toSQL() {
146
139
  const query = this.dialect.buildRelationalQuery({
140
+ fullSchema: this.fullSchema,
147
141
  schema: this.schema,
148
142
  tableNamesMap: this.tableNamesMap,
149
143
  table: this.table,
150
144
  tableConfig: this.tableConfig,
151
145
  queryConfig: this.config,
152
- tables: this.tables,
153
- mode: this.mode,
154
- isNested: this.rowMode
146
+ tableAlias: this.tableConfig.tsName
155
147
  });
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();
169
148
  const builtQuery = this.dialect.sqlToQuery(query.sql);
170
149
  return { query, builtQuery };
171
150
  }
@@ -175,16 +154,16 @@ class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
175
154
  /** @internal */
176
155
  executeRaw() {
177
156
  if (this.mode === "first") {
178
- return this._prepare().get();
157
+ return this._prepare(false).get();
179
158
  }
180
- return this._prepare().all();
159
+ return this._prepare(false).all();
181
160
  }
182
161
  async execute() {
183
162
  return this.executeRaw();
184
163
  }
185
164
  }
186
165
  class SQLiteSyncRelationalQuery extends SQLiteRelationalQuery {
187
- static [import_entity.entityKind] = "SQLiteSyncRelationalQueryV2";
166
+ static [import_entity.entityKind] = "SQLiteSyncRelationalQuery";
188
167
  sync() {
189
168
  return this.executeRaw();
190
169
  }