drizzle-orm 0.39.2-c7c31ad → 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 -187
  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 -185
  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 +3 -51
  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 -162
  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 -160
  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 -626
  415. package/relations.cjs.map +1 -1
  416. package/relations.d.cts +140 -305
  417. package/relations.d.ts +140 -305
  418. package/relations.js +240 -619
  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 -176
  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 -174
  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
package/relations.js CHANGED
@@ -1,15 +1,7 @@
1
- import {
2
- getTableUniqueName,
3
- IsAlias,
4
- OriginalName,
5
- Schema,
6
- Table
7
- } from "./table.js";
8
- import { Columns } from "./table.js";
9
- import { aliasedTable } from "./alias.js";
1
+ import { getTableUniqueName, Table } from "./table.js";
10
2
  import { Column } from "./column.js";
11
3
  import { entityKind, is } from "./entity.js";
12
- import { DrizzleError } from "./errors.js";
4
+ import { PrimaryKeyBuilder } from "./pg-core/primary-keys.js";
13
5
  import {
14
6
  and,
15
7
  asc,
@@ -35,661 +27,290 @@ import {
35
27
  notLike,
36
28
  or
37
29
  } from "./sql/expressions/index.js";
38
- import { SQL, sql, View } from "./sql/sql.js";
39
- class Relations {
40
- constructor(schema, tables, config) {
41
- this.schema = schema;
42
- this.tables = tables;
43
- this.config = config;
44
- for (const [tsName, table] of Object.entries(tables)) {
45
- if (config[tsName]?.$drizzleTypeError)
46
- continue;
47
- const isTable = is(table, Table);
48
- const isView = is(table, View);
49
- if (!(isTable || isView))
50
- continue;
51
- this.tableNamesMap[getTableUniqueName(table)] = tsName;
52
- this.tablesConfig[tsName] = {
53
- table,
54
- tsName,
55
- dbName: table[Table.Symbol.Name],
56
- schema: table[Table.Symbol.Schema],
57
- columns: table[Table.Symbol.Columns],
58
- relations: config[tsName] || {}
59
- };
60
- }
61
- for (const tableConfig of Object.values(this.tablesConfig)) {
62
- for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
63
- if (!is(relation, Relation)) {
64
- continue;
65
- }
66
- relation.sourceTable = tableConfig.table;
67
- relation.fieldName = relationFieldName;
68
- }
69
- }
70
- for (const tableConfig of Object.values(this.tablesConfig)) {
71
- for (const [relationFieldName, relation] of Object.entries(tableConfig.relations)) {
72
- const relationPrintName = `relations -> ${tableConfig.tsName}.${relationFieldName}`;
73
- if (!is(relation, Relation)) {
74
- continue;
75
- }
76
- if (typeof relation.alias === "string" && !relation.alias) {
77
- throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
78
- }
79
- if (relation.sourceColumns?.length === 0) {
80
- throw new Error(`${relationPrintName}: "from" cannot be an empty array`);
81
- }
82
- if (relation.targetColumns?.length === 0) {
83
- throw new Error(`${relationPrintName}: "to" cannot be an empty array`);
84
- }
85
- if (relation.sourceColumns && relation.targetColumns) {
86
- if (relation.sourceColumns.length !== relation.targetColumns.length) {
87
- throw new Error(
88
- `${relationPrintName}: "from" and "to" fields must have the same length`
89
- );
90
- }
91
- if (relation.through) {
92
- if (relation.through.source.length !== relation.through.target.length || relation.through.source.length !== relation.sourceColumns.length || relation.through.target.length !== relation.targetColumns.length) {
93
- throw new Error(
94
- `${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
95
- );
96
- }
97
- for (const column of relation.through.source) {
98
- if (tables[column._.tableName] !== relation.throughTable) {
99
- throw new Error(
100
- `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
101
- );
102
- }
103
- }
104
- for (const column of relation.through.target) {
105
- if (tables[column._.tableName] !== relation.throughTable) {
106
- throw new Error(
107
- `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
108
- );
109
- }
110
- }
111
- }
112
- continue;
113
- }
114
- if (relation.sourceColumns || relation.targetColumns) {
115
- throw new Error(
116
- `${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
117
- );
118
- }
119
- let reverseRelation;
120
- const targetTableTsName = this.tableNamesMap[getTableUniqueName(relation.targetTable)];
121
- if (!targetTableTsName) {
122
- throw new Error(
123
- `Table "${getTableUniqueName(relation.targetTable)}" not found in provided TS schema`
124
- );
125
- }
126
- const reverseTableConfig = this.tablesConfig[targetTableTsName];
127
- if (!reverseTableConfig) {
128
- throw new Error(
129
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableTsName}" were found"`
130
- );
131
- }
132
- if (relation.alias) {
133
- const reverseRelations = Object.values(reverseTableConfig.relations).filter(
134
- (it) => is(it, Relation) && it.alias === relation.alias
135
- );
136
- if (reverseRelations.length > 1) {
137
- throw new Error(
138
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${relation.alias}" found in table "${targetTableTsName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
139
- );
140
- }
141
- reverseRelation = reverseRelations[0];
142
- if (!reverseRelation) {
143
- throw new Error(
144
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableTsName}" with alias "${relation.alias}"`
145
- );
146
- }
147
- } else {
148
- const reverseRelations = Object.values(reverseTableConfig.relations).filter(
149
- (it) => is(it, Relation) && it.targetTable === relation.sourceTable && !it.alias
150
- );
151
- if (reverseRelations.length > 1) {
152
- throw new Error(
153
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableTsName}" and "${getTableUniqueName(relation.sourceTable)}" were found.
154
- Hint: you can specify "alias" on both sides of the relation with the same value`
155
- );
156
- }
157
- reverseRelation = reverseRelations[0];
158
- if (!reverseRelation) {
159
- throw new Error(
160
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableTsName}" with target table "${getTableUniqueName(relation.sourceTable)}" was found`
161
- );
162
- }
163
- }
164
- if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
165
- throw new Error(
166
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableTsName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
167
- );
168
- }
169
- relation.sourceColumns = reverseRelation.targetColumns;
170
- relation.targetColumns = reverseRelation.sourceColumns;
171
- relation.through = reverseRelation.through ? {
172
- source: reverseRelation.through.target,
173
- target: reverseRelation.through.source
174
- } : void 0;
175
- relation.throughTable = reverseRelation.throughTable;
176
- relation.isReversed = !relation.where;
177
- relation.where = relation.where ?? reverseRelation.where;
178
- }
179
- }
180
- }
181
- static [entityKind] = "RelationsV2";
182
- /** table DB name -> schema table key */
183
- tableNamesMap = {};
184
- tablesConfig = {};
185
- }
30
+ import { SQL, sql } from "./sql/sql.js";
186
31
  class Relation {
187
- constructor(targetTable) {
188
- this.targetTable = targetTable;
32
+ constructor(sourceTable, referencedTable, relationName) {
33
+ this.sourceTable = sourceTable;
34
+ this.referencedTable = referencedTable;
35
+ this.relationName = relationName;
36
+ this.referencedTableName = referencedTable[Table.Symbol.Name];
189
37
  }
190
- static [entityKind] = "RelationV2";
38
+ static [entityKind] = "Relation";
39
+ referencedTableName;
191
40
  fieldName;
192
- sourceColumns;
193
- targetColumns;
194
- alias;
195
- where;
196
- sourceTable;
197
- through;
198
- throughTable;
199
- isReversed;
41
+ }
42
+ class Relations {
43
+ constructor(table, config) {
44
+ this.table = table;
45
+ this.config = config;
46
+ }
47
+ static [entityKind] = "Relations";
200
48
  }
201
49
  class One extends Relation {
202
- static [entityKind] = "OneV2";
203
- optional;
204
- constructor(tables, targetTable, config) {
205
- super(targetTable);
206
- this.alias = config?.alias;
207
- this.where = config?.where;
208
- if (config?.from) {
209
- this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
210
- this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
211
- return it._.column;
212
- });
213
- }
214
- if (config?.to) {
215
- this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
216
- this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
217
- return it._.column;
218
- });
219
- }
220
- if (this.throughTable) {
221
- this.through = Array.isArray(config?.from) ? {
222
- source: config.from.map((c) => c._.through),
223
- target: (config.to ?? []).map((c) => c._.through)
224
- } : {
225
- source: (config?.from ? [config.from] : []).map((c) => c._.through),
226
- target: (config?.to ? [config.to] : []).map((c) => c._.through)
227
- };
228
- }
229
- this.optional = config?.optional ?? true;
50
+ constructor(sourceTable, referencedTable, config, isNullable) {
51
+ super(sourceTable, referencedTable, config?.relationName);
52
+ this.config = config;
53
+ this.isNullable = isNullable;
54
+ }
55
+ static [entityKind] = "One";
56
+ withFieldName(fieldName) {
57
+ const relation = new One(
58
+ this.sourceTable,
59
+ this.referencedTable,
60
+ this.config,
61
+ this.isNullable
62
+ );
63
+ relation.fieldName = fieldName;
64
+ return relation;
230
65
  }
231
66
  }
232
67
  class Many extends Relation {
233
- constructor(tables, targetTable, config) {
234
- super(targetTable);
68
+ constructor(sourceTable, referencedTable, config) {
69
+ super(sourceTable, referencedTable, config?.relationName);
235
70
  this.config = config;
236
- this.alias = config?.alias;
237
- this.where = config?.where;
238
- if (config?.from) {
239
- this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
240
- this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
241
- return it._.column;
242
- });
243
- }
244
- if (config?.to) {
245
- this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
246
- this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
247
- return it._.column;
248
- });
249
- }
250
- if (this.throughTable) {
251
- this.through = Array.isArray(config?.from) ? {
252
- source: config.from.map((c) => c._.through),
253
- target: (config.to ?? []).map((c) => c._.through)
254
- } : {
255
- source: (config?.from ? [config.from] : []).map((c) => c._.through),
256
- target: (config?.to ? [config.to] : []).map((c) => c._.through)
257
- };
258
- }
259
71
  }
260
- static [entityKind] = "ManyV2";
261
- }
262
- class AggregatedField {
263
- static [entityKind] = "AggregatedField";
264
- table;
265
- onTable(table) {
266
- this.table = table;
267
- return this;
72
+ static [entityKind] = "Many";
73
+ withFieldName(fieldName) {
74
+ const relation = new Many(
75
+ this.sourceTable,
76
+ this.referencedTable,
77
+ this.config
78
+ );
79
+ relation.fieldName = fieldName;
80
+ return relation;
268
81
  }
269
82
  }
270
- class Count extends AggregatedField {
271
- static [entityKind] = "AggregatedFieldCount";
272
- query;
273
- getSQL() {
274
- if (!this.query) {
275
- if (!this.table)
276
- throw new Error("Table must be set before building aggregate field");
277
- this.query = sql`select count(*) as ${sql.identifier("r")} from ${getTableAsAliasSQL(this.table)}`.mapWith(Number);
278
- }
279
- return this.query;
280
- }
83
+ function getOperators() {
84
+ return {
85
+ and,
86
+ between,
87
+ eq,
88
+ exists,
89
+ gt,
90
+ gte,
91
+ ilike,
92
+ inArray,
93
+ isNull,
94
+ isNotNull,
95
+ like,
96
+ lt,
97
+ lte,
98
+ ne,
99
+ not,
100
+ notBetween,
101
+ notExists,
102
+ notLike,
103
+ notIlike,
104
+ notInArray,
105
+ or,
106
+ sql
107
+ };
281
108
  }
282
- const operators = {
283
- and,
284
- between,
285
- eq,
286
- exists,
287
- gt,
288
- gte,
289
- ilike,
290
- inArray,
291
- isNull,
292
- isNotNull,
293
- like,
294
- lt,
295
- lte,
296
- ne,
297
- not,
298
- notBetween,
299
- notExists,
300
- notLike,
301
- notIlike,
302
- notInArray,
303
- or,
304
- sql
305
- };
306
- const orderByOperators = {
307
- sql,
308
- asc,
309
- desc
310
- };
311
109
  function getOrderByOperators() {
312
- return orderByOperators;
110
+ return {
111
+ sql,
112
+ asc,
113
+ desc
114
+ };
313
115
  }
314
- function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path) {
315
- for (const selectionItem of buildQueryResultSelection) {
316
- if (selectionItem.selection) {
317
- const currentPath = `${path ? `${path}.` : ""}${selectionItem.key}`;
318
- if (row[selectionItem.key] === null)
319
- continue;
320
- if (parseJson)
321
- row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
322
- if (selectionItem.isArray) {
323
- for (const item of row[selectionItem.key]) {
324
- mapRelationalRow(
325
- item,
326
- selectionItem.selection,
327
- mapColumnValue,
328
- false,
329
- currentPath
330
- );
116
+ function extractTablesRelationalConfig(schema, configHelpers) {
117
+ if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) {
118
+ schema = schema["default"];
119
+ }
120
+ const tableNamesMap = {};
121
+ const relationsBuffer = {};
122
+ const tablesConfig = {};
123
+ for (const [key, value] of Object.entries(schema)) {
124
+ if (is(value, Table)) {
125
+ const dbName = getTableUniqueName(value);
126
+ const bufferedRelations = relationsBuffer[dbName];
127
+ tableNamesMap[dbName] = key;
128
+ tablesConfig[key] = {
129
+ tsName: key,
130
+ dbName: value[Table.Symbol.Name],
131
+ schema: value[Table.Symbol.Schema],
132
+ columns: value[Table.Symbol.Columns],
133
+ relations: bufferedRelations?.relations ?? {},
134
+ primaryKey: bufferedRelations?.primaryKey ?? []
135
+ };
136
+ for (const column of Object.values(
137
+ value[Table.Symbol.Columns]
138
+ )) {
139
+ if (column.primary) {
140
+ tablesConfig[key].primaryKey.push(column);
331
141
  }
332
- continue;
333
142
  }
334
- mapRelationalRow(
335
- row[selectionItem.key],
336
- selectionItem.selection,
337
- mapColumnValue,
338
- false,
339
- currentPath
143
+ const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
144
+ if (extraConfig) {
145
+ for (const configEntry of Object.values(extraConfig)) {
146
+ if (is(configEntry, PrimaryKeyBuilder)) {
147
+ tablesConfig[key].primaryKey.push(...configEntry.columns);
148
+ }
149
+ }
150
+ }
151
+ } else if (is(value, Relations)) {
152
+ const dbName = getTableUniqueName(value.table);
153
+ const tableName = tableNamesMap[dbName];
154
+ const relations2 = value.config(
155
+ configHelpers(value.table)
340
156
  );
341
- continue;
342
- }
343
- const field = selectionItem.field;
344
- const value = mapColumnValue(row[selectionItem.key]);
345
- if (value === null)
346
- continue;
347
- let decoder;
348
- if (is(field, Column)) {
349
- decoder = field;
350
- } else if (is(field, SQL)) {
351
- decoder = field.decoder;
352
- } else if (is(field, SQL.Aliased)) {
353
- decoder = field.sql.decoder;
354
- } else {
355
- decoder = field.getSQL().decoder;
157
+ let primaryKey;
158
+ for (const [relationName, relation] of Object.entries(relations2)) {
159
+ if (tableName) {
160
+ const tableConfig = tablesConfig[tableName];
161
+ tableConfig.relations[relationName] = relation;
162
+ if (primaryKey) {
163
+ tableConfig.primaryKey.push(...primaryKey);
164
+ }
165
+ } else {
166
+ if (!(dbName in relationsBuffer)) {
167
+ relationsBuffer[dbName] = {
168
+ relations: {},
169
+ primaryKey
170
+ };
171
+ }
172
+ relationsBuffer[dbName].relations[relationName] = relation;
173
+ }
174
+ }
356
175
  }
357
- row[selectionItem.key] = decoder.mapFromDriverValue(value);
358
176
  }
359
- return row;
177
+ return { tables: tablesConfig, tableNamesMap };
360
178
  }
361
- class RelationsBuilderTable {
362
- static [entityKind] = "RelationsBuilderTable";
363
- _;
364
- constructor(table, key) {
365
- this._ = {
366
- name: key,
367
- table
368
- };
369
- }
370
- getSQL() {
371
- return this._.table.getSQL();
372
- }
179
+ function relations(table, relations2) {
180
+ return new Relations(
181
+ table,
182
+ (helpers) => Object.fromEntries(
183
+ Object.entries(relations2(helpers)).map(([key, value]) => [
184
+ key,
185
+ value.withFieldName(key)
186
+ ])
187
+ )
188
+ );
189
+ }
190
+ function createOne(sourceTable) {
191
+ return function one(table, config) {
192
+ return new One(
193
+ sourceTable,
194
+ table,
195
+ config,
196
+ config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
197
+ );
198
+ };
199
+ }
200
+ function createMany(sourceTable) {
201
+ return function many(referencedTable, config) {
202
+ return new Many(sourceTable, referencedTable, config);
203
+ };
373
204
  }
374
- class RelationsBuilderColumn {
375
- static [entityKind] = "RelationsBuilderColumn";
376
- _;
377
- constructor(column, tableName, key, through) {
378
- this._ = {
379
- tableName,
380
- data: void 0,
381
- column,
382
- through,
383
- key
205
+ function normalizeRelation(schema, tableNamesMap, relation) {
206
+ if (is(relation, One) && relation.config) {
207
+ return {
208
+ fields: relation.config.fields,
209
+ references: relation.config.references
384
210
  };
385
211
  }
386
- through(column) {
387
- return new RelationsBuilderColumn(
388
- this._.column,
389
- this._.tableName,
390
- this._.key,
391
- column
212
+ const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
213
+ if (!referencedTableTsName) {
214
+ throw new Error(
215
+ `Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`
392
216
  );
393
217
  }
394
- getSQL() {
395
- return this._.column.getSQL();
218
+ const referencedTableConfig = schema[referencedTableTsName];
219
+ if (!referencedTableConfig) {
220
+ throw new Error(`Table "${referencedTableTsName}" not found in schema`);
396
221
  }
397
- }
398
- class RelationsHelperStatic {
399
- static [entityKind] = "RelationsHelperStatic";
400
- _;
401
- constructor(tables) {
402
- this._ = {
403
- tables
404
- };
405
- const one = {};
406
- const many = {};
407
- for (const [tableName, table] of Object.entries(tables)) {
408
- one[tableName] = (config) => {
409
- return new One(tables, table, config);
410
- };
411
- many[tableName] = (config) => {
412
- return new Many(tables, table, config);
413
- };
414
- }
415
- this.one = one;
416
- this.many = many;
222
+ const sourceTable = relation.sourceTable;
223
+ const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
224
+ if (!sourceTableTsName) {
225
+ throw new Error(
226
+ `Table "${sourceTable[Table.Symbol.Name]}" not found in schema`
227
+ );
417
228
  }
418
- one;
419
- many;
420
- /** @internal - to be reworked */
421
- aggs = {
422
- count() {
423
- return new Count();
424
- }
425
- };
426
- }
427
- function createRelationsHelper(schema) {
428
- const schemaTables = Object.fromEntries(
429
- Object.entries(schema).filter((e) => is(e[1], Table) || is(e[1], View))
430
- );
431
- const helperStatic = new RelationsHelperStatic(schemaTables);
432
- const tables = Object.entries(schema).reduce((acc, [tKey, value]) => {
433
- if (is(value, Table) || is(value, View)) {
434
- const rTable = new RelationsBuilderTable(value, tKey);
435
- const columns = Object.entries(value[Columns]).reduce(
436
- (acc2, [cKey, column]) => {
437
- const rbColumn = new RelationsBuilderColumn(column, tKey, cKey);
438
- acc2[cKey] = rbColumn;
439
- return acc2;
440
- },
441
- {}
442
- );
443
- acc[tKey] = Object.assign(rTable, columns);
444
- }
445
- return acc;
446
- }, {});
447
- return Object.assign(helperStatic, tables);
448
- }
449
- function defineRelations(schema, relations) {
450
- return new Relations(
451
- schema,
452
- schema,
453
- relations(createRelationsHelper(schema))
454
- );
455
- }
456
- function fieldSelectionToSQL(table, target) {
457
- const field = table[Columns][target];
458
- return field ? is(field, Column) ? field : is(field, SQL.Aliased) ? sql`${table}.${sql.identifier(field.fieldAlias)}` : sql`${table}.${sql.identifier(target)}` : sql`${table}.${sql.identifier(target)}`;
459
- }
460
- function relationsFieldFilterToSQL(column, filter) {
461
- if (typeof filter !== "object")
462
- return eq(column, filter);
463
- const entries = Object.entries(filter);
464
- if (!entries.length)
465
- return void 0;
466
- const parts = [];
467
- for (const [target, value] of entries) {
468
- if (value === void 0)
469
- continue;
470
- switch (target) {
471
- case "NOT": {
472
- const res = relationsFieldFilterToSQL(column, value);
473
- if (!res)
474
- continue;
475
- parts.push(not(res));
476
- continue;
477
- }
478
- case "OR": {
479
- if (!value.length)
480
- continue;
481
- parts.push(
482
- or(
483
- ...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))
484
- )
485
- );
486
- continue;
487
- }
488
- case "isNotNull":
489
- case "isNull": {
490
- if (!value)
491
- continue;
492
- parts.push(operators[target](column));
493
- continue;
494
- }
495
- case "in": {
496
- parts.push(operators.inArray(column, value));
497
- continue;
498
- }
499
- case "notIn": {
500
- parts.push(operators.notInArray(column, value));
501
- continue;
502
- }
503
- default: {
504
- parts.push(
505
- operators[target](
506
- column,
507
- value
508
- )
509
- );
510
- continue;
511
- }
229
+ const reverseRelations = [];
230
+ for (const referencedTableRelation of Object.values(
231
+ referencedTableConfig.relations
232
+ )) {
233
+ if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
234
+ reverseRelations.push(referencedTableRelation);
512
235
  }
513
236
  }
514
- if (!parts.length)
515
- return void 0;
516
- return and(...parts);
517
- }
518
- function relationsFilterToSQL(table, filter, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, depth = 0) {
519
- const entries = Object.entries(filter);
520
- if (!entries.length)
521
- return void 0;
522
- const parts = [];
523
- for (const [target, value] of entries) {
524
- if (value === void 0)
525
- continue;
526
- switch (target) {
527
- case "RAW": {
528
- if (value) {
529
- parts.push(
530
- value(table, operators)
531
- );
532
- }
533
- continue;
534
- }
535
- case "OR": {
536
- if (!value?.length)
537
- continue;
538
- parts.push(
539
- or(
540
- ...value.map((subFilter) => relationsFilterToSQL(table, subFilter))
541
- )
542
- );
543
- continue;
544
- }
545
- case "NOT": {
546
- if (value === void 0)
547
- continue;
548
- const built = relationsFilterToSQL(table, value);
549
- if (!built)
550
- continue;
551
- parts.push(not(built));
552
- continue;
553
- }
554
- default: {
555
- if (table[Columns][target]) {
556
- const column = fieldSelectionToSQL(table, target);
557
- const colFilter = relationsFieldFilterToSQL(
558
- column,
559
- value
560
- );
561
- if (colFilter)
562
- parts.push(colFilter);
563
- continue;
564
- }
565
- const relation = tableRelations[target];
566
- if (!relation) {
567
- throw new DrizzleError({
568
- message: `Unknown relational filter field: "${target}"`
569
- });
570
- }
571
- const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
572
- const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
573
- const targetConfig = tablesRelations[tableNamesMap[getTableUniqueName(relation.targetTable)]];
574
- const {
575
- filter: relationFilter,
576
- joinCondition
577
- } = relationToSQL(relation, table, targetTable, throughTable);
578
- const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
579
- targetTable,
580
- value,
581
- targetConfig.relations,
582
- tablesRelations,
583
- tableNamesMap,
584
- depth + 1
585
- );
586
- const filter2 = and(
587
- relationFilter,
588
- subfilter
589
- );
590
- const subquery = throughTable ? sql`(select * from ${getTableAsAliasSQL(targetTable)} inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}${sql` where ${filter2}`.if(filter2)} limit 1)` : sql`(select * from ${getTableAsAliasSQL(targetTable)}${sql` where ${filter2}`.if(filter2)} limit 1)`;
591
- if (filter2)
592
- parts.push((value ? exists : notExists)(subquery));
593
- }
594
- }
237
+ if (reverseRelations.length > 1) {
238
+ throw relation.relationName ? new Error(
239
+ `There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`
240
+ ) : new Error(
241
+ `There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`
242
+ );
595
243
  }
596
- return and(...parts);
597
- }
598
- function relationsOrderToSQL(table, orders) {
599
- if (typeof orders === "function") {
600
- const data = orders(table, orderByOperators);
601
- return is(data, SQL) ? data : Array.isArray(data) ? data.length ? sql.join(data.map((o) => is(o, SQL) ? o : asc(o)), sql`, `) : void 0 : is(data, Column) ? asc(data) : void 0;
244
+ if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
245
+ return {
246
+ fields: reverseRelations[0].config.references,
247
+ references: reverseRelations[0].config.fields
248
+ };
602
249
  }
603
- const entries = Object.entries(orders).filter(([_, value]) => value);
604
- if (!entries.length)
605
- return void 0;
606
- return sql.join(
607
- entries.map(([target, value]) => (value === "asc" ? asc : desc)(fieldSelectionToSQL(table, target))),
608
- sql`, `
250
+ throw new Error(
251
+ `There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`
609
252
  );
610
253
  }
611
- function relationExtrasToSQL(table, extras) {
612
- const subqueries = [];
613
- const selection = [];
614
- for (const [key, extra] of Object.entries(
615
- typeof extras === "function" ? extras(table, { sql: operators.sql }) : extras
616
- )) {
617
- if (!extra)
618
- continue;
619
- const query = sql`(${extra.getSQL()}) as ${sql.identifier(key)}`;
620
- query.decoder = extra.getSQL().decoder;
621
- subqueries.push(query);
622
- selection.push({
623
- key,
624
- field: query
625
- });
626
- }
254
+ function createTableRelationsHelpers(sourceTable) {
627
255
  return {
628
- sql: subqueries.length ? sql.join(subqueries, sql`, `) : void 0,
629
- selection
256
+ one: createOne(sourceTable),
257
+ many: createMany(sourceTable)
630
258
  };
631
259
  }
632
- function relationToSQL(relation, sourceTable, targetTable, throughTable) {
633
- if (relation.through) {
634
- const outerColumnWhere = relation.sourceColumns.map((s, i) => {
635
- const t = relation.through.source[i];
636
- return eq(
637
- sql`${sourceTable}.${sql.identifier(s.name)}`,
638
- sql`${throughTable}.${sql.identifier(is(t._.column, Column) ? t._.column.name : t._.key)}`
639
- );
640
- });
641
- const innerColumnWhere = relation.targetColumns.map((s, i) => {
642
- const t = relation.through.target[i];
643
- return eq(
644
- sql`${throughTable}.${sql.identifier(is(t._.column, Column) ? t._.column.name : t._.key)}`,
645
- sql`${targetTable}.${sql.identifier(s.name)}`
260
+ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
261
+ const result = {};
262
+ for (const [
263
+ selectionItemIndex,
264
+ selectionItem
265
+ ] of buildQueryResultSelection.entries()) {
266
+ if (selectionItem.isJson) {
267
+ const relation = tableConfig.relations[selectionItem.tsKey];
268
+ const rawSubRows = row[selectionItemIndex];
269
+ const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
270
+ result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(
271
+ tablesConfig,
272
+ tablesConfig[selectionItem.relationTableTsKey],
273
+ subRows,
274
+ selectionItem.selection,
275
+ mapColumnValue
276
+ ) : subRows.map(
277
+ (subRow) => mapRelationalRow(
278
+ tablesConfig,
279
+ tablesConfig[selectionItem.relationTableTsKey],
280
+ subRow,
281
+ selectionItem.selection,
282
+ mapColumnValue
283
+ )
646
284
  );
647
- });
648
- return {
649
- filter: and(
650
- relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0,
651
- ...outerColumnWhere
652
- ),
653
- joinCondition: and(...innerColumnWhere)
654
- };
285
+ } else {
286
+ const value = mapColumnValue(row[selectionItemIndex]);
287
+ const field = selectionItem.field;
288
+ let decoder;
289
+ if (is(field, Column)) {
290
+ decoder = field;
291
+ } else if (is(field, SQL)) {
292
+ decoder = field.decoder;
293
+ } else {
294
+ decoder = field.sql.decoder;
295
+ }
296
+ result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
297
+ }
655
298
  }
656
- const columnWhere = relation.sourceColumns.map((s, i) => {
657
- const t = relation.targetColumns[i];
658
- return eq(
659
- sql`${sourceTable}.${sql.identifier(s.name)}`,
660
- sql`${targetTable}.${sql.identifier(t.name)}`
661
- );
662
- });
663
- const fullWhere = and(
664
- ...columnWhere,
665
- relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0
666
- );
667
- return { filter: fullWhere };
668
- }
669
- function getTableAsAliasSQL(table) {
670
- return sql`${table[IsAlias] ? sql`${sql`${sql.identifier(table[Schema] ?? "")}.`.if(table[Schema])}${sql.identifier(table[OriginalName])} as ${table}` : table}`;
299
+ return result;
671
300
  }
672
301
  export {
673
- AggregatedField,
674
- Count,
675
302
  Many,
676
303
  One,
677
304
  Relation,
678
305
  Relations,
679
- RelationsBuilderColumn,
680
- RelationsBuilderTable,
681
- RelationsHelperStatic,
682
- createRelationsHelper,
683
- defineRelations,
684
- fieldSelectionToSQL,
306
+ createMany,
307
+ createOne,
308
+ createTableRelationsHelpers,
309
+ extractTablesRelationalConfig,
310
+ getOperators,
685
311
  getOrderByOperators,
686
- getTableAsAliasSQL,
687
312
  mapRelationalRow,
688
- operators,
689
- orderByOperators,
690
- relationExtrasToSQL,
691
- relationToSQL,
692
- relationsFilterToSQL,
693
- relationsOrderToSQL
313
+ normalizeRelation,
314
+ relations
694
315
  };
695
316
  //# sourceMappingURL=relations.js.map