drizzle-orm 0.38.3-7db411e → 0.38.3-8e428d1

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