drizzle-orm 1.0.0-beta.21 → 1.0.0-beta.21-4fa69ab

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 (1591) hide show
  1. package/_relations.cjs.map +1 -1
  2. package/_relations.d.cts +2 -13
  3. package/_relations.d.ts +2 -13
  4. package/_relations.js.map +1 -1
  5. package/aws-data-api/common/index.cjs +2 -0
  6. package/aws-data-api/common/index.cjs.map +1 -1
  7. package/aws-data-api/common/index.js +2 -0
  8. package/aws-data-api/common/index.js.map +1 -1
  9. package/aws-data-api/pg/driver.cjs +93 -20
  10. package/aws-data-api/pg/driver.cjs.map +1 -1
  11. package/aws-data-api/pg/driver.d.cts +17 -13
  12. package/aws-data-api/pg/driver.d.ts +16 -12
  13. package/aws-data-api/pg/driver.js +93 -20
  14. package/aws-data-api/pg/driver.js.map +1 -1
  15. package/aws-data-api/pg/index.cjs +1 -1
  16. package/aws-data-api/pg/index.d.cts +3 -3
  17. package/aws-data-api/pg/index.d.ts +3 -3
  18. package/aws-data-api/pg/index.js +3 -3
  19. package/aws-data-api/pg/migrator.cjs.map +1 -1
  20. package/aws-data-api/pg/migrator.d.cts +1 -1
  21. package/aws-data-api/pg/migrator.d.ts +1 -1
  22. package/aws-data-api/pg/migrator.js.map +1 -1
  23. package/aws-data-api/pg/session.cjs +44 -113
  24. package/aws-data-api/pg/session.cjs.map +1 -1
  25. package/aws-data-api/pg/session.d.cts +12 -42
  26. package/aws-data-api/pg/session.d.ts +12 -42
  27. package/aws-data-api/pg/session.js +46 -114
  28. package/aws-data-api/pg/session.js.map +1 -1
  29. package/better-sqlite3/driver.cjs +5 -2
  30. package/better-sqlite3/driver.cjs.map +1 -1
  31. package/better-sqlite3/driver.d.ts +1 -1
  32. package/better-sqlite3/driver.js +5 -2
  33. package/better-sqlite3/driver.js.map +1 -1
  34. package/better-sqlite3/session.cjs +15 -14
  35. package/better-sqlite3/session.cjs.map +1 -1
  36. package/better-sqlite3/session.d.cts +10 -6
  37. package/better-sqlite3/session.d.ts +10 -6
  38. package/better-sqlite3/session.js +16 -15
  39. package/better-sqlite3/session.js.map +1 -1
  40. package/bun-sql/driver.cjs.map +1 -1
  41. package/bun-sql/driver.d.cts +7 -6
  42. package/bun-sql/driver.d.ts +7 -6
  43. package/bun-sql/driver.js.map +1 -1
  44. package/bun-sql/index.cjs +0 -1
  45. package/bun-sql/index.d.cts +2 -2
  46. package/bun-sql/index.d.ts +2 -2
  47. package/bun-sql/index.js +2 -2
  48. package/bun-sql/migrator.cjs.map +1 -1
  49. package/bun-sql/migrator.d.cts +2 -2
  50. package/bun-sql/migrator.d.ts +2 -2
  51. package/bun-sql/migrator.js.map +1 -1
  52. package/bun-sql/mysql/driver.cjs +4 -3
  53. package/bun-sql/mysql/driver.cjs.map +1 -1
  54. package/bun-sql/mysql/driver.js +3 -2
  55. package/bun-sql/mysql/driver.js.map +1 -1
  56. package/bun-sql/mysql/session.cjs +36 -23
  57. package/bun-sql/mysql/session.cjs.map +1 -1
  58. package/bun-sql/mysql/session.d.cts +10 -4
  59. package/bun-sql/mysql/session.d.ts +11 -5
  60. package/bun-sql/mysql/session.js +37 -24
  61. package/bun-sql/mysql/session.js.map +1 -1
  62. package/bun-sql/postgres/driver.cjs +143 -19
  63. package/bun-sql/postgres/driver.cjs.map +1 -1
  64. package/bun-sql/postgres/driver.d.cts +10 -6
  65. package/bun-sql/postgres/driver.d.ts +10 -6
  66. package/bun-sql/postgres/driver.js +143 -19
  67. package/bun-sql/postgres/driver.js.map +1 -1
  68. package/bun-sql/postgres/index.cjs +1 -1
  69. package/bun-sql/postgres/index.d.cts +3 -3
  70. package/bun-sql/postgres/index.d.ts +3 -3
  71. package/bun-sql/postgres/index.js +3 -3
  72. package/bun-sql/postgres/migrator.cjs.map +1 -1
  73. package/bun-sql/postgres/migrator.d.cts +1 -1
  74. package/bun-sql/postgres/migrator.d.ts +1 -1
  75. package/bun-sql/postgres/migrator.js.map +1 -1
  76. package/bun-sql/postgres/session.cjs +16 -111
  77. package/bun-sql/postgres/session.cjs.map +1 -1
  78. package/bun-sql/postgres/session.d.cts +11 -33
  79. package/bun-sql/postgres/session.d.ts +10 -32
  80. package/bun-sql/postgres/session.js +17 -111
  81. package/bun-sql/postgres/session.js.map +1 -1
  82. package/bun-sql/session.cjs +0 -1
  83. package/bun-sql/session.d.cts +2 -2
  84. package/bun-sql/session.d.ts +2 -2
  85. package/bun-sql/session.js +2 -2
  86. package/bun-sql/sqlite/driver.cjs +4 -3
  87. package/bun-sql/sqlite/driver.cjs.map +1 -1
  88. package/bun-sql/sqlite/driver.d.ts +1 -1
  89. package/bun-sql/sqlite/driver.js +3 -2
  90. package/bun-sql/sqlite/driver.js.map +1 -1
  91. package/bun-sql/sqlite/session.cjs +17 -16
  92. package/bun-sql/sqlite/session.cjs.map +1 -1
  93. package/bun-sql/sqlite/session.d.cts +9 -6
  94. package/bun-sql/sqlite/session.d.ts +9 -6
  95. package/bun-sql/sqlite/session.js +18 -17
  96. package/bun-sql/sqlite/session.js.map +1 -1
  97. package/bun-sqlite/driver.cjs +5 -2
  98. package/bun-sqlite/driver.cjs.map +1 -1
  99. package/bun-sqlite/driver.d.ts +1 -1
  100. package/bun-sqlite/driver.js +5 -2
  101. package/bun-sqlite/driver.js.map +1 -1
  102. package/bun-sqlite/session.cjs +15 -14
  103. package/bun-sqlite/session.cjs.map +1 -1
  104. package/bun-sqlite/session.d.cts +10 -6
  105. package/bun-sqlite/session.d.ts +10 -6
  106. package/bun-sqlite/session.js +16 -15
  107. package/bun-sqlite/session.js.map +1 -1
  108. package/cache/core/cache-effect.d.cts +1 -1
  109. package/cache/core/cache-effect.d.ts +1 -1
  110. package/cache/upstash/cache.d.cts +1 -1
  111. package/cache/upstash/cache.d.ts +1 -1
  112. package/cockroach/driver.cjs +9 -3
  113. package/cockroach/driver.cjs.map +1 -1
  114. package/cockroach/driver.d.cts +1 -0
  115. package/cockroach/driver.d.ts +2 -1
  116. package/cockroach/driver.js +9 -3
  117. package/cockroach/driver.js.map +1 -1
  118. package/cockroach/session.cjs +7 -9
  119. package/cockroach/session.cjs.map +1 -1
  120. package/cockroach/session.d.cts +5 -3
  121. package/cockroach/session.d.ts +6 -4
  122. package/cockroach/session.js +8 -10
  123. package/cockroach/session.js.map +1 -1
  124. package/cockroach-core/columns/bigint.cjs +4 -4
  125. package/cockroach-core/columns/bigint.cjs.map +1 -1
  126. package/cockroach-core/columns/bigint.d.cts +2 -2
  127. package/cockroach-core/columns/bigint.d.ts +2 -2
  128. package/cockroach-core/columns/bigint.js +4 -4
  129. package/cockroach-core/columns/bigint.js.map +1 -1
  130. package/cockroach-core/columns/common.cjs +4 -4
  131. package/cockroach-core/columns/common.cjs.map +1 -1
  132. package/cockroach-core/columns/common.d.cts +2 -2
  133. package/cockroach-core/columns/common.d.ts +2 -2
  134. package/cockroach-core/columns/common.js +4 -4
  135. package/cockroach-core/columns/common.js.map +1 -1
  136. package/cockroach-core/columns/custom.cjs +4 -4
  137. package/cockroach-core/columns/custom.cjs.map +1 -1
  138. package/cockroach-core/columns/custom.d.cts +2 -2
  139. package/cockroach-core/columns/custom.d.ts +2 -2
  140. package/cockroach-core/columns/custom.js +4 -4
  141. package/cockroach-core/columns/custom.js.map +1 -1
  142. package/cockroach-core/columns/date.cjs +6 -6
  143. package/cockroach-core/columns/date.cjs.map +1 -1
  144. package/cockroach-core/columns/date.d.cts +3 -3
  145. package/cockroach-core/columns/date.d.ts +3 -3
  146. package/cockroach-core/columns/date.js +6 -6
  147. package/cockroach-core/columns/date.js.map +1 -1
  148. package/cockroach-core/columns/decimal.cjs +4 -4
  149. package/cockroach-core/columns/decimal.cjs.map +1 -1
  150. package/cockroach-core/columns/decimal.d.cts +2 -2
  151. package/cockroach-core/columns/decimal.d.ts +2 -2
  152. package/cockroach-core/columns/decimal.js +4 -4
  153. package/cockroach-core/columns/decimal.js.map +1 -1
  154. package/cockroach-core/columns/float.cjs +2 -2
  155. package/cockroach-core/columns/float.cjs.map +1 -1
  156. package/cockroach-core/columns/float.d.cts +1 -1
  157. package/cockroach-core/columns/float.d.ts +1 -1
  158. package/cockroach-core/columns/float.js +2 -2
  159. package/cockroach-core/columns/float.js.map +1 -1
  160. package/cockroach-core/columns/geometry.cjs +8 -8
  161. package/cockroach-core/columns/geometry.cjs.map +1 -1
  162. package/cockroach-core/columns/geometry.d.cts +5 -5
  163. package/cockroach-core/columns/geometry.d.ts +5 -5
  164. package/cockroach-core/columns/geometry.js +8 -8
  165. package/cockroach-core/columns/geometry.js.map +1 -1
  166. package/cockroach-core/columns/integer.cjs +2 -2
  167. package/cockroach-core/columns/integer.cjs.map +1 -1
  168. package/cockroach-core/columns/integer.d.cts +1 -1
  169. package/cockroach-core/columns/integer.d.ts +1 -1
  170. package/cockroach-core/columns/integer.js +2 -2
  171. package/cockroach-core/columns/integer.js.map +1 -1
  172. package/cockroach-core/columns/jsonb.cjs +4 -4
  173. package/cockroach-core/columns/jsonb.cjs.map +1 -1
  174. package/cockroach-core/columns/jsonb.d.cts +2 -2
  175. package/cockroach-core/columns/jsonb.d.ts +2 -2
  176. package/cockroach-core/columns/jsonb.js +4 -4
  177. package/cockroach-core/columns/jsonb.js.map +1 -1
  178. package/cockroach-core/columns/vector.cjs +4 -4
  179. package/cockroach-core/columns/vector.cjs.map +1 -1
  180. package/cockroach-core/columns/vector.d.cts +2 -2
  181. package/cockroach-core/columns/vector.d.ts +2 -2
  182. package/cockroach-core/columns/vector.js +4 -4
  183. package/cockroach-core/columns/vector.js.map +1 -1
  184. package/cockroach-core/db.cjs +1 -1
  185. package/cockroach-core/db.cjs.map +1 -1
  186. package/cockroach-core/db.js +1 -1
  187. package/cockroach-core/db.js.map +1 -1
  188. package/cockroach-core/dialect.cjs +1 -1
  189. package/cockroach-core/dialect.d.ts +1 -1
  190. package/cockroach-core/dialect.js +1 -1
  191. package/cockroach-core/query-builders/delete.cjs +6 -2
  192. package/cockroach-core/query-builders/delete.cjs.map +1 -1
  193. package/cockroach-core/query-builders/delete.d.cts +1 -1
  194. package/cockroach-core/query-builders/delete.d.ts +1 -1
  195. package/cockroach-core/query-builders/delete.js +6 -2
  196. package/cockroach-core/query-builders/delete.js.map +1 -1
  197. package/cockroach-core/query-builders/insert.cjs +6 -2
  198. package/cockroach-core/query-builders/insert.cjs.map +1 -1
  199. package/cockroach-core/query-builders/insert.js +6 -2
  200. package/cockroach-core/query-builders/insert.js.map +1 -1
  201. package/cockroach-core/query-builders/query.cjs +2 -2
  202. package/cockroach-core/query-builders/query.cjs.map +1 -1
  203. package/cockroach-core/query-builders/query.js +2 -2
  204. package/cockroach-core/query-builders/query.js.map +1 -1
  205. package/cockroach-core/query-builders/raw.cjs +0 -4
  206. package/cockroach-core/query-builders/raw.cjs.map +1 -1
  207. package/cockroach-core/query-builders/raw.js +0 -4
  208. package/cockroach-core/query-builders/raw.js.map +1 -1
  209. package/cockroach-core/query-builders/refresh-materialized-view.cjs +2 -2
  210. package/cockroach-core/query-builders/refresh-materialized-view.cjs.map +1 -1
  211. package/cockroach-core/query-builders/refresh-materialized-view.js +2 -2
  212. package/cockroach-core/query-builders/refresh-materialized-view.js.map +1 -1
  213. package/cockroach-core/query-builders/select.cjs +6 -2
  214. package/cockroach-core/query-builders/select.cjs.map +1 -1
  215. package/cockroach-core/query-builders/select.js +6 -2
  216. package/cockroach-core/query-builders/select.js.map +1 -1
  217. package/cockroach-core/query-builders/update.cjs +6 -2
  218. package/cockroach-core/query-builders/update.cjs.map +1 -1
  219. package/cockroach-core/query-builders/update.js +6 -2
  220. package/cockroach-core/query-builders/update.js.map +1 -1
  221. package/cockroach-core/session.cjs +2 -2
  222. package/cockroach-core/session.cjs.map +1 -1
  223. package/cockroach-core/session.d.cts +1 -1
  224. package/cockroach-core/session.d.ts +1 -1
  225. package/cockroach-core/session.js +2 -2
  226. package/cockroach-core/session.js.map +1 -1
  227. package/cockroach-core/table.cjs +1 -1
  228. package/cockroach-core/table.cjs.map +1 -1
  229. package/cockroach-core/table.js +1 -1
  230. package/cockroach-core/table.js.map +1 -1
  231. package/codecs.cjs +77 -0
  232. package/codecs.cjs.map +1 -0
  233. package/codecs.d.cts +68 -0
  234. package/codecs.d.ts +68 -0
  235. package/codecs.js +74 -0
  236. package/codecs.js.map +1 -0
  237. package/column.cjs +10 -5
  238. package/column.cjs.map +1 -1
  239. package/column.d.cts +3 -3
  240. package/column.d.ts +3 -3
  241. package/column.js +10 -5
  242. package/column.js.map +1 -1
  243. package/d1/driver.cjs +3 -2
  244. package/d1/driver.cjs.map +1 -1
  245. package/d1/driver.d.ts +1 -1
  246. package/d1/driver.js +3 -2
  247. package/d1/driver.js.map +1 -1
  248. package/d1/session.cjs +16 -14
  249. package/d1/session.cjs.map +1 -1
  250. package/d1/session.d.cts +9 -6
  251. package/d1/session.d.ts +9 -6
  252. package/d1/session.js +17 -15
  253. package/d1/session.js.map +1 -1
  254. package/durable-sqlite/driver.cjs +5 -2
  255. package/durable-sqlite/driver.cjs.map +1 -1
  256. package/durable-sqlite/driver.d.ts +1 -1
  257. package/durable-sqlite/driver.js +5 -2
  258. package/durable-sqlite/driver.js.map +1 -1
  259. package/durable-sqlite/session.cjs +15 -14
  260. package/durable-sqlite/session.cjs.map +1 -1
  261. package/durable-sqlite/session.d.cts +10 -6
  262. package/durable-sqlite/session.d.ts +10 -6
  263. package/durable-sqlite/session.js +16 -15
  264. package/durable-sqlite/session.js.map +1 -1
  265. package/effect-postgres/driver.cjs +99 -13
  266. package/effect-postgres/driver.cjs.map +1 -1
  267. package/effect-postgres/driver.d.cts +12 -8
  268. package/effect-postgres/driver.d.ts +12 -8
  269. package/effect-postgres/driver.js +99 -13
  270. package/effect-postgres/driver.js.map +1 -1
  271. package/effect-postgres/index.cjs +1 -1
  272. package/effect-postgres/index.d.cts +3 -3
  273. package/effect-postgres/index.d.ts +3 -3
  274. package/effect-postgres/index.js +3 -3
  275. package/effect-postgres/migrator.cjs.map +1 -1
  276. package/effect-postgres/migrator.d.cts +1 -1
  277. package/effect-postgres/migrator.d.ts +1 -1
  278. package/effect-postgres/migrator.js.map +1 -1
  279. package/effect-postgres/session.cjs +12 -71
  280. package/effect-postgres/session.cjs.map +1 -1
  281. package/effect-postgres/session.d.cts +14 -31
  282. package/effect-postgres/session.d.ts +16 -33
  283. package/effect-postgres/session.js +13 -71
  284. package/effect-postgres/session.js.map +1 -1
  285. package/expo-sqlite/driver.cjs +5 -2
  286. package/expo-sqlite/driver.cjs.map +1 -1
  287. package/expo-sqlite/driver.d.ts +1 -1
  288. package/expo-sqlite/driver.js +5 -2
  289. package/expo-sqlite/driver.js.map +1 -1
  290. package/expo-sqlite/session.cjs +15 -14
  291. package/expo-sqlite/session.cjs.map +1 -1
  292. package/expo-sqlite/session.d.cts +10 -6
  293. package/expo-sqlite/session.d.ts +10 -6
  294. package/expo-sqlite/session.js +16 -15
  295. package/expo-sqlite/session.js.map +1 -1
  296. package/gel/driver.cjs +4 -2
  297. package/gel/driver.cjs.map +1 -1
  298. package/gel/driver.d.cts +1 -0
  299. package/gel/driver.d.ts +2 -1
  300. package/gel/driver.js +4 -2
  301. package/gel/driver.js.map +1 -1
  302. package/gel/session.cjs +12 -12
  303. package/gel/session.cjs.map +1 -1
  304. package/gel/session.d.cts +8 -5
  305. package/gel/session.d.ts +9 -6
  306. package/gel/session.js +13 -13
  307. package/gel/session.js.map +1 -1
  308. package/gel-core/columns/bigintT.cjs +2 -2
  309. package/gel-core/columns/bigintT.cjs.map +1 -1
  310. package/gel-core/columns/bigintT.d.cts +1 -1
  311. package/gel-core/columns/bigintT.d.ts +1 -1
  312. package/gel-core/columns/bigintT.js +2 -2
  313. package/gel-core/columns/bigintT.js.map +1 -1
  314. package/gel-core/columns/common.cjs +2 -2
  315. package/gel-core/columns/common.cjs.map +1 -1
  316. package/gel-core/columns/common.d.cts +1 -1
  317. package/gel-core/columns/common.d.ts +1 -1
  318. package/gel-core/columns/common.js +2 -2
  319. package/gel-core/columns/common.js.map +1 -1
  320. package/gel-core/columns/custom.cjs +4 -4
  321. package/gel-core/columns/custom.cjs.map +1 -1
  322. package/gel-core/columns/custom.d.cts +2 -2
  323. package/gel-core/columns/custom.d.ts +2 -2
  324. package/gel-core/columns/custom.js +4 -4
  325. package/gel-core/columns/custom.js.map +1 -1
  326. package/gel-core/columns/double-precision.cjs +2 -2
  327. package/gel-core/columns/double-precision.cjs.map +1 -1
  328. package/gel-core/columns/double-precision.d.cts +1 -1
  329. package/gel-core/columns/double-precision.d.ts +1 -1
  330. package/gel-core/columns/double-precision.js +2 -2
  331. package/gel-core/columns/double-precision.js.map +1 -1
  332. package/gel-core/columns/timestamptz.cjs +2 -2
  333. package/gel-core/columns/timestamptz.cjs.map +1 -1
  334. package/gel-core/columns/timestamptz.d.cts +1 -1
  335. package/gel-core/columns/timestamptz.d.ts +1 -1
  336. package/gel-core/columns/timestamptz.js +2 -2
  337. package/gel-core/columns/timestamptz.js.map +1 -1
  338. package/gel-core/db.cjs +1 -1
  339. package/gel-core/db.cjs.map +1 -1
  340. package/gel-core/db.d.ts +1 -1
  341. package/gel-core/db.js +1 -1
  342. package/gel-core/db.js.map +1 -1
  343. package/gel-core/query-builders/_query.cjs +2 -2
  344. package/gel-core/query-builders/_query.cjs.map +1 -1
  345. package/gel-core/query-builders/_query.js +2 -2
  346. package/gel-core/query-builders/_query.js.map +1 -1
  347. package/gel-core/query-builders/delete.cjs +2 -2
  348. package/gel-core/query-builders/delete.cjs.map +1 -1
  349. package/gel-core/query-builders/delete.js +2 -2
  350. package/gel-core/query-builders/delete.js.map +1 -1
  351. package/gel-core/query-builders/insert.cjs +2 -2
  352. package/gel-core/query-builders/insert.cjs.map +1 -1
  353. package/gel-core/query-builders/insert.js +2 -2
  354. package/gel-core/query-builders/insert.js.map +1 -1
  355. package/gel-core/query-builders/query.cjs +13 -5
  356. package/gel-core/query-builders/query.cjs.map +1 -1
  357. package/gel-core/query-builders/query.d.ts +1 -1
  358. package/gel-core/query-builders/query.js +14 -6
  359. package/gel-core/query-builders/query.js.map +1 -1
  360. package/gel-core/query-builders/raw.cjs +0 -4
  361. package/gel-core/query-builders/raw.cjs.map +1 -1
  362. package/gel-core/query-builders/raw.js +0 -4
  363. package/gel-core/query-builders/raw.js.map +1 -1
  364. package/gel-core/query-builders/refresh-materialized-view.cjs +2 -2
  365. package/gel-core/query-builders/refresh-materialized-view.cjs.map +1 -1
  366. package/gel-core/query-builders/refresh-materialized-view.js +2 -2
  367. package/gel-core/query-builders/refresh-materialized-view.js.map +1 -1
  368. package/gel-core/query-builders/select.cjs +6 -2
  369. package/gel-core/query-builders/select.cjs.map +1 -1
  370. package/gel-core/query-builders/select.js +6 -2
  371. package/gel-core/query-builders/select.js.map +1 -1
  372. package/gel-core/query-builders/update.cjs +2 -2
  373. package/gel-core/query-builders/update.cjs.map +1 -1
  374. package/gel-core/query-builders/update.js +2 -2
  375. package/gel-core/query-builders/update.js.map +1 -1
  376. package/gel-core/session.cjs +2 -2
  377. package/gel-core/session.cjs.map +1 -1
  378. package/gel-core/session.d.cts +3 -3
  379. package/gel-core/session.d.ts +3 -3
  380. package/gel-core/session.js +2 -2
  381. package/gel-core/session.js.map +1 -1
  382. package/gel-core/table.cjs +1 -1
  383. package/gel-core/table.cjs.map +1 -1
  384. package/gel-core/table.js +1 -1
  385. package/gel-core/table.js.map +1 -1
  386. package/index.cjs +6 -0
  387. package/index.d.cts +6 -6
  388. package/index.d.ts +6 -6
  389. package/index.js +4 -4
  390. package/libsql/driver-core.cjs +3 -2
  391. package/libsql/driver-core.cjs.map +1 -1
  392. package/libsql/driver-core.d.ts +1 -1
  393. package/libsql/driver-core.js +3 -2
  394. package/libsql/driver-core.js.map +1 -1
  395. package/libsql/session.cjs +13 -14
  396. package/libsql/session.cjs.map +1 -1
  397. package/libsql/session.d.cts +9 -6
  398. package/libsql/session.d.ts +9 -6
  399. package/libsql/session.js +14 -15
  400. package/libsql/session.js.map +1 -1
  401. package/mssql-core/columns/bigint.cjs +2 -2
  402. package/mssql-core/columns/bigint.cjs.map +1 -1
  403. package/mssql-core/columns/bigint.d.cts +1 -1
  404. package/mssql-core/columns/bigint.d.ts +1 -1
  405. package/mssql-core/columns/bigint.js +2 -2
  406. package/mssql-core/columns/bigint.js.map +1 -1
  407. package/mssql-core/columns/custom.cjs +4 -4
  408. package/mssql-core/columns/custom.cjs.map +1 -1
  409. package/mssql-core/columns/custom.d.cts +2 -2
  410. package/mssql-core/columns/custom.d.ts +2 -2
  411. package/mssql-core/columns/custom.js +4 -4
  412. package/mssql-core/columns/custom.js.map +1 -1
  413. package/mssql-core/columns/date.cjs +4 -4
  414. package/mssql-core/columns/date.cjs.map +1 -1
  415. package/mssql-core/columns/date.d.cts +2 -2
  416. package/mssql-core/columns/date.d.ts +2 -2
  417. package/mssql-core/columns/date.js +4 -4
  418. package/mssql-core/columns/date.js.map +1 -1
  419. package/mssql-core/columns/datetime.cjs +2 -2
  420. package/mssql-core/columns/datetime.cjs.map +1 -1
  421. package/mssql-core/columns/datetime.d.cts +1 -1
  422. package/mssql-core/columns/datetime.d.ts +1 -1
  423. package/mssql-core/columns/datetime.js +2 -2
  424. package/mssql-core/columns/datetime.js.map +1 -1
  425. package/mssql-core/columns/datetime2.cjs +2 -2
  426. package/mssql-core/columns/datetime2.cjs.map +1 -1
  427. package/mssql-core/columns/datetime2.d.cts +1 -1
  428. package/mssql-core/columns/datetime2.d.ts +1 -1
  429. package/mssql-core/columns/datetime2.js +2 -2
  430. package/mssql-core/columns/datetime2.js.map +1 -1
  431. package/mssql-core/columns/datetimeoffset.cjs +2 -2
  432. package/mssql-core/columns/datetimeoffset.cjs.map +1 -1
  433. package/mssql-core/columns/datetimeoffset.d.cts +1 -1
  434. package/mssql-core/columns/datetimeoffset.d.ts +1 -1
  435. package/mssql-core/columns/datetimeoffset.js +2 -2
  436. package/mssql-core/columns/datetimeoffset.js.map +1 -1
  437. package/mssql-core/columns/decimal.cjs +4 -4
  438. package/mssql-core/columns/decimal.cjs.map +1 -1
  439. package/mssql-core/columns/decimal.d.cts +2 -2
  440. package/mssql-core/columns/decimal.d.ts +2 -2
  441. package/mssql-core/columns/decimal.js +4 -4
  442. package/mssql-core/columns/decimal.js.map +1 -1
  443. package/mssql-core/columns/numeric.cjs +4 -4
  444. package/mssql-core/columns/numeric.cjs.map +1 -1
  445. package/mssql-core/columns/numeric.d.cts +2 -2
  446. package/mssql-core/columns/numeric.d.ts +2 -2
  447. package/mssql-core/columns/numeric.js +4 -4
  448. package/mssql-core/columns/numeric.js.map +1 -1
  449. package/mssql-core/columns/smallint.cjs +2 -2
  450. package/mssql-core/columns/smallint.cjs.map +1 -1
  451. package/mssql-core/columns/smallint.d.cts +1 -1
  452. package/mssql-core/columns/smallint.d.ts +1 -1
  453. package/mssql-core/columns/smallint.js +2 -2
  454. package/mssql-core/columns/smallint.js.map +1 -1
  455. package/mssql-core/columns/time.cjs +2 -2
  456. package/mssql-core/columns/time.cjs.map +1 -1
  457. package/mssql-core/columns/time.d.cts +1 -1
  458. package/mssql-core/columns/time.d.ts +1 -1
  459. package/mssql-core/columns/time.js +2 -2
  460. package/mssql-core/columns/time.js.map +1 -1
  461. package/mssql-core/columns/tinyint.cjs +2 -2
  462. package/mssql-core/columns/tinyint.cjs.map +1 -1
  463. package/mssql-core/columns/tinyint.d.cts +1 -1
  464. package/mssql-core/columns/tinyint.d.ts +1 -1
  465. package/mssql-core/columns/tinyint.js +2 -2
  466. package/mssql-core/columns/tinyint.js.map +1 -1
  467. package/mssql-core/columns/varchar.cjs +4 -4
  468. package/mssql-core/columns/varchar.cjs.map +1 -1
  469. package/mssql-core/columns/varchar.d.cts +2 -2
  470. package/mssql-core/columns/varchar.d.ts +2 -2
  471. package/mssql-core/columns/varchar.js +4 -4
  472. package/mssql-core/columns/varchar.js.map +1 -1
  473. package/mssql-core/dialect.cjs +1 -1
  474. package/mssql-core/dialect.d.ts +1 -1
  475. package/mssql-core/dialect.js +1 -1
  476. package/mssql-core/query-builders/select.cjs +4 -0
  477. package/mssql-core/query-builders/select.cjs.map +1 -1
  478. package/mssql-core/query-builders/select.js +4 -0
  479. package/mssql-core/query-builders/select.js.map +1 -1
  480. package/mssql-core/query-builders/update.d.ts +1 -1
  481. package/mssql-core/table.cjs +1 -1
  482. package/mssql-core/table.cjs.map +1 -1
  483. package/mssql-core/table.js +1 -1
  484. package/mssql-core/table.js.map +1 -1
  485. package/mysql-core/columns/bigint.cjs +8 -8
  486. package/mysql-core/columns/bigint.cjs.map +1 -1
  487. package/mysql-core/columns/bigint.d.cts +4 -4
  488. package/mysql-core/columns/bigint.d.ts +4 -4
  489. package/mysql-core/columns/bigint.js +8 -8
  490. package/mysql-core/columns/bigint.js.map +1 -1
  491. package/mysql-core/columns/binary.cjs +2 -2
  492. package/mysql-core/columns/binary.cjs.map +1 -1
  493. package/mysql-core/columns/binary.d.cts +1 -1
  494. package/mysql-core/columns/binary.d.ts +1 -1
  495. package/mysql-core/columns/binary.js +2 -2
  496. package/mysql-core/columns/binary.js.map +1 -1
  497. package/mysql-core/columns/blob.cjs +4 -4
  498. package/mysql-core/columns/blob.cjs.map +1 -1
  499. package/mysql-core/columns/blob.d.cts +2 -2
  500. package/mysql-core/columns/blob.d.ts +2 -2
  501. package/mysql-core/columns/blob.js +4 -4
  502. package/mysql-core/columns/blob.js.map +1 -1
  503. package/mysql-core/columns/boolean.cjs +2 -2
  504. package/mysql-core/columns/boolean.cjs.map +1 -1
  505. package/mysql-core/columns/boolean.d.cts +1 -1
  506. package/mysql-core/columns/boolean.d.ts +1 -1
  507. package/mysql-core/columns/boolean.js +2 -2
  508. package/mysql-core/columns/boolean.js.map +1 -1
  509. package/mysql-core/columns/custom.cjs +4 -4
  510. package/mysql-core/columns/custom.cjs.map +1 -1
  511. package/mysql-core/columns/custom.d.cts +2 -2
  512. package/mysql-core/columns/custom.d.ts +2 -2
  513. package/mysql-core/columns/custom.js +4 -4
  514. package/mysql-core/columns/custom.js.map +1 -1
  515. package/mysql-core/columns/date.cjs +4 -4
  516. package/mysql-core/columns/date.cjs.map +1 -1
  517. package/mysql-core/columns/date.d.cts +2 -2
  518. package/mysql-core/columns/date.d.ts +2 -2
  519. package/mysql-core/columns/date.js +4 -4
  520. package/mysql-core/columns/date.js.map +1 -1
  521. package/mysql-core/columns/datetime.cjs +8 -8
  522. package/mysql-core/columns/datetime.cjs.map +1 -1
  523. package/mysql-core/columns/datetime.d.cts +4 -4
  524. package/mysql-core/columns/datetime.d.ts +4 -4
  525. package/mysql-core/columns/datetime.js +8 -8
  526. package/mysql-core/columns/datetime.js.map +1 -1
  527. package/mysql-core/columns/decimal.cjs +4 -4
  528. package/mysql-core/columns/decimal.cjs.map +1 -1
  529. package/mysql-core/columns/decimal.d.cts +2 -2
  530. package/mysql-core/columns/decimal.d.ts +2 -2
  531. package/mysql-core/columns/decimal.js +4 -4
  532. package/mysql-core/columns/decimal.js.map +1 -1
  533. package/mysql-core/columns/float.cjs +2 -2
  534. package/mysql-core/columns/float.cjs.map +1 -1
  535. package/mysql-core/columns/float.d.cts +1 -1
  536. package/mysql-core/columns/float.d.ts +1 -1
  537. package/mysql-core/columns/float.js +2 -2
  538. package/mysql-core/columns/float.js.map +1 -1
  539. package/mysql-core/columns/int.cjs +2 -2
  540. package/mysql-core/columns/int.cjs.map +1 -1
  541. package/mysql-core/columns/int.d.cts +1 -1
  542. package/mysql-core/columns/int.d.ts +1 -1
  543. package/mysql-core/columns/int.js +2 -2
  544. package/mysql-core/columns/int.js.map +1 -1
  545. package/mysql-core/columns/json.cjs +2 -2
  546. package/mysql-core/columns/json.cjs.map +1 -1
  547. package/mysql-core/columns/json.d.cts +1 -1
  548. package/mysql-core/columns/json.d.ts +1 -1
  549. package/mysql-core/columns/json.js +2 -2
  550. package/mysql-core/columns/json.js.map +1 -1
  551. package/mysql-core/columns/mediumint.cjs +2 -2
  552. package/mysql-core/columns/mediumint.cjs.map +1 -1
  553. package/mysql-core/columns/mediumint.d.cts +1 -1
  554. package/mysql-core/columns/mediumint.d.ts +1 -1
  555. package/mysql-core/columns/mediumint.js +2 -2
  556. package/mysql-core/columns/mediumint.js.map +1 -1
  557. package/mysql-core/columns/serial.cjs +2 -2
  558. package/mysql-core/columns/serial.cjs.map +1 -1
  559. package/mysql-core/columns/serial.d.cts +1 -1
  560. package/mysql-core/columns/serial.d.ts +1 -1
  561. package/mysql-core/columns/serial.js +2 -2
  562. package/mysql-core/columns/serial.js.map +1 -1
  563. package/mysql-core/columns/smallint.cjs +2 -2
  564. package/mysql-core/columns/smallint.cjs.map +1 -1
  565. package/mysql-core/columns/smallint.d.cts +1 -1
  566. package/mysql-core/columns/smallint.d.ts +1 -1
  567. package/mysql-core/columns/smallint.js +2 -2
  568. package/mysql-core/columns/smallint.js.map +1 -1
  569. package/mysql-core/columns/time.cjs +2 -2
  570. package/mysql-core/columns/time.cjs.map +1 -1
  571. package/mysql-core/columns/time.d.cts +1 -1
  572. package/mysql-core/columns/time.d.ts +1 -1
  573. package/mysql-core/columns/time.js +2 -2
  574. package/mysql-core/columns/time.js.map +1 -1
  575. package/mysql-core/columns/timestamp.cjs +8 -8
  576. package/mysql-core/columns/timestamp.cjs.map +1 -1
  577. package/mysql-core/columns/timestamp.d.cts +4 -4
  578. package/mysql-core/columns/timestamp.d.ts +4 -4
  579. package/mysql-core/columns/timestamp.js +8 -8
  580. package/mysql-core/columns/timestamp.js.map +1 -1
  581. package/mysql-core/columns/tinyint.cjs +2 -2
  582. package/mysql-core/columns/tinyint.cjs.map +1 -1
  583. package/mysql-core/columns/tinyint.d.cts +1 -1
  584. package/mysql-core/columns/tinyint.d.ts +1 -1
  585. package/mysql-core/columns/tinyint.js +2 -2
  586. package/mysql-core/columns/tinyint.js.map +1 -1
  587. package/mysql-core/columns/varbinary.cjs +2 -2
  588. package/mysql-core/columns/varbinary.cjs.map +1 -1
  589. package/mysql-core/columns/varbinary.d.cts +1 -1
  590. package/mysql-core/columns/varbinary.d.ts +1 -1
  591. package/mysql-core/columns/varbinary.js +2 -2
  592. package/mysql-core/columns/varbinary.js.map +1 -1
  593. package/mysql-core/columns/year.cjs +2 -2
  594. package/mysql-core/columns/year.cjs.map +1 -1
  595. package/mysql-core/columns/year.d.cts +1 -1
  596. package/mysql-core/columns/year.d.ts +1 -1
  597. package/mysql-core/columns/year.js +2 -2
  598. package/mysql-core/columns/year.js.map +1 -1
  599. package/mysql-core/db.d.ts +1 -1
  600. package/mysql-core/dialect.cjs +1 -1
  601. package/mysql-core/dialect.d.ts +1 -1
  602. package/mysql-core/dialect.js +1 -1
  603. package/mysql-core/query-builders/query.cjs +13 -5
  604. package/mysql-core/query-builders/query.cjs.map +1 -1
  605. package/mysql-core/query-builders/query.d.ts +1 -1
  606. package/mysql-core/query-builders/query.js +13 -5
  607. package/mysql-core/query-builders/query.js.map +1 -1
  608. package/mysql-core/query-builders/select.cjs +4 -0
  609. package/mysql-core/query-builders/select.cjs.map +1 -1
  610. package/mysql-core/query-builders/select.js +4 -0
  611. package/mysql-core/query-builders/select.js.map +1 -1
  612. package/mysql-core/session.cjs +1 -2
  613. package/mysql-core/session.cjs.map +1 -1
  614. package/mysql-core/session.d.cts +3 -4
  615. package/mysql-core/session.d.ts +3 -4
  616. package/mysql-core/session.js +1 -2
  617. package/mysql-core/session.js.map +1 -1
  618. package/mysql-core/table.cjs +1 -1
  619. package/mysql-core/table.cjs.map +1 -1
  620. package/mysql-core/table.js +1 -1
  621. package/mysql-core/table.js.map +1 -1
  622. package/mysql-proxy/driver.cjs +5 -2
  623. package/mysql-proxy/driver.cjs.map +1 -1
  624. package/mysql-proxy/driver.js +5 -2
  625. package/mysql-proxy/driver.js.map +1 -1
  626. package/mysql-proxy/session.cjs +25 -18
  627. package/mysql-proxy/session.cjs.map +1 -1
  628. package/mysql-proxy/session.d.cts +11 -4
  629. package/mysql-proxy/session.d.ts +12 -5
  630. package/mysql-proxy/session.js +26 -19
  631. package/mysql-proxy/session.js.map +1 -1
  632. package/mysql2/driver.cjs +3 -2
  633. package/mysql2/driver.cjs.map +1 -1
  634. package/mysql2/driver.d.cts +1 -0
  635. package/mysql2/driver.d.ts +3 -2
  636. package/mysql2/driver.js +3 -2
  637. package/mysql2/driver.js.map +1 -1
  638. package/mysql2/session.cjs +48 -38
  639. package/mysql2/session.cjs.map +1 -1
  640. package/mysql2/session.d.cts +11 -4
  641. package/mysql2/session.d.ts +12 -5
  642. package/mysql2/session.js +49 -39
  643. package/mysql2/session.js.map +1 -1
  644. package/neon-http/driver.cjs +34 -65
  645. package/neon-http/driver.cjs.map +1 -1
  646. package/neon-http/driver.d.cts +15 -19
  647. package/neon-http/driver.d.ts +16 -20
  648. package/neon-http/driver.js +34 -64
  649. package/neon-http/driver.js.map +1 -1
  650. package/neon-http/index.cjs +2 -4
  651. package/neon-http/index.d.cts +3 -3
  652. package/neon-http/index.d.ts +3 -3
  653. package/neon-http/index.js +3 -3
  654. package/neon-http/migrator.cjs +1 -1
  655. package/neon-http/migrator.cjs.map +1 -1
  656. package/neon-http/migrator.d.cts +1 -1
  657. package/neon-http/migrator.d.ts +1 -1
  658. package/neon-http/migrator.js +1 -1
  659. package/neon-http/migrator.js.map +1 -1
  660. package/neon-http/session.cjs +27 -116
  661. package/neon-http/session.cjs.map +1 -1
  662. package/neon-http/session.d.cts +10 -38
  663. package/neon-http/session.d.ts +10 -38
  664. package/neon-http/session.js +29 -116
  665. package/neon-http/session.js.map +1 -1
  666. package/neon-serverless/driver.cjs +14 -32
  667. package/neon-serverless/driver.cjs.map +1 -1
  668. package/neon-serverless/driver.d.cts +12 -17
  669. package/neon-serverless/driver.d.ts +13 -18
  670. package/neon-serverless/driver.js +14 -31
  671. package/neon-serverless/driver.js.map +1 -1
  672. package/neon-serverless/index.cjs +2 -3
  673. package/neon-serverless/index.d.cts +3 -3
  674. package/neon-serverless/index.d.ts +3 -3
  675. package/neon-serverless/index.js +3 -3
  676. package/neon-serverless/migrator.cjs.map +1 -1
  677. package/neon-serverless/migrator.d.cts +1 -1
  678. package/neon-serverless/migrator.d.ts +1 -1
  679. package/neon-serverless/migrator.js.map +1 -1
  680. package/neon-serverless/session.cjs +32 -108
  681. package/neon-serverless/session.cjs.map +1 -1
  682. package/neon-serverless/session.d.cts +9 -32
  683. package/neon-serverless/session.d.ts +9 -32
  684. package/neon-serverless/session.js +34 -109
  685. package/neon-serverless/session.js.map +1 -1
  686. package/netlify-db/driver.cjs +36 -43
  687. package/netlify-db/driver.cjs.map +1 -1
  688. package/netlify-db/driver.d.cts +29 -29
  689. package/netlify-db/driver.d.ts +31 -31
  690. package/netlify-db/driver.js +35 -42
  691. package/netlify-db/driver.js.map +1 -1
  692. package/netlify-db/index.cjs +3 -2
  693. package/netlify-db/index.d.cts +3 -3
  694. package/netlify-db/index.d.ts +3 -3
  695. package/netlify-db/index.js +2 -2
  696. package/netlify-db/migrator.cjs.map +1 -1
  697. package/netlify-db/migrator.d.cts +1 -1
  698. package/netlify-db/migrator.d.ts +1 -1
  699. package/netlify-db/migrator.js.map +1 -1
  700. package/netlify-db/session.cjs +61 -39
  701. package/netlify-db/session.cjs.map +1 -1
  702. package/netlify-db/session.d.cts +22 -23
  703. package/netlify-db/session.d.ts +23 -24
  704. package/netlify-db/session.js +63 -41
  705. package/netlify-db/session.js.map +1 -1
  706. package/node-mssql/driver.cjs +9 -3
  707. package/node-mssql/driver.cjs.map +1 -1
  708. package/node-mssql/driver.d.cts +1 -0
  709. package/node-mssql/driver.d.ts +2 -1
  710. package/node-mssql/driver.js +9 -3
  711. package/node-mssql/driver.js.map +1 -1
  712. package/node-mssql/session.cjs +6 -4
  713. package/node-mssql/session.cjs.map +1 -1
  714. package/node-mssql/session.d.cts +4 -1
  715. package/node-mssql/session.d.ts +5 -2
  716. package/node-mssql/session.js +7 -5
  717. package/node-mssql/session.js.map +1 -1
  718. package/node-postgres/driver.cjs +15 -18
  719. package/node-postgres/driver.cjs.map +1 -1
  720. package/node-postgres/driver.d.cts +11 -6
  721. package/node-postgres/driver.d.ts +12 -7
  722. package/node-postgres/driver.js +15 -18
  723. package/node-postgres/driver.js.map +1 -1
  724. package/node-postgres/index.cjs +2 -2
  725. package/node-postgres/index.d.cts +3 -3
  726. package/node-postgres/index.d.ts +3 -3
  727. package/node-postgres/index.js +3 -3
  728. package/node-postgres/migrator.cjs.map +1 -1
  729. package/node-postgres/migrator.d.cts +1 -1
  730. package/node-postgres/migrator.d.ts +1 -1
  731. package/node-postgres/migrator.js.map +1 -1
  732. package/node-postgres/session.cjs +32 -125
  733. package/node-postgres/session.cjs.map +1 -1
  734. package/node-postgres/session.d.cts +10 -30
  735. package/node-postgres/session.d.ts +9 -29
  736. package/node-postgres/session.js +34 -126
  737. package/node-postgres/session.js.map +1 -1
  738. package/node-sqlite/driver.cjs +1 -1
  739. package/node-sqlite/driver.d.ts +1 -1
  740. package/node-sqlite/driver.js +1 -1
  741. package/node-sqlite/session.cjs +4 -9
  742. package/node-sqlite/session.cjs.map +1 -1
  743. package/node-sqlite/session.d.cts +3 -4
  744. package/node-sqlite/session.d.ts +4 -5
  745. package/node-sqlite/session.js +4 -9
  746. package/node-sqlite/session.js.map +1 -1
  747. package/op-sqlite/driver.cjs +3 -2
  748. package/op-sqlite/driver.cjs.map +1 -1
  749. package/op-sqlite/driver.d.ts +1 -1
  750. package/op-sqlite/driver.js +3 -2
  751. package/op-sqlite/driver.js.map +1 -1
  752. package/op-sqlite/session.cjs +17 -15
  753. package/op-sqlite/session.cjs.map +1 -1
  754. package/op-sqlite/session.d.cts +10 -6
  755. package/op-sqlite/session.d.ts +10 -6
  756. package/op-sqlite/session.js +18 -16
  757. package/op-sqlite/session.js.map +1 -1
  758. package/operations.d.cts +3 -0
  759. package/operations.d.ts +3 -0
  760. package/package.json +43 -31
  761. package/pg-core/{utils/array.cjs → array.cjs} +1 -1
  762. package/pg-core/array.cjs.map +1 -0
  763. package/pg-core/{utils/array.d.cts → array.d.cts} +1 -1
  764. package/pg-core/{utils/array.d.ts → array.d.ts} +1 -1
  765. package/pg-core/{utils/array.js → array.js} +1 -1
  766. package/pg-core/array.js.map +1 -0
  767. package/pg-core/async/count.cjs +2 -9
  768. package/pg-core/async/count.cjs.map +1 -1
  769. package/pg-core/async/count.js +2 -9
  770. package/pg-core/async/count.js.map +1 -1
  771. package/pg-core/async/db.cjs +8 -28
  772. package/pg-core/async/db.cjs.map +1 -1
  773. package/pg-core/async/db.d.cts +5 -13
  774. package/pg-core/async/db.d.ts +6 -14
  775. package/pg-core/async/db.js +8 -28
  776. package/pg-core/async/db.js.map +1 -1
  777. package/pg-core/async/delete.cjs +7 -12
  778. package/pg-core/async/delete.cjs.map +1 -1
  779. package/pg-core/async/delete.js +7 -12
  780. package/pg-core/async/delete.js.map +1 -1
  781. package/pg-core/async/insert.cjs +7 -12
  782. package/pg-core/async/insert.cjs.map +1 -1
  783. package/pg-core/async/insert.js +7 -12
  784. package/pg-core/async/insert.js.map +1 -1
  785. package/pg-core/async/query.cjs +8 -14
  786. package/pg-core/async/query.cjs.map +1 -1
  787. package/pg-core/async/query.js +8 -14
  788. package/pg-core/async/query.js.map +1 -1
  789. package/pg-core/async/refresh-materialized-view.cjs +1 -9
  790. package/pg-core/async/refresh-materialized-view.cjs.map +1 -1
  791. package/pg-core/async/refresh-materialized-view.js +1 -9
  792. package/pg-core/async/refresh-materialized-view.js.map +1 -1
  793. package/pg-core/async/select.cjs +4 -13
  794. package/pg-core/async/select.cjs.map +1 -1
  795. package/pg-core/async/select.js +4 -13
  796. package/pg-core/async/select.js.map +1 -1
  797. package/pg-core/async/session.cjs +44 -20
  798. package/pg-core/async/session.cjs.map +1 -1
  799. package/pg-core/async/session.d.cts +25 -31
  800. package/pg-core/async/session.d.ts +26 -32
  801. package/pg-core/async/session.js +45 -21
  802. package/pg-core/async/session.js.map +1 -1
  803. package/pg-core/async/update.cjs +11 -15
  804. package/pg-core/async/update.cjs.map +1 -1
  805. package/pg-core/async/update.js +11 -15
  806. package/pg-core/async/update.js.map +1 -1
  807. package/pg-core/codecs.cjs +156 -0
  808. package/pg-core/codecs.cjs.map +1 -0
  809. package/pg-core/codecs.d.cts +27 -0
  810. package/pg-core/codecs.d.ts +27 -0
  811. package/pg-core/codecs.js +148 -0
  812. package/pg-core/codecs.js.map +1 -0
  813. package/pg-core/columns/bigint.cjs +10 -9
  814. package/pg-core/columns/bigint.cjs.map +1 -1
  815. package/pg-core/columns/bigint.d.cts +2 -3
  816. package/pg-core/columns/bigint.d.ts +2 -3
  817. package/pg-core/columns/bigint.js +10 -9
  818. package/pg-core/columns/bigint.js.map +1 -1
  819. package/pg-core/columns/bigserial.cjs +6 -6
  820. package/pg-core/columns/bigserial.cjs.map +1 -1
  821. package/pg-core/columns/bigserial.d.cts +1 -2
  822. package/pg-core/columns/bigserial.d.ts +1 -2
  823. package/pg-core/columns/bigserial.js +6 -6
  824. package/pg-core/columns/bigserial.js.map +1 -1
  825. package/pg-core/columns/boolean.cjs +2 -0
  826. package/pg-core/columns/boolean.cjs.map +1 -1
  827. package/pg-core/columns/boolean.js +2 -0
  828. package/pg-core/columns/boolean.js.map +1 -1
  829. package/pg-core/columns/bytea.cjs +2 -8
  830. package/pg-core/columns/bytea.cjs.map +1 -1
  831. package/pg-core/columns/bytea.d.cts +0 -1
  832. package/pg-core/columns/bytea.d.ts +0 -1
  833. package/pg-core/columns/bytea.js +2 -8
  834. package/pg-core/columns/bytea.js.map +1 -1
  835. package/pg-core/columns/char.cjs +2 -0
  836. package/pg-core/columns/char.cjs.map +1 -1
  837. package/pg-core/columns/char.js +2 -0
  838. package/pg-core/columns/char.js.map +1 -1
  839. package/pg-core/columns/cidr.cjs +2 -0
  840. package/pg-core/columns/cidr.cjs.map +1 -1
  841. package/pg-core/columns/cidr.js +2 -0
  842. package/pg-core/columns/cidr.js.map +1 -1
  843. package/pg-core/columns/common.cjs +10 -8
  844. package/pg-core/columns/common.cjs.map +1 -1
  845. package/pg-core/columns/common.d.cts +34 -39
  846. package/pg-core/columns/common.d.ts +34 -39
  847. package/pg-core/columns/common.js +10 -8
  848. package/pg-core/columns/common.js.map +1 -1
  849. package/pg-core/columns/custom.cjs +16 -46
  850. package/pg-core/columns/custom.cjs.map +1 -1
  851. package/pg-core/columns/custom.d.cts +17 -8
  852. package/pg-core/columns/custom.d.ts +17 -8
  853. package/pg-core/columns/custom.js +16 -46
  854. package/pg-core/columns/custom.js.map +1 -1
  855. package/pg-core/columns/date.cjs +11 -12
  856. package/pg-core/columns/date.cjs.map +1 -1
  857. package/pg-core/columns/date.d.cts +3 -4
  858. package/pg-core/columns/date.d.ts +3 -4
  859. package/pg-core/columns/date.js +11 -12
  860. package/pg-core/columns/date.js.map +1 -1
  861. package/pg-core/columns/double-precision.cjs +2 -4
  862. package/pg-core/columns/double-precision.cjs.map +1 -1
  863. package/pg-core/columns/double-precision.d.cts +0 -1
  864. package/pg-core/columns/double-precision.d.ts +0 -1
  865. package/pg-core/columns/double-precision.js +2 -4
  866. package/pg-core/columns/double-precision.js.map +1 -1
  867. package/pg-core/columns/enum.cjs +4 -0
  868. package/pg-core/columns/enum.cjs.map +1 -1
  869. package/pg-core/columns/enum.js +4 -0
  870. package/pg-core/columns/enum.js.map +1 -1
  871. package/pg-core/columns/index.d.cts +2 -2
  872. package/pg-core/columns/index.d.ts +2 -2
  873. package/pg-core/columns/inet.cjs +2 -0
  874. package/pg-core/columns/inet.cjs.map +1 -1
  875. package/pg-core/columns/inet.js +2 -0
  876. package/pg-core/columns/inet.js.map +1 -1
  877. package/pg-core/columns/integer.cjs +2 -4
  878. package/pg-core/columns/integer.cjs.map +1 -1
  879. package/pg-core/columns/integer.d.cts +0 -1
  880. package/pg-core/columns/integer.d.ts +0 -1
  881. package/pg-core/columns/integer.js +2 -4
  882. package/pg-core/columns/integer.js.map +1 -1
  883. package/pg-core/columns/interval.cjs +2 -0
  884. package/pg-core/columns/interval.cjs.map +1 -1
  885. package/pg-core/columns/interval.js +2 -0
  886. package/pg-core/columns/interval.js.map +1 -1
  887. package/pg-core/columns/json.cjs +2 -11
  888. package/pg-core/columns/json.cjs.map +1 -1
  889. package/pg-core/columns/json.d.cts +0 -2
  890. package/pg-core/columns/json.d.ts +0 -2
  891. package/pg-core/columns/json.js +2 -11
  892. package/pg-core/columns/json.js.map +1 -1
  893. package/pg-core/columns/jsonb.cjs +2 -11
  894. package/pg-core/columns/jsonb.cjs.map +1 -1
  895. package/pg-core/columns/jsonb.d.cts +0 -2
  896. package/pg-core/columns/jsonb.d.ts +0 -2
  897. package/pg-core/columns/jsonb.js +2 -11
  898. package/pg-core/columns/jsonb.js.map +1 -1
  899. package/pg-core/columns/line.cjs +12 -8
  900. package/pg-core/columns/line.cjs.map +1 -1
  901. package/pg-core/columns/line.d.cts +5 -5
  902. package/pg-core/columns/line.d.ts +5 -5
  903. package/pg-core/columns/line.js +12 -8
  904. package/pg-core/columns/line.js.map +1 -1
  905. package/pg-core/columns/macaddr.cjs +2 -0
  906. package/pg-core/columns/macaddr.cjs.map +1 -1
  907. package/pg-core/columns/macaddr.js +2 -0
  908. package/pg-core/columns/macaddr.js.map +1 -1
  909. package/pg-core/columns/macaddr8.cjs +2 -0
  910. package/pg-core/columns/macaddr8.cjs.map +1 -1
  911. package/pg-core/columns/macaddr8.js +2 -0
  912. package/pg-core/columns/macaddr8.js.map +1 -1
  913. package/pg-core/columns/numeric.cjs +12 -15
  914. package/pg-core/columns/numeric.cjs.map +1 -1
  915. package/pg-core/columns/numeric.d.cts +4 -5
  916. package/pg-core/columns/numeric.d.ts +4 -5
  917. package/pg-core/columns/numeric.js +12 -15
  918. package/pg-core/columns/numeric.js.map +1 -1
  919. package/pg-core/columns/point.cjs +19 -21
  920. package/pg-core/columns/point.cjs.map +1 -1
  921. package/pg-core/columns/point.d.cts +5 -11
  922. package/pg-core/columns/point.d.ts +5 -11
  923. package/pg-core/columns/point.js +19 -21
  924. package/pg-core/columns/point.js.map +1 -1
  925. package/pg-core/columns/postgis_extension/geometry.cjs +12 -9
  926. package/pg-core/columns/postgis_extension/geometry.cjs.map +1 -1
  927. package/pg-core/columns/postgis_extension/geometry.d.cts +5 -5
  928. package/pg-core/columns/postgis_extension/geometry.d.ts +5 -5
  929. package/pg-core/columns/postgis_extension/geometry.js +12 -9
  930. package/pg-core/columns/postgis_extension/geometry.js.map +1 -1
  931. package/pg-core/columns/real.cjs +2 -4
  932. package/pg-core/columns/real.cjs.map +1 -1
  933. package/pg-core/columns/real.d.cts +0 -1
  934. package/pg-core/columns/real.d.ts +0 -1
  935. package/pg-core/columns/real.js +2 -4
  936. package/pg-core/columns/real.js.map +1 -1
  937. package/pg-core/columns/serial.cjs +2 -0
  938. package/pg-core/columns/serial.cjs.map +1 -1
  939. package/pg-core/columns/serial.js +2 -0
  940. package/pg-core/columns/serial.js.map +1 -1
  941. package/pg-core/columns/smallint.cjs +2 -4
  942. package/pg-core/columns/smallint.cjs.map +1 -1
  943. package/pg-core/columns/smallint.d.cts +0 -1
  944. package/pg-core/columns/smallint.d.ts +0 -1
  945. package/pg-core/columns/smallint.js +2 -4
  946. package/pg-core/columns/smallint.js.map +1 -1
  947. package/pg-core/columns/smallserial.cjs +2 -0
  948. package/pg-core/columns/smallserial.cjs.map +1 -1
  949. package/pg-core/columns/smallserial.js +2 -0
  950. package/pg-core/columns/smallserial.js.map +1 -1
  951. package/pg-core/columns/text.cjs +2 -0
  952. package/pg-core/columns/text.cjs.map +1 -1
  953. package/pg-core/columns/text.js +2 -0
  954. package/pg-core/columns/text.js.map +1 -1
  955. package/pg-core/columns/time.cjs +2 -0
  956. package/pg-core/columns/time.cjs.map +1 -1
  957. package/pg-core/columns/time.js +2 -0
  958. package/pg-core/columns/time.js.map +1 -1
  959. package/pg-core/columns/timestamp.cjs +13 -14
  960. package/pg-core/columns/timestamp.cjs.map +1 -1
  961. package/pg-core/columns/timestamp.d.cts +3 -4
  962. package/pg-core/columns/timestamp.d.ts +3 -4
  963. package/pg-core/columns/timestamp.js +13 -14
  964. package/pg-core/columns/timestamp.js.map +1 -1
  965. package/pg-core/columns/uuid.cjs +2 -0
  966. package/pg-core/columns/uuid.cjs.map +1 -1
  967. package/pg-core/columns/uuid.js +2 -0
  968. package/pg-core/columns/uuid.js.map +1 -1
  969. package/pg-core/columns/varchar.cjs +2 -0
  970. package/pg-core/columns/varchar.cjs.map +1 -1
  971. package/pg-core/columns/varchar.js +2 -0
  972. package/pg-core/columns/varchar.js.map +1 -1
  973. package/pg-core/columns/vector_extension/bit.cjs +2 -0
  974. package/pg-core/columns/vector_extension/bit.cjs.map +1 -1
  975. package/pg-core/columns/vector_extension/bit.js +2 -0
  976. package/pg-core/columns/vector_extension/bit.js.map +1 -1
  977. package/pg-core/columns/vector_extension/halfvec.cjs +6 -4
  978. package/pg-core/columns/vector_extension/halfvec.cjs.map +1 -1
  979. package/pg-core/columns/vector_extension/halfvec.d.cts +2 -2
  980. package/pg-core/columns/vector_extension/halfvec.d.ts +2 -2
  981. package/pg-core/columns/vector_extension/halfvec.js +6 -4
  982. package/pg-core/columns/vector_extension/halfvec.js.map +1 -1
  983. package/pg-core/columns/vector_extension/sparsevec.cjs +2 -0
  984. package/pg-core/columns/vector_extension/sparsevec.cjs.map +1 -1
  985. package/pg-core/columns/vector_extension/sparsevec.js +2 -0
  986. package/pg-core/columns/vector_extension/sparsevec.js.map +1 -1
  987. package/pg-core/columns/vector_extension/vector.cjs +6 -4
  988. package/pg-core/columns/vector_extension/vector.cjs.map +1 -1
  989. package/pg-core/columns/vector_extension/vector.d.cts +2 -2
  990. package/pg-core/columns/vector_extension/vector.d.ts +2 -2
  991. package/pg-core/columns/vector_extension/vector.js +6 -4
  992. package/pg-core/columns/vector_extension/vector.js.map +1 -1
  993. package/pg-core/dialect.cjs +73 -226
  994. package/pg-core/dialect.cjs.map +1 -1
  995. package/pg-core/dialect.d.cts +27 -34
  996. package/pg-core/dialect.d.ts +27 -34
  997. package/pg-core/dialect.js +78 -230
  998. package/pg-core/dialect.js.map +1 -1
  999. package/pg-core/effect/count.cjs +1 -1
  1000. package/pg-core/effect/count.cjs.map +1 -1
  1001. package/pg-core/effect/count.d.cts +2 -2
  1002. package/pg-core/effect/count.d.ts +2 -2
  1003. package/pg-core/effect/count.js +1 -1
  1004. package/pg-core/effect/count.js.map +1 -1
  1005. package/pg-core/effect/db.cjs +9 -18
  1006. package/pg-core/effect/db.cjs.map +1 -1
  1007. package/pg-core/effect/db.d.cts +7 -11
  1008. package/pg-core/effect/db.d.ts +6 -10
  1009. package/pg-core/effect/db.js +9 -18
  1010. package/pg-core/effect/db.js.map +1 -1
  1011. package/pg-core/effect/delete.cjs +7 -5
  1012. package/pg-core/effect/delete.cjs.map +1 -1
  1013. package/pg-core/effect/delete.d.cts +1 -1
  1014. package/pg-core/effect/delete.d.ts +1 -1
  1015. package/pg-core/effect/delete.js +7 -5
  1016. package/pg-core/effect/delete.js.map +1 -1
  1017. package/pg-core/effect/insert.cjs +7 -5
  1018. package/pg-core/effect/insert.cjs.map +1 -1
  1019. package/pg-core/effect/insert.d.cts +1 -1
  1020. package/pg-core/effect/insert.d.ts +1 -1
  1021. package/pg-core/effect/insert.js +7 -5
  1022. package/pg-core/effect/insert.js.map +1 -1
  1023. package/pg-core/effect/query.cjs +7 -6
  1024. package/pg-core/effect/query.cjs.map +1 -1
  1025. package/pg-core/effect/query.d.cts +1 -1
  1026. package/pg-core/effect/query.d.ts +1 -1
  1027. package/pg-core/effect/query.js +7 -6
  1028. package/pg-core/effect/query.js.map +1 -1
  1029. package/pg-core/effect/refresh-materialized-view.cjs +1 -2
  1030. package/pg-core/effect/refresh-materialized-view.cjs.map +1 -1
  1031. package/pg-core/effect/refresh-materialized-view.d.cts +1 -1
  1032. package/pg-core/effect/refresh-materialized-view.d.ts +1 -1
  1033. package/pg-core/effect/refresh-materialized-view.js +1 -2
  1034. package/pg-core/effect/refresh-materialized-view.js.map +1 -1
  1035. package/pg-core/effect/select.cjs +3 -5
  1036. package/pg-core/effect/select.cjs.map +1 -1
  1037. package/pg-core/effect/select.d.cts +1 -1
  1038. package/pg-core/effect/select.d.ts +1 -1
  1039. package/pg-core/effect/select.js +3 -5
  1040. package/pg-core/effect/select.js.map +1 -1
  1041. package/pg-core/effect/session.cjs +28 -17
  1042. package/pg-core/effect/session.cjs.map +1 -1
  1043. package/pg-core/effect/session.d.cts +24 -28
  1044. package/pg-core/effect/session.d.ts +25 -29
  1045. package/pg-core/effect/session.js +29 -18
  1046. package/pg-core/effect/session.js.map +1 -1
  1047. package/pg-core/effect/update.cjs +8 -8
  1048. package/pg-core/effect/update.cjs.map +1 -1
  1049. package/pg-core/effect/update.d.cts +1 -1
  1050. package/pg-core/effect/update.d.ts +1 -1
  1051. package/pg-core/effect/update.js +8 -8
  1052. package/pg-core/effect/update.js.map +1 -1
  1053. package/pg-core/index.cjs +4 -4
  1054. package/pg-core/index.d.cts +4 -4
  1055. package/pg-core/index.d.ts +4 -4
  1056. package/pg-core/index.js +1 -1
  1057. package/pg-core/query-builders/delete.cjs +6 -2
  1058. package/pg-core/query-builders/delete.cjs.map +1 -1
  1059. package/pg-core/query-builders/delete.d.cts +2 -0
  1060. package/pg-core/query-builders/delete.d.ts +2 -0
  1061. package/pg-core/query-builders/delete.js +6 -2
  1062. package/pg-core/query-builders/delete.js.map +1 -1
  1063. package/pg-core/query-builders/insert.cjs +7 -2
  1064. package/pg-core/query-builders/insert.cjs.map +1 -1
  1065. package/pg-core/query-builders/insert.d.cts +2 -0
  1066. package/pg-core/query-builders/insert.d.ts +2 -0
  1067. package/pg-core/query-builders/insert.js +7 -2
  1068. package/pg-core/query-builders/insert.js.map +1 -1
  1069. package/pg-core/query-builders/query-builder.cjs +2 -1
  1070. package/pg-core/query-builders/query-builder.cjs.map +1 -1
  1071. package/pg-core/query-builders/query-builder.js +2 -1
  1072. package/pg-core/query-builders/query-builder.js.map +1 -1
  1073. package/pg-core/query-builders/query.cjs +0 -1
  1074. package/pg-core/query-builders/query.cjs.map +1 -1
  1075. package/pg-core/query-builders/query.d.cts +2 -1
  1076. package/pg-core/query-builders/query.d.ts +2 -1
  1077. package/pg-core/query-builders/query.js +0 -1
  1078. package/pg-core/query-builders/query.js.map +1 -1
  1079. package/pg-core/query-builders/raw.cjs +0 -4
  1080. package/pg-core/query-builders/raw.cjs.map +1 -1
  1081. package/pg-core/query-builders/raw.js +0 -4
  1082. package/pg-core/query-builders/raw.js.map +1 -1
  1083. package/pg-core/query-builders/select.cjs +6 -2
  1084. package/pg-core/query-builders/select.cjs.map +1 -1
  1085. package/pg-core/query-builders/select.d.cts +1 -0
  1086. package/pg-core/query-builders/select.d.ts +1 -0
  1087. package/pg-core/query-builders/select.js +6 -2
  1088. package/pg-core/query-builders/select.js.map +1 -1
  1089. package/pg-core/query-builders/select.types.d.cts +1 -0
  1090. package/pg-core/query-builders/select.types.d.ts +1 -0
  1091. package/pg-core/query-builders/update.cjs +6 -2
  1092. package/pg-core/query-builders/update.cjs.map +1 -1
  1093. package/pg-core/query-builders/update.d.cts +2 -0
  1094. package/pg-core/query-builders/update.d.ts +2 -0
  1095. package/pg-core/query-builders/update.js +6 -2
  1096. package/pg-core/query-builders/update.js.map +1 -1
  1097. package/pg-core/session.cjs +3 -5
  1098. package/pg-core/session.cjs.map +1 -1
  1099. package/pg-core/session.d.cts +4 -7
  1100. package/pg-core/session.d.ts +4 -7
  1101. package/pg-core/session.js +3 -5
  1102. package/pg-core/session.js.map +1 -1
  1103. package/pg-core/table.cjs +1 -1
  1104. package/pg-core/table.cjs.map +1 -1
  1105. package/pg-core/table.js +1 -1
  1106. package/pg-core/table.js.map +1 -1
  1107. package/pg-core/utils.cjs.map +1 -1
  1108. package/pg-core/utils.d.cts +7 -1
  1109. package/pg-core/utils.d.ts +7 -1
  1110. package/pg-core/utils.js.map +1 -1
  1111. package/pg-core/view.cjs +2 -2
  1112. package/pg-core/view.cjs.map +1 -1
  1113. package/pg-core/view.js +2 -2
  1114. package/pg-core/view.js.map +1 -1
  1115. package/pg-proxy/driver.cjs +10 -15
  1116. package/pg-proxy/driver.cjs.map +1 -1
  1117. package/pg-proxy/driver.d.cts +6 -3
  1118. package/pg-proxy/driver.d.ts +6 -3
  1119. package/pg-proxy/driver.js +10 -14
  1120. package/pg-proxy/driver.js.map +1 -1
  1121. package/pg-proxy/index.cjs +0 -2
  1122. package/pg-proxy/index.d.cts +2 -2
  1123. package/pg-proxy/index.d.ts +2 -2
  1124. package/pg-proxy/index.js +2 -2
  1125. package/pg-proxy/migrator.cjs.map +1 -1
  1126. package/pg-proxy/migrator.d.cts +1 -1
  1127. package/pg-proxy/migrator.d.ts +1 -1
  1128. package/pg-proxy/migrator.js.map +1 -1
  1129. package/pg-proxy/session.cjs +8 -84
  1130. package/pg-proxy/session.cjs.map +1 -1
  1131. package/pg-proxy/session.d.cts +9 -32
  1132. package/pg-proxy/session.d.ts +9 -32
  1133. package/pg-proxy/session.js +10 -84
  1134. package/pg-proxy/session.js.map +1 -1
  1135. package/pglite/driver.cjs +71 -33
  1136. package/pglite/driver.cjs.map +1 -1
  1137. package/pglite/driver.d.cts +12 -17
  1138. package/pglite/driver.d.ts +13 -18
  1139. package/pglite/driver.js +71 -32
  1140. package/pglite/driver.js.map +1 -1
  1141. package/pglite/index.cjs +2 -3
  1142. package/pglite/index.d.cts +3 -3
  1143. package/pglite/index.d.ts +3 -3
  1144. package/pglite/index.js +3 -3
  1145. package/pglite/migrator.cjs.map +1 -1
  1146. package/pglite/migrator.d.cts +1 -1
  1147. package/pglite/migrator.d.ts +1 -1
  1148. package/pglite/migrator.js.map +1 -1
  1149. package/pglite/session.cjs +24 -85
  1150. package/pglite/session.cjs.map +1 -1
  1151. package/pglite/session.d.cts +9 -30
  1152. package/pglite/session.d.ts +9 -30
  1153. package/pglite/session.js +26 -86
  1154. package/pglite/session.js.map +1 -1
  1155. package/planetscale-serverless/driver.cjs +3 -2
  1156. package/planetscale-serverless/driver.cjs.map +1 -1
  1157. package/planetscale-serverless/driver.d.cts +1 -0
  1158. package/planetscale-serverless/driver.d.ts +1 -0
  1159. package/planetscale-serverless/driver.js +3 -2
  1160. package/planetscale-serverless/driver.js.map +1 -1
  1161. package/planetscale-serverless/session.cjs +26 -19
  1162. package/planetscale-serverless/session.cjs.map +1 -1
  1163. package/planetscale-serverless/session.d.cts +12 -6
  1164. package/planetscale-serverless/session.d.ts +13 -7
  1165. package/planetscale-serverless/session.js +27 -20
  1166. package/planetscale-serverless/session.js.map +1 -1
  1167. package/postgres-js/driver.cjs +124 -19
  1168. package/postgres-js/driver.cjs.map +1 -1
  1169. package/postgres-js/driver.d.cts +10 -6
  1170. package/postgres-js/driver.d.ts +10 -6
  1171. package/postgres-js/driver.js +124 -19
  1172. package/postgres-js/driver.js.map +1 -1
  1173. package/postgres-js/index.cjs +2 -2
  1174. package/postgres-js/index.d.cts +3 -3
  1175. package/postgres-js/index.d.ts +3 -3
  1176. package/postgres-js/index.js +3 -3
  1177. package/postgres-js/migrator.cjs.map +1 -1
  1178. package/postgres-js/migrator.d.cts +1 -1
  1179. package/postgres-js/migrator.d.ts +1 -1
  1180. package/postgres-js/migrator.js.map +1 -1
  1181. package/postgres-js/session.cjs +16 -111
  1182. package/postgres-js/session.cjs.map +1 -1
  1183. package/postgres-js/session.d.cts +10 -31
  1184. package/postgres-js/session.d.ts +9 -30
  1185. package/postgres-js/session.js +17 -111
  1186. package/postgres-js/session.js.map +1 -1
  1187. package/prisma/mysql/session.cjs +2 -1
  1188. package/prisma/mysql/session.cjs.map +1 -1
  1189. package/prisma/mysql/session.d.cts +1 -0
  1190. package/prisma/mysql/session.d.ts +2 -1
  1191. package/prisma/mysql/session.js +2 -1
  1192. package/prisma/mysql/session.js.map +1 -1
  1193. package/prisma/pg/driver.cjs +9 -3
  1194. package/prisma/pg/driver.cjs.map +1 -1
  1195. package/prisma/pg/driver.d.cts +7 -3
  1196. package/prisma/pg/driver.d.ts +7 -3
  1197. package/prisma/pg/driver.js +9 -4
  1198. package/prisma/pg/driver.js.map +1 -1
  1199. package/prisma/pg/index.cjs +2 -2
  1200. package/prisma/pg/index.d.cts +3 -3
  1201. package/prisma/pg/index.d.ts +3 -3
  1202. package/prisma/pg/index.js +3 -3
  1203. package/prisma/pg/session.cjs +1 -25
  1204. package/prisma/pg/session.cjs.map +1 -1
  1205. package/prisma/pg/session.d.cts +3 -15
  1206. package/prisma/pg/session.d.ts +2 -14
  1207. package/prisma/pg/session.js +2 -25
  1208. package/prisma/pg/session.js.map +1 -1
  1209. package/prisma/sqlite/session.cjs +0 -3
  1210. package/prisma/sqlite/session.cjs.map +1 -1
  1211. package/prisma/sqlite/session.d.cts +0 -1
  1212. package/prisma/sqlite/session.d.ts +1 -2
  1213. package/prisma/sqlite/session.js +0 -3
  1214. package/prisma/sqlite/session.js.map +1 -1
  1215. package/query-builders/query-builder.cjs +4 -0
  1216. package/query-builders/query-builder.cjs.map +1 -1
  1217. package/query-builders/query-builder.js +4 -0
  1218. package/query-builders/query-builder.js.map +1 -1
  1219. package/relations.cjs +84 -23
  1220. package/relations.cjs.map +1 -1
  1221. package/relations.d.cts +41 -16
  1222. package/relations.d.ts +41 -16
  1223. package/relations.js +83 -24
  1224. package/relations.js.map +1 -1
  1225. package/row-mappers/index.cjs +1 -1
  1226. package/row-mappers/index.cjs.map +1 -1
  1227. package/row-mappers/index.js +1 -1
  1228. package/row-mappers/index.js.map +1 -1
  1229. package/singlestore/driver.cjs +4 -2
  1230. package/singlestore/driver.cjs.map +1 -1
  1231. package/singlestore/driver.d.cts +2 -1
  1232. package/singlestore/driver.d.ts +3 -2
  1233. package/singlestore/driver.js +4 -2
  1234. package/singlestore/driver.js.map +1 -1
  1235. package/singlestore/session.cjs +16 -6
  1236. package/singlestore/session.cjs.map +1 -1
  1237. package/singlestore/session.d.cts +8 -4
  1238. package/singlestore/session.d.ts +8 -4
  1239. package/singlestore/session.js +17 -7
  1240. package/singlestore/session.js.map +1 -1
  1241. package/singlestore-core/columns/bigint.cjs +4 -4
  1242. package/singlestore-core/columns/bigint.cjs.map +1 -1
  1243. package/singlestore-core/columns/bigint.d.cts +2 -2
  1244. package/singlestore-core/columns/bigint.d.ts +2 -2
  1245. package/singlestore-core/columns/bigint.js +4 -4
  1246. package/singlestore-core/columns/bigint.js.map +1 -1
  1247. package/singlestore-core/columns/binary.cjs +2 -2
  1248. package/singlestore-core/columns/binary.cjs.map +1 -1
  1249. package/singlestore-core/columns/binary.d.cts +1 -1
  1250. package/singlestore-core/columns/binary.d.ts +1 -1
  1251. package/singlestore-core/columns/binary.js +2 -2
  1252. package/singlestore-core/columns/binary.js.map +1 -1
  1253. package/singlestore-core/columns/boolean.cjs +2 -2
  1254. package/singlestore-core/columns/boolean.cjs.map +1 -1
  1255. package/singlestore-core/columns/boolean.d.cts +1 -1
  1256. package/singlestore-core/columns/boolean.d.ts +1 -1
  1257. package/singlestore-core/columns/boolean.js +2 -2
  1258. package/singlestore-core/columns/boolean.js.map +1 -1
  1259. package/singlestore-core/columns/custom.cjs +4 -4
  1260. package/singlestore-core/columns/custom.cjs.map +1 -1
  1261. package/singlestore-core/columns/custom.d.cts +2 -2
  1262. package/singlestore-core/columns/custom.d.ts +2 -2
  1263. package/singlestore-core/columns/custom.js +4 -4
  1264. package/singlestore-core/columns/custom.js.map +1 -1
  1265. package/singlestore-core/columns/date.cjs +2 -2
  1266. package/singlestore-core/columns/date.cjs.map +1 -1
  1267. package/singlestore-core/columns/date.d.cts +1 -1
  1268. package/singlestore-core/columns/date.d.ts +1 -1
  1269. package/singlestore-core/columns/date.js +2 -2
  1270. package/singlestore-core/columns/date.js.map +1 -1
  1271. package/singlestore-core/columns/datetime.cjs +6 -6
  1272. package/singlestore-core/columns/datetime.cjs.map +1 -1
  1273. package/singlestore-core/columns/datetime.d.cts +3 -3
  1274. package/singlestore-core/columns/datetime.d.ts +3 -3
  1275. package/singlestore-core/columns/datetime.js +6 -6
  1276. package/singlestore-core/columns/datetime.js.map +1 -1
  1277. package/singlestore-core/columns/decimal.cjs +4 -4
  1278. package/singlestore-core/columns/decimal.cjs.map +1 -1
  1279. package/singlestore-core/columns/decimal.d.cts +2 -2
  1280. package/singlestore-core/columns/decimal.d.ts +2 -2
  1281. package/singlestore-core/columns/decimal.js +4 -4
  1282. package/singlestore-core/columns/decimal.js.map +1 -1
  1283. package/singlestore-core/columns/float.cjs +2 -2
  1284. package/singlestore-core/columns/float.cjs.map +1 -1
  1285. package/singlestore-core/columns/float.d.cts +1 -1
  1286. package/singlestore-core/columns/float.d.ts +1 -1
  1287. package/singlestore-core/columns/float.js +2 -2
  1288. package/singlestore-core/columns/float.js.map +1 -1
  1289. package/singlestore-core/columns/int.cjs +2 -2
  1290. package/singlestore-core/columns/int.cjs.map +1 -1
  1291. package/singlestore-core/columns/int.d.cts +1 -1
  1292. package/singlestore-core/columns/int.d.ts +1 -1
  1293. package/singlestore-core/columns/int.js +2 -2
  1294. package/singlestore-core/columns/int.js.map +1 -1
  1295. package/singlestore-core/columns/json.cjs +2 -2
  1296. package/singlestore-core/columns/json.cjs.map +1 -1
  1297. package/singlestore-core/columns/json.d.cts +1 -1
  1298. package/singlestore-core/columns/json.d.ts +1 -1
  1299. package/singlestore-core/columns/json.js +2 -2
  1300. package/singlestore-core/columns/json.js.map +1 -1
  1301. package/singlestore-core/columns/mediumint.cjs +2 -2
  1302. package/singlestore-core/columns/mediumint.cjs.map +1 -1
  1303. package/singlestore-core/columns/mediumint.d.cts +1 -1
  1304. package/singlestore-core/columns/mediumint.d.ts +1 -1
  1305. package/singlestore-core/columns/mediumint.js +2 -2
  1306. package/singlestore-core/columns/mediumint.js.map +1 -1
  1307. package/singlestore-core/columns/serial.cjs +2 -2
  1308. package/singlestore-core/columns/serial.cjs.map +1 -1
  1309. package/singlestore-core/columns/serial.d.cts +1 -1
  1310. package/singlestore-core/columns/serial.d.ts +1 -1
  1311. package/singlestore-core/columns/serial.js +2 -2
  1312. package/singlestore-core/columns/serial.js.map +1 -1
  1313. package/singlestore-core/columns/smallint.cjs +2 -2
  1314. package/singlestore-core/columns/smallint.cjs.map +1 -1
  1315. package/singlestore-core/columns/smallint.d.cts +1 -1
  1316. package/singlestore-core/columns/smallint.d.ts +1 -1
  1317. package/singlestore-core/columns/smallint.js +2 -2
  1318. package/singlestore-core/columns/smallint.js.map +1 -1
  1319. package/singlestore-core/columns/timestamp.cjs +6 -6
  1320. package/singlestore-core/columns/timestamp.cjs.map +1 -1
  1321. package/singlestore-core/columns/timestamp.d.cts +3 -3
  1322. package/singlestore-core/columns/timestamp.d.ts +3 -3
  1323. package/singlestore-core/columns/timestamp.js +6 -6
  1324. package/singlestore-core/columns/timestamp.js.map +1 -1
  1325. package/singlestore-core/columns/tinyint.cjs +2 -2
  1326. package/singlestore-core/columns/tinyint.cjs.map +1 -1
  1327. package/singlestore-core/columns/tinyint.d.cts +1 -1
  1328. package/singlestore-core/columns/tinyint.d.ts +1 -1
  1329. package/singlestore-core/columns/tinyint.js +2 -2
  1330. package/singlestore-core/columns/tinyint.js.map +1 -1
  1331. package/singlestore-core/columns/varbinary.cjs +2 -2
  1332. package/singlestore-core/columns/varbinary.cjs.map +1 -1
  1333. package/singlestore-core/columns/varbinary.d.cts +1 -1
  1334. package/singlestore-core/columns/varbinary.d.ts +1 -1
  1335. package/singlestore-core/columns/varbinary.js +2 -2
  1336. package/singlestore-core/columns/varbinary.js.map +1 -1
  1337. package/singlestore-core/columns/vector.cjs +8 -8
  1338. package/singlestore-core/columns/vector.cjs.map +1 -1
  1339. package/singlestore-core/columns/vector.d.cts +4 -4
  1340. package/singlestore-core/columns/vector.d.ts +4 -4
  1341. package/singlestore-core/columns/vector.js +8 -8
  1342. package/singlestore-core/columns/vector.js.map +1 -1
  1343. package/singlestore-core/columns/year.cjs +2 -2
  1344. package/singlestore-core/columns/year.cjs.map +1 -1
  1345. package/singlestore-core/columns/year.d.cts +1 -1
  1346. package/singlestore-core/columns/year.d.ts +1 -1
  1347. package/singlestore-core/columns/year.js +2 -2
  1348. package/singlestore-core/columns/year.js.map +1 -1
  1349. package/singlestore-core/db.d.ts +1 -1
  1350. package/singlestore-core/dialect.cjs +1 -1
  1351. package/singlestore-core/dialect.d.ts +1 -1
  1352. package/singlestore-core/dialect.js +1 -1
  1353. package/singlestore-core/query-builders/query.cjs +13 -5
  1354. package/singlestore-core/query-builders/query.cjs.map +1 -1
  1355. package/singlestore-core/query-builders/query.d.ts +1 -1
  1356. package/singlestore-core/query-builders/query.js +13 -5
  1357. package/singlestore-core/query-builders/query.js.map +1 -1
  1358. package/singlestore-core/query-builders/select.cjs +4 -0
  1359. package/singlestore-core/query-builders/select.cjs.map +1 -1
  1360. package/singlestore-core/query-builders/select.js +4 -0
  1361. package/singlestore-core/query-builders/select.js.map +1 -1
  1362. package/singlestore-core/session.cjs.map +1 -1
  1363. package/singlestore-core/session.d.cts +2 -2
  1364. package/singlestore-core/session.d.ts +2 -2
  1365. package/singlestore-core/session.js.map +1 -1
  1366. package/singlestore-core/table.cjs +1 -1
  1367. package/singlestore-core/table.cjs.map +1 -1
  1368. package/singlestore-core/table.js +1 -1
  1369. package/singlestore-core/table.js.map +1 -1
  1370. package/singlestore-proxy/driver.cjs +5 -2
  1371. package/singlestore-proxy/driver.cjs.map +1 -1
  1372. package/singlestore-proxy/driver.js +5 -2
  1373. package/singlestore-proxy/driver.js.map +1 -1
  1374. package/singlestore-proxy/session.cjs +11 -6
  1375. package/singlestore-proxy/session.cjs.map +1 -1
  1376. package/singlestore-proxy/session.d.cts +9 -4
  1377. package/singlestore-proxy/session.d.ts +9 -4
  1378. package/singlestore-proxy/session.js +12 -7
  1379. package/singlestore-proxy/session.js.map +1 -1
  1380. package/sql/index.cjs +1 -0
  1381. package/sql/index.d.cts +2 -2
  1382. package/sql/index.d.ts +2 -2
  1383. package/sql/index.js +2 -2
  1384. package/sql/sql.cjs +32 -11
  1385. package/sql/sql.cjs.map +1 -1
  1386. package/sql/sql.d.cts +15 -5
  1387. package/sql/sql.d.ts +15 -5
  1388. package/sql/sql.js +32 -12
  1389. package/sql/sql.js.map +1 -1
  1390. package/sql-js/driver.cjs +5 -2
  1391. package/sql-js/driver.cjs.map +1 -1
  1392. package/sql-js/driver.d.ts +1 -1
  1393. package/sql-js/driver.js +5 -2
  1394. package/sql-js/driver.js.map +1 -1
  1395. package/sql-js/session.cjs +14 -14
  1396. package/sql-js/session.cjs.map +1 -1
  1397. package/sql-js/session.d.cts +10 -6
  1398. package/sql-js/session.d.ts +10 -6
  1399. package/sql-js/session.js +15 -15
  1400. package/sql-js/session.js.map +1 -1
  1401. package/sqlite-cloud/driver.cjs +3 -2
  1402. package/sqlite-cloud/driver.cjs.map +1 -1
  1403. package/sqlite-cloud/driver.d.ts +1 -1
  1404. package/sqlite-cloud/driver.js +3 -2
  1405. package/sqlite-cloud/driver.js.map +1 -1
  1406. package/sqlite-cloud/session.cjs +20 -19
  1407. package/sqlite-cloud/session.cjs.map +1 -1
  1408. package/sqlite-cloud/session.d.cts +9 -6
  1409. package/sqlite-cloud/session.d.ts +9 -6
  1410. package/sqlite-cloud/session.js +21 -20
  1411. package/sqlite-cloud/session.js.map +1 -1
  1412. package/sqlite-core/columns/blob.cjs +10 -10
  1413. package/sqlite-core/columns/blob.cjs.map +1 -1
  1414. package/sqlite-core/columns/blob.d.cts +5 -5
  1415. package/sqlite-core/columns/blob.d.ts +5 -5
  1416. package/sqlite-core/columns/blob.js +10 -10
  1417. package/sqlite-core/columns/blob.js.map +1 -1
  1418. package/sqlite-core/columns/custom.cjs +4 -4
  1419. package/sqlite-core/columns/custom.cjs.map +1 -1
  1420. package/sqlite-core/columns/custom.d.cts +2 -2
  1421. package/sqlite-core/columns/custom.d.ts +2 -2
  1422. package/sqlite-core/columns/custom.js +4 -4
  1423. package/sqlite-core/columns/custom.js.map +1 -1
  1424. package/sqlite-core/columns/integer.cjs +8 -8
  1425. package/sqlite-core/columns/integer.cjs.map +1 -1
  1426. package/sqlite-core/columns/integer.d.cts +4 -4
  1427. package/sqlite-core/columns/integer.d.ts +4 -4
  1428. package/sqlite-core/columns/integer.js +8 -8
  1429. package/sqlite-core/columns/integer.js.map +1 -1
  1430. package/sqlite-core/columns/numeric.cjs +4 -4
  1431. package/sqlite-core/columns/numeric.cjs.map +1 -1
  1432. package/sqlite-core/columns/numeric.d.cts +2 -2
  1433. package/sqlite-core/columns/numeric.d.ts +2 -2
  1434. package/sqlite-core/columns/numeric.js +4 -4
  1435. package/sqlite-core/columns/numeric.js.map +1 -1
  1436. package/sqlite-core/columns/text.cjs +4 -4
  1437. package/sqlite-core/columns/text.cjs.map +1 -1
  1438. package/sqlite-core/columns/text.d.cts +2 -2
  1439. package/sqlite-core/columns/text.d.ts +2 -2
  1440. package/sqlite-core/columns/text.js +4 -4
  1441. package/sqlite-core/columns/text.js.map +1 -1
  1442. package/sqlite-core/db.d.ts +1 -1
  1443. package/sqlite-core/dialect.cjs +2 -2
  1444. package/sqlite-core/dialect.d.ts +1 -1
  1445. package/sqlite-core/dialect.js +2 -2
  1446. package/sqlite-core/query-builders/_query.cjs +1 -1
  1447. package/sqlite-core/query-builders/_query.cjs.map +1 -1
  1448. package/sqlite-core/query-builders/_query.js +1 -1
  1449. package/sqlite-core/query-builders/_query.js.map +1 -1
  1450. package/sqlite-core/query-builders/delete.cjs +1 -1
  1451. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  1452. package/sqlite-core/query-builders/delete.js +1 -1
  1453. package/sqlite-core/query-builders/delete.js.map +1 -1
  1454. package/sqlite-core/query-builders/insert.cjs +1 -1
  1455. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  1456. package/sqlite-core/query-builders/insert.js +1 -1
  1457. package/sqlite-core/query-builders/insert.js.map +1 -1
  1458. package/sqlite-core/query-builders/query.cjs +13 -5
  1459. package/sqlite-core/query-builders/query.cjs.map +1 -1
  1460. package/sqlite-core/query-builders/query.d.ts +1 -1
  1461. package/sqlite-core/query-builders/query.js +13 -5
  1462. package/sqlite-core/query-builders/query.js.map +1 -1
  1463. package/sqlite-core/query-builders/raw.cjs +0 -4
  1464. package/sqlite-core/query-builders/raw.cjs.map +1 -1
  1465. package/sqlite-core/query-builders/raw.js +0 -4
  1466. package/sqlite-core/query-builders/raw.js.map +1 -1
  1467. package/sqlite-core/query-builders/select.cjs +5 -1
  1468. package/sqlite-core/query-builders/select.cjs.map +1 -1
  1469. package/sqlite-core/query-builders/select.js +5 -1
  1470. package/sqlite-core/query-builders/select.js.map +1 -1
  1471. package/sqlite-core/query-builders/update.cjs +1 -1
  1472. package/sqlite-core/query-builders/update.cjs.map +1 -1
  1473. package/sqlite-core/query-builders/update.js +1 -1
  1474. package/sqlite-core/query-builders/update.js.map +1 -1
  1475. package/sqlite-core/session.cjs +8 -8
  1476. package/sqlite-core/session.cjs.map +1 -1
  1477. package/sqlite-core/session.d.cts +5 -5
  1478. package/sqlite-core/session.d.ts +5 -5
  1479. package/sqlite-core/session.js +8 -8
  1480. package/sqlite-core/session.js.map +1 -1
  1481. package/sqlite-core/table.cjs +1 -1
  1482. package/sqlite-core/table.cjs.map +1 -1
  1483. package/sqlite-core/table.js +1 -1
  1484. package/sqlite-core/table.js.map +1 -1
  1485. package/sqlite-proxy/driver.cjs +3 -2
  1486. package/sqlite-proxy/driver.cjs.map +1 -1
  1487. package/sqlite-proxy/driver.d.ts +1 -1
  1488. package/sqlite-proxy/driver.js +3 -2
  1489. package/sqlite-proxy/driver.js.map +1 -1
  1490. package/sqlite-proxy/session.cjs +19 -16
  1491. package/sqlite-proxy/session.cjs.map +1 -1
  1492. package/sqlite-proxy/session.d.cts +11 -7
  1493. package/sqlite-proxy/session.d.ts +11 -7
  1494. package/sqlite-proxy/session.js +20 -17
  1495. package/sqlite-proxy/session.js.map +1 -1
  1496. package/table.d.cts +1 -1
  1497. package/table.d.ts +1 -1
  1498. package/tidb-serverless/driver.cjs +3 -2
  1499. package/tidb-serverless/driver.cjs.map +1 -1
  1500. package/tidb-serverless/driver.d.cts +1 -0
  1501. package/tidb-serverless/driver.d.ts +1 -0
  1502. package/tidb-serverless/driver.js +3 -2
  1503. package/tidb-serverless/driver.js.map +1 -1
  1504. package/tidb-serverless/session.cjs +24 -36
  1505. package/tidb-serverless/session.cjs.map +1 -1
  1506. package/tidb-serverless/session.d.cts +10 -4
  1507. package/tidb-serverless/session.d.ts +11 -5
  1508. package/tidb-serverless/session.js +25 -37
  1509. package/tidb-serverless/session.js.map +1 -1
  1510. package/tursodatabase/driver-core.cjs +3 -2
  1511. package/tursodatabase/driver-core.cjs.map +1 -1
  1512. package/tursodatabase/driver-core.d.ts +1 -1
  1513. package/tursodatabase/driver-core.js +3 -2
  1514. package/tursodatabase/driver-core.js.map +1 -1
  1515. package/tursodatabase/session.cjs +19 -18
  1516. package/tursodatabase/session.cjs.map +1 -1
  1517. package/tursodatabase/session.d.cts +9 -6
  1518. package/tursodatabase/session.d.ts +9 -6
  1519. package/tursodatabase/session.js +20 -19
  1520. package/tursodatabase/session.js.map +1 -1
  1521. package/up-migrations/effect-pg.cjs +3 -3
  1522. package/up-migrations/effect-pg.cjs.map +1 -1
  1523. package/up-migrations/effect-pg.js +3 -3
  1524. package/up-migrations/effect-pg.js.map +1 -1
  1525. package/up-migrations/pg.cjs +3 -8
  1526. package/up-migrations/pg.cjs.map +1 -1
  1527. package/up-migrations/pg.d.cts +1 -1
  1528. package/up-migrations/pg.d.ts +1 -1
  1529. package/up-migrations/pg.js +3 -8
  1530. package/up-migrations/pg.js.map +1 -1
  1531. package/up-migrations/sqlite.d.ts +2 -2
  1532. package/utils.cjs +128 -6
  1533. package/utils.cjs.map +1 -1
  1534. package/utils.d.cts +10 -3
  1535. package/utils.d.ts +10 -3
  1536. package/utils.js +126 -7
  1537. package/utils.js.map +1 -1
  1538. package/vercel-postgres/driver.cjs +14 -32
  1539. package/vercel-postgres/driver.cjs.map +1 -1
  1540. package/vercel-postgres/driver.d.cts +12 -17
  1541. package/vercel-postgres/driver.d.ts +13 -18
  1542. package/vercel-postgres/driver.js +14 -31
  1543. package/vercel-postgres/driver.js.map +1 -1
  1544. package/vercel-postgres/index.cjs +2 -3
  1545. package/vercel-postgres/index.d.cts +3 -3
  1546. package/vercel-postgres/index.d.ts +3 -3
  1547. package/vercel-postgres/index.js +3 -3
  1548. package/vercel-postgres/migrator.cjs.map +1 -1
  1549. package/vercel-postgres/migrator.d.cts +1 -1
  1550. package/vercel-postgres/migrator.d.ts +1 -1
  1551. package/vercel-postgres/migrator.js.map +1 -1
  1552. package/vercel-postgres/session.cjs +32 -110
  1553. package/vercel-postgres/session.cjs.map +1 -1
  1554. package/vercel-postgres/session.d.cts +9 -32
  1555. package/vercel-postgres/session.d.ts +9 -32
  1556. package/vercel-postgres/session.js +34 -111
  1557. package/vercel-postgres/session.js.map +1 -1
  1558. package/xata-http/driver.cjs +91 -31
  1559. package/xata-http/driver.cjs.map +1 -1
  1560. package/xata-http/driver.d.cts +10 -16
  1561. package/xata-http/driver.d.ts +11 -17
  1562. package/xata-http/driver.js +91 -30
  1563. package/xata-http/driver.js.map +1 -1
  1564. package/xata-http/index.cjs +2 -4
  1565. package/xata-http/index.d.cts +3 -3
  1566. package/xata-http/index.d.ts +3 -3
  1567. package/xata-http/index.js +3 -3
  1568. package/xata-http/migrator.cjs +1 -1
  1569. package/xata-http/migrator.cjs.map +1 -1
  1570. package/xata-http/migrator.d.cts +1 -1
  1571. package/xata-http/migrator.d.ts +1 -1
  1572. package/xata-http/migrator.js +1 -1
  1573. package/xata-http/migrator.js.map +1 -1
  1574. package/xata-http/session.cjs +23 -109
  1575. package/xata-http/session.cjs.map +1 -1
  1576. package/xata-http/session.d.cts +7 -33
  1577. package/xata-http/session.d.ts +6 -32
  1578. package/xata-http/session.js +25 -109
  1579. package/xata-http/session.js.map +1 -1
  1580. package/pg-core/query-builders/_query.cjs +0 -101
  1581. package/pg-core/query-builders/_query.cjs.map +0 -1
  1582. package/pg-core/query-builders/_query.d.cts +0 -55
  1583. package/pg-core/query-builders/_query.d.ts +0 -55
  1584. package/pg-core/query-builders/_query.js +0 -97
  1585. package/pg-core/query-builders/_query.js.map +0 -1
  1586. package/pg-core/utils/array.cjs.map +0 -1
  1587. package/pg-core/utils/array.js.map +0 -1
  1588. package/pg-core/utils/index.cjs +0 -6
  1589. package/pg-core/utils/index.d.cts +0 -2
  1590. package/pg-core/utils/index.d.ts +0 -2
  1591. package/pg-core/utils/index.js +0 -3
@@ -1 +1 @@
1
- {"version":3,"file":"effect-pg.cjs","names":["Effect","sql"],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.all(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.all<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
1
+ {"version":3,"file":"effect-pg.cjs","names":["Effect","sql"],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.objects(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.objects<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
@@ -14,7 +14,7 @@ function getVersion(columns) {
14
14
  const upgradeFunctions = { 0: (migrationsSchema, migrationsTable, session, localMigrations) => {
15
15
  return Effect.gen(function* () {
16
16
  const table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;
17
- const dbRows = yield* session.all(sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
17
+ const dbRows = yield* session.objects(sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
18
18
  localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
19
19
  const byMillis = /* @__PURE__ */ new Map();
20
20
  const byHash = /* @__PURE__ */ new Map();
@@ -54,10 +54,10 @@ const upgradeFunctions = { 0: (migrationsSchema, migrationsTable, session, local
54
54
  * Version 1: Extended schema (id, hash, created_at, name, applied_at)
55
55
  */
56
56
  const upgradeIfNeeded = Effect.fn("upgradeIfNeeded")(function* (migrationsSchema, migrationsTable, session, localMigrations) {
57
- if ((yield* session.all(sql`SELECT 1 FROM information_schema.tables
57
+ if ((yield* session.objects(sql`SELECT 1 FROM information_schema.tables
58
58
  WHERE table_schema = ${migrationsSchema}
59
59
  AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
60
- const version = getVersion((yield* session.all(sql`SELECT
60
+ const version = getVersion((yield* session.objects(sql`SELECT
61
61
  n.nspname AS "schema",
62
62
  c.relname AS "table_name",
63
63
  a.attname AS "column_name",
@@ -1 +1 @@
1
- {"version":3,"file":"effect-pg.js","names":[],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.all(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.all<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
1
+ {"version":3,"file":"effect-pg.js","names":[],"sources":["../../src/up-migrations/effect-pg.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { QueryEffectHKTBase } from '~/effect-core/query-effect.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { PgEffectSession } from '~/pg-core/effect/session.ts';\nimport { sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) => Effect.Effect<void, TEffectHKT['error'], TEffectHKT['context']>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: (migrationsSchema, migrationsTable, session, localMigrations) => {\n\t\treturn Effect.gen(function*() {\n\t\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t\t// 1. Read all existing DB migrations\n\t\t\t// Sort them by ids asc (order how they were applied)\n\t\t\tconst dbRows = yield* session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t\t);\n\n\t\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\t\tlocalMigrations.sort((a, b) =>\n\t\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t\t);\n\n\t\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\t\tfor (const lm of localMigrations) {\n\t\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t\t}\n\t\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\t\tbyHash.set(lm.hash, lm);\n\t\t\t}\n\n\t\t\t// 3. Match each DB row to a local migration\n\t\t\t// Priority: millis -> hash\n\t\t\tconst toApply: { id: number; name: string }[] = [];\n\t\t\tlet unmatchedIds: number[] = [];\n\n\t\t\tfor (const dbRow of dbRows) {\n\t\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\t\tmatched = candidates[0];\n\t\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t\t} else {\n\t\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t\t}\n\n\t\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t\t}\n\n\t\t\t// 4. Check for unmatched\n\t\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\t\tif (unmatchedIds.length > 0) {\n\t\t\t\tthrow Error(\n\t\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Create extra column and backfill names for matched migrations\n\t\t\tyield* session.transaction((tx) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tyield* tx.execute(sql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`);\n\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t\t\t\t);\n\n\t\t\t\t\tfor (const backfillEntry of toApply) {\n\t\t\t\t\t\tyield* tx.execute(\n\t\t\t\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${backfillEntry.name}, ${\n\t\t\t\t\t\t\t\tsql.identifier('applied_at')\n\t\t\t\t\t\t\t} = NULL WHERE ${sql.identifier('id')} = ${backfillEntry.id}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport const upgradeIfNeeded: <TEffectHKT extends QueryEffectHKTBase>(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tsession: PgEffectSession<TEffectHKT>,\n\tlocalMigrations: MigrationMeta[],\n) => Effect.Effect<UpgradeResult, TEffectHKT['error'], TEffectHKT['context']> = Effect.fn('upgradeIfNeeded')(\n\tfunction*<TEffectHKT extends QueryEffectHKTBase>(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tsession: PgEffectSession<TEffectHKT>,\n\t\tlocalMigrations: MigrationMeta[],\n\t) {\n\t\t// Check if the table exists at all\n\t\tconst result = yield* session.objects(\n\t\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t\t);\n\n\t\tif (result.length === 0) {\n\t\t\treturn { newDb: true };\n\t\t}\n\n\t\t// Table exists, check table shape\n\t\tconst rows = yield* session.objects<{ schema: string; table_name: string; column_name: string; type: string }>(\n\t\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t\t);\n\n\t\tconst version = getVersion(rows.map((r) => r.column_name));\n\n\t\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\t\tconst upgradeFn = upgradeFunctions[v];\n\t\t\tif (!upgradeFn) {\n\t\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t\t}\n\t\t\tyield* upgradeFn(migrationsSchema, migrationsTable, session, localMigrations);\n\t\t}\n\n\t\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n\t},\n);\n"],"mappings":"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"}
@@ -8,18 +8,13 @@ function getVersion(columns) {
8
8
  if (columns.includes("name")) return 1;
9
9
  return 0;
10
10
  }
11
- async function execute(session, sql) {
12
- const result = await session.execute(sql);
13
- if ("rows" in result) return result.rows;
14
- return result;
15
- }
16
11
  /**
17
12
  * Map of upgrade functions. Each key is the version being upgraded FROM,
18
13
  * and the function upgrades the table to the next version.
19
14
  */
20
15
  const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {
21
16
  const table = __sql_sql_ts.sql`${__sql_sql_ts.sql.identifier(migrationsSchema)}.${__sql_sql_ts.sql.identifier(migrationsTable)}`;
22
- const dbRows = await execute(db.session, __sql_sql_ts.sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
17
+ const dbRows = await db.session.objects(__sql_sql_ts.sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
23
18
  localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
24
19
  const byMillis = /* @__PURE__ */ new Map();
25
20
  const byHash = /* @__PURE__ */ new Map();
@@ -62,10 +57,10 @@ const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, loca
62
57
  * Version 1: Extended schema (id, hash, created_at, name, applied_at)
63
58
  */
64
59
  async function upgradeIfNeeded(migrationsSchema, migrationsTable, db, localMigrations, mode = "transaction") {
65
- if ((await execute(db.session, __sql_sql_ts.sql`SELECT 1 FROM information_schema.tables
60
+ if ((await db.session.objects(__sql_sql_ts.sql`SELECT 1 FROM information_schema.tables
66
61
  WHERE table_schema = ${migrationsSchema}
67
62
  AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
68
- let version = getVersion((await execute(db.session, __sql_sql_ts.sql`SELECT
63
+ let version = getVersion((await db.session.objects(__sql_sql_ts.sql`SELECT
69
64
  n.nspname AS "schema",
70
65
  c.relname AS "table_name",
71
66
  a.attname AS "column_name",
@@ -1 +1 @@
1
- {"version":3,"file":"pg.cjs","names":["sql"],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { TablesRelationalConfig } from '~/_relations.ts';\nimport type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { NeonHttpSession } from '~/neon-http/session.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncSession, PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\nimport type { XataHttpSession } from '~/xata-http/session.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n// postgres.js returns array of objects\n// pg-proxy returns arrays of objects\n// node-postgres returns { rows: array of objects }\nasync function execute<T extends any[]>(\n\tsession:\n\t\t| PgAsyncSession\n\t\t| NeonHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>\n\t\t| XataHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>,\n\tsql: SQL,\n): Promise<T> {\n\tconst result: { rows: T } | T = await session.execute(sql);\n\tif ('rows' in result) return result.rows;\n\treturn result;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await execute<{ id: number; hash: string; created_at: string }[]>(\n\t\t\tdb.session,\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await execute<{ '1': 1 }[]>(\n\t\tdb.session,\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await execute<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }[]\n\t>(\n\t\tdb.session,\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"pg.cjs","names":["sql"],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await db.session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await db.session.objects<{ '1': 1 }>(\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await db.session.objects<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }\n\t>(\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
@@ -14,7 +14,7 @@ interface UpgradeResult {
14
14
  * Version 0: Original schema (id, hash, created_at)
15
15
  * Version 1: Extended schema (id, hash, created_at, name, applied_at)
16
16
  */
17
- declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any, any, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
17
+ declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
18
18
  //#endregion
19
19
  export { upgradeIfNeeded };
20
20
  //# sourceMappingURL=pg.d.cts.map
@@ -14,7 +14,7 @@ interface UpgradeResult {
14
14
  * Version 0: Original schema (id, hash, created_at)
15
15
  * Version 1: Extended schema (id, hash, created_at, name, applied_at)
16
16
  */
17
- declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any, any, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
17
+ declare function upgradeIfNeeded(migrationsSchema: string, migrationsTable: string, db: PgAsyncDatabase<PgQueryResultHKT, any>, localMigrations: MigrationMeta[], mode?: 'transaction' | 'execute' | 'batch'): Promise<UpgradeResult>;
18
18
  //#endregion
19
19
  export { upgradeIfNeeded };
20
20
  //# sourceMappingURL=pg.d.ts.map
@@ -6,18 +6,13 @@ function getVersion(columns) {
6
6
  if (columns.includes("name")) return 1;
7
7
  return 0;
8
8
  }
9
- async function execute(session, sql) {
10
- const result = await session.execute(sql);
11
- if ("rows" in result) return result.rows;
12
- return result;
13
- }
14
9
  /**
15
10
  * Map of upgrade functions. Each key is the version being upgraded FROM,
16
11
  * and the function upgrades the table to the next version.
17
12
  */
18
13
  const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {
19
14
  const table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;
20
- const dbRows = await execute(db.session, sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
15
+ const dbRows = await db.session.objects(sql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`);
21
16
  localMigrations.sort((a, b) => a.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? "").localeCompare(b.name ?? ""));
22
17
  const byMillis = /* @__PURE__ */ new Map();
23
18
  const byHash = /* @__PURE__ */ new Map();
@@ -60,10 +55,10 @@ const upgradeFunctions = { 0: async (migrationsSchema, migrationsTable, db, loca
60
55
  * Version 1: Extended schema (id, hash, created_at, name, applied_at)
61
56
  */
62
57
  async function upgradeIfNeeded(migrationsSchema, migrationsTable, db, localMigrations, mode = "transaction") {
63
- if ((await execute(db.session, sql`SELECT 1 FROM information_schema.tables
58
+ if ((await db.session.objects(sql`SELECT 1 FROM information_schema.tables
64
59
  WHERE table_schema = ${migrationsSchema}
65
60
  AND table_name = ${migrationsTable}`)).length === 0) return { newDb: true };
66
- let version = getVersion((await execute(db.session, sql`SELECT
61
+ let version = getVersion((await db.session.objects(sql`SELECT
67
62
  n.nspname AS "schema",
68
63
  c.relname AS "table_name",
69
64
  a.attname AS "column_name",
@@ -1 +1 @@
1
- {"version":3,"file":"pg.js","names":[],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { TablesRelationalConfig } from '~/_relations.ts';\nimport type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { NeonHttpSession } from '~/neon-http/session.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncSession, PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\nimport type { XataHttpSession } from '~/xata-http/session.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n// postgres.js returns array of objects\n// pg-proxy returns arrays of objects\n// node-postgres returns { rows: array of objects }\nasync function execute<T extends any[]>(\n\tsession:\n\t\t| PgAsyncSession\n\t\t| NeonHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>\n\t\t| XataHttpSession<Record<string, unknown>, AnyRelations, TablesRelationalConfig>,\n\tsql: SQL,\n): Promise<T> {\n\tconst result: { rows: T } | T = await session.execute(sql);\n\tif ('rows' in result) return result.rows;\n\treturn result;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await execute<{ id: number; hash: string; created_at: string }[]>(\n\t\t\tdb.session,\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any, any, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await execute<{ '1': 1 }[]>(\n\t\tdb.session,\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await execute<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }[]\n\t>(\n\t\tdb.session,\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"pg.js","names":[],"sources":["../../src/up-migrations/pg.ts"],"sourcesContent":["import type { BatchItem } from '~/batch.ts';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { NeonHttpDatabase } from '~/neon-http/driver.ts';\nimport type { PgAsyncDatabase } from '~/pg-core/async/db.ts';\nimport type { PgAsyncTransaction } from '~/pg-core/async/session.ts';\nimport type { PgQueryResultHKT } from '~/pg-core/session.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\nconst CURRENT_MIGRATION_TABLE_VERSION = 1;\n\ninterface UpgradeResult {\n\tnewDb?: boolean;\n\tprevVersion?: number;\n\tcurrentVersion?: number;\n}\n\nfunction getVersion(columns: string[]) {\n\tif (columns.includes('name')) return 1;\n\treturn 0;\n}\n\n/**\n * Map of upgrade functions. Each key is the version being upgraded FROM,\n * and the function upgrades the table to the next version.\n */\nconst upgradeFunctions: Record<\n\tnumber,\n\t(\n\t\tmigrationsSchema: string,\n\t\tmigrationsTable: string,\n\t\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\t\tlocalMigrations: MigrationMeta[],\n\t\tmode: 'transaction' | 'execute' | 'batch',\n\t) => Promise<void>\n> = {\n\t/**\n\t * Upgrade from version 0 to version 1:\n\t * 1. Read all existing DB migrations\n\t * 2. Sort localMigrations ASC by millis and if the same - sort by name\n\t * 3. Match each DB row to a local migration\n\t * If multiple migrations share the same second, use hash matching as a tiebreaker\n\t * Not implemented for now -> If hash matching fails, fall back to serial id ordering\n\t * 5. Create extra column and backfill names for matched migrations\n\t */\n\t0: async (migrationsSchema, migrationsTable, db, localMigrations, mode) => {\n\t\tconst table = sql`${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)}`;\n\n\t\t// 1. Read all existing DB migrations\n\t\t// Sort them by ids asc (order how they were applied)\n\t\tconst dbRows = await db.session.objects<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${table} ORDER BY id ASC`,\n\t\t);\n\n\t\t// 2. Sort ASC by millis and if the same - sort by name\n\t\tlocalMigrations.sort((a, b) =>\n\t\t\ta.folderMillis !== b.folderMillis ? a.folderMillis - b.folderMillis : (a.name ?? '').localeCompare(b.name ?? '')\n\t\t);\n\n\t\tconst byMillis = new Map<number, MigrationMeta[]>();\n\t\tconst byHash = new Map<string, MigrationMeta>();\n\t\tfor (const lm of localMigrations) {\n\t\t\tif (!byMillis.has(lm.folderMillis)) {\n\t\t\t\tbyMillis.set(lm.folderMillis, []);\n\t\t\t}\n\t\t\tbyMillis.get(lm.folderMillis)!.push(lm);\n\t\t\tbyHash.set(lm.hash, lm);\n\t\t}\n\n\t\t// \t3. Match each DB row to a local migration\n\t\t// \tPriority: millis -> hash\n\t\tconst toApply: { id: number; name: string }[] = [];\n\t\tlet unmatchedIds: number[] = [];\n\n\t\tfor (const dbRow of dbRows) {\n\t\t\tconst stringified = String(dbRow.created_at);\n\t\t\tconst millis = Number(stringified.substring(0, stringified.length - 3) + '000');\n\t\t\tconst candidates = byMillis.get(millis);\n\n\t\t\tlet matched: MigrationMeta | undefined;\n\n\t\t\tif (candidates && candidates.length === 1) {\n\t\t\t\tmatched = candidates[0];\n\t\t\t} else if (candidates && candidates.length > 1) {\n\t\t\t\tmatched = candidates.find((c) => c.hash === dbRow.hash);\n\t\t\t} else {\n\t\t\t\tmatched = byHash.get(dbRow.hash);\n\t\t\t}\n\n\t\t\tif (matched) toApply.push({ id: dbRow.id, name: matched.name });\n\t\t\telse unmatchedIds.push(dbRow.id);\n\t\t}\n\n\t\t// 4. Check for unmatched\n\t\t// Our assumption on this migration flow is that all DB entries should be matched to a local migration\n\t\t// (if same seconds - fallback to hash, if hash fails - corner case)\n\t\t// If there are unmatched entries, it means that the local environment is missing migrations that have been applied to the DB,\n\t\t// which can lead to inconsistencies and potential issues when running future migrations\n\t\tif (unmatchedIds.length > 0) {\n\t\t\tthrow Error(\n\t\t\t\t`While upgrading your database migrations table we found ${unmatchedIds.length} migrations (ids: ${\n\t\t\t\t\tunmatchedIds.join(', ')\n\t\t\t\t}) in the database that do not match any local migration. This means that some migrations were applied to the database but are missing from the local environment`,\n\t\t\t);\n\t\t}\n\n\t\t// 5. Create extra column and backfill names for matched migrations\n\t\tconst sqls: SQL[] = [\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${sql.identifier('name')} text`,\n\t\t\tsql`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${\n\t\t\t\tsql.identifier('applied_at')\n\t\t\t} timestamp with time zone DEFAULT now()`,\n\t\t];\n\t\tfor (const { id, name } of toApply) {\n\t\t\tsqls.push(\n\t\t\t\tsql`UPDATE ${table} SET ${sql.identifier('name')} = ${name}, ${sql.identifier('applied_at')} = NULL WHERE ${\n\t\t\t\t\tsql.identifier('id')\n\t\t\t\t} = ${id}`,\n\t\t\t);\n\t\t}\n\n\t\t// check if http\n\t\t// execute -> proxy, http drivers\n\t\t// transaction -> other\n\t\tif (mode === 'transaction') {\n\t\t\tawait db.transaction(async (tx: PgAsyncTransaction<any, any>) => {\n\t\t\t\tfor (const sql of sqls) {\n\t\t\t\t\tawait tx.execute(sql);\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (mode === 'batch') {\n\t\t\tconst database = db as NeonHttpDatabase;\n\n\t\t\tawait database.batch(\n\t\t\t\tsqls.map((s) => database.execute(s)) as unknown as [BatchItem<'pg'>, ...BatchItem<'pg'>[]],\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const sql of sqls) {\n\t\t\t\tawait db.execute(sql);\n\t\t\t}\n\t\t}\n\t},\n};\n\n/**\n * Detects the current version of the migrations table schema and upgrades it if needed.\n *\n * Version 0: Original schema (id, hash, created_at)\n * Version 1: Extended schema (id, hash, created_at, name, applied_at)\n */\nexport async function upgradeIfNeeded(\n\tmigrationsSchema: string,\n\tmigrationsTable: string,\n\tdb: PgAsyncDatabase<PgQueryResultHKT, any>,\n\tlocalMigrations: MigrationMeta[],\n\tmode: 'transaction' | 'execute' | 'batch' = 'transaction',\n): Promise<UpgradeResult> {\n\t// Check if the table exists at all\n\tconst result = await db.session.objects<{ '1': 1 }>(\n\t\tsql`SELECT 1 FROM information_schema.tables\n\t\t\tWHERE table_schema = ${migrationsSchema}\n\t\t\tAND table_name = ${migrationsTable}`,\n\t);\n\n\tif (result.length === 0) {\n\t\treturn { newDb: true };\n\t}\n\n\t// Table exists, check table shape\n\tconst rows = await db.session.objects<\n\t\t{ schema: string; table_name: string; column_name: string; type: string }\n\t>(\n\t\tsql`SELECT\n\t\t\tn.nspname AS \"schema\",\n\t\t\tc.relname AS \"table_name\",\n\t\t\ta.attname AS \"column_name\",\n\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) AS \"type\"\n\t\tFROM\n\t\t\tpg_catalog.pg_attribute a\n\t\t\tJOIN pg_catalog.pg_class c ON c.oid = a.attrelid\n\t\t\tJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n\t\tWHERE\n\t\t\ta.attnum > 0\n\t\t\tAND NOT a.attisdropped\n\t\t\tAND n.nspname = ${migrationsSchema}\n\t\t\tAND c.relname = ${migrationsTable}\n\t\tORDER BY a.attnum;`,\n\t);\n\n\tlet version = getVersion(rows.map((r) => r.column_name));\n\n\tfor (let v = version; v < CURRENT_MIGRATION_TABLE_VERSION; v++) {\n\t\tconst upgradeFn = upgradeFunctions[v];\n\t\tif (!upgradeFn) {\n\t\t\tthrow new Error(`No upgrade path from migration table version ${v} to ${v + 1}`);\n\t\t}\n\t\tawait upgradeFn(migrationsSchema, migrationsTable, db, localMigrations, mode);\n\t}\n\n\treturn { prevVersion: version, currentVersion: CURRENT_MIGRATION_TABLE_VERSION };\n}\n"],"mappings":"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"}
@@ -1,7 +1,7 @@
1
- import { TablesRelationalConfig } from "../_relations.js";
2
1
  import { MigrationMeta } from "../migrator.js";
3
- import { SQLiteSession } from "../sqlite-core/session.js";
2
+ import { TablesRelationalConfig } from "../_relations.js";
4
3
  import { AnyRelations } from "../relations.js";
4
+ import { SQLiteSession } from "../sqlite-core/session.js";
5
5
  import { SQLiteD1Session } from "../d1/session.js";
6
6
  import { LibSQLSession } from "../libsql/session.js";
7
7
  import { SQLiteCloudSession } from "../sqlite-cloud/session.js";
package/utils.cjs CHANGED
@@ -10,7 +10,7 @@ const require_view_common = require('./view-common.cjs');
10
10
  /** @internal */
11
11
  function mapResultRow(columns, row, joinsNotNullableMap) {
12
12
  const nullifyMap = {};
13
- const result = columns.reduce((result, { path, field }, columnIndex) => {
13
+ const result = columns.reduce((result, { path, field, codec, arrayDimensions }, columnIndex) => {
14
14
  let decoder;
15
15
  if (require_entity.is(field, require_column.Column)) decoder = field;
16
16
  else if (require_entity.is(field, require_sql_sql.SQL)) decoder = field.decoder;
@@ -22,7 +22,7 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
22
22
  node = node[pathChunk];
23
23
  } else {
24
24
  const rawValue = row[columnIndex];
25
- const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
25
+ const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(codec ? codec(rawValue, arrayDimensions) : rawValue);
26
26
  if (joinsNotNullableMap && require_entity.is(field, require_column.Column) && path.length === 2) {
27
27
  const objectName = path[0];
28
28
  if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? require_table.getTableName(field.table) : false;
@@ -37,16 +37,122 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
37
37
  return result;
38
38
  }
39
39
  /** @internal */
40
- function orderSelectedFields(fields, pathPrefix) {
40
+ function makeJitQueryMapperInner(columns, joinsNotNullableMap) {
41
+ let fn = [];
42
+ if (joinsNotNullableMap) fn.push(`const nullifyMap = {};`);
43
+ const initializedPaths = /* @__PURE__ */ new Set();
44
+ for (const [idx, { path: pathArr, field, codec, arrayDimensions }] of columns.entries()) {
45
+ const pathPrefix = pathArr.slice(0, -1);
46
+ const path = pathArr.map((e) => `[${JSON.stringify(e)}]`).join("");
47
+ let processedPath;
48
+ for (const p of pathPrefix) {
49
+ processedPath = processedPath ? `${processedPath}[${JSON.stringify(p)}]` : `[${JSON.stringify(p)}]`;
50
+ if (initializedPaths.has(processedPath)) continue;
51
+ fn.push(`res${processedPath} = {};`);
52
+ initializedPaths.add(processedPath);
53
+ }
54
+ let decoder;
55
+ let decoderStr;
56
+ if (require_entity.is(field, require_column.Column)) {
57
+ decoder = field;
58
+ decoderStr = `this.columns[${idx}].field.mapFromDriverValue`;
59
+ } else if (require_entity.is(field, require_sql_sql.SQL)) {
60
+ decoder = field.decoder;
61
+ decoderStr = `this.columns[${idx}].field.decoder.mapFromDriverValue`;
62
+ } else if (require_entity.is(field, require_subquery.Subquery)) {
63
+ decoder = field._.sql.decoder;
64
+ decoderStr = `this.columns[${idx}].field._.sql.decoder.mapFromDriverValue`;
65
+ } else {
66
+ decoder = field.sql.decoder;
67
+ decoderStr = `this.columns[${idx}].field.sql.decoder.mapFromDriverValue`;
68
+ }
69
+ if (decoder.mapFromDriverValue.isNoop) decoderStr = "";
70
+ const rowStr = `rows[i][${idx}]`;
71
+ let decodedValue = rowStr;
72
+ if (codec) decodedValue = `this.columns[${idx}].codec(${decodedValue}, ${arrayDimensions})`;
73
+ if (decoderStr) decodedValue = `${decoderStr}(${decodedValue})`;
74
+ fn.push(` res${path} = ${rowStr} === null ? ${rowStr} : ${decodedValue};`);
75
+ if (joinsNotNullableMap && require_entity.is(field, require_column.Column) && pathArr.length === 2) {
76
+ const objectName = JSON.stringify(pathArr[0]);
77
+ fn.push(`if (!(${objectName} in nullifyMap)) {`, ` nullifyMap[${objectName}] = res${path} === null ? this.getTableName(this.columns[${idx}].field.table) : false;`, `} else if (typeof nullifyMap[${objectName}] === 'string' && nullifyMap[${objectName}] !== this.getTableName(this.columns[${idx}].field.table)) {`, ` nullifyMap[${objectName}] = false;`, `}`);
78
+ }
79
+ }
80
+ if (joinsNotNullableMap) fn.push(`if(Object.keys(nullifyMap).length) {`, ` for (const [objectName, tableName] of Object.entries(nullifyMap)) {`, ` if (typeof tableName === 'string' && !this.joinsNotNullableMap[tableName]) {`, ` res[objectName] = null;`, ` }`, ` }`, `}`);
81
+ return fn.join("\n");
82
+ }
83
+ function makeJitQueryMapper(columns, joinsNotNullableMap) {
84
+ return new Function("rows", `const mapped = [];
85
+ for (let i = 0; i < rows.length; ++i) {
86
+ const res = {};
87
+ ${makeJitQueryMapperInner(columns, joinsNotNullableMap)}
88
+ mapped[i] = res;
89
+ }
90
+ return mapped;
91
+ //# sourceURL=drizzle:jit-query-mapper`).bind({
92
+ getTableName: require_table.getTableName,
93
+ columns,
94
+ joinsNotNullableMap
95
+ });
96
+ }
97
+ function makeDefaultQueryMapper(columns, joinsNotNullableMap) {
98
+ const interpretedData = columns.map(({ field, codec, arrayDimensions, path }) => {
99
+ let processNullifyMap;
100
+ let decoderSrc;
101
+ if (require_entity.is(field, require_column.Column)) {
102
+ decoderSrc = field;
103
+ if (joinsNotNullableMap && path.length === 2) {
104
+ const objectName = path[0];
105
+ processNullifyMap = (nullifyMap, value) => {
106
+ if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? require_table.getTableName(field.table) : false;
107
+ else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== require_table.getTableName(field.table)) nullifyMap[objectName] = false;
108
+ };
109
+ }
110
+ } else if (require_entity.is(field, require_sql_sql.SQL)) decoderSrc = field.decoder;
111
+ else if (require_entity.is(field, require_subquery.Subquery)) decoderSrc = field._.sql.decoder;
112
+ else decoderSrc = field.sql.decoder;
113
+ let decoder;
114
+ if (decoderSrc.mapFromDriverValue.isNoop) decoder = codec ? (v) => codec(v, arrayDimensions) : void 0;
115
+ else decoder = codec ? (v) => decoderSrc.mapFromDriverValue(codec(v, arrayDimensions)) : (v) => decoderSrc.mapFromDriverValue(v);
116
+ return [decoder, processNullifyMap];
117
+ });
118
+ return ((rows) => rows.map((row) => {
119
+ const nullifyMap = {};
120
+ const result = columns.reduce((result, { path }, columnIndex) => {
121
+ let node = result;
122
+ for (const [pathChunkIndex, pathChunk] of path.entries()) if (pathChunkIndex < path.length - 1) {
123
+ if (!(pathChunk in node)) node[pathChunk] = {};
124
+ node = node[pathChunk];
125
+ } else {
126
+ const [decoder, processNullifyMap] = interpretedData[columnIndex];
127
+ const rawValue = row[columnIndex];
128
+ const value = node[pathChunk] = rawValue === null ? null : decoder ? decoder(rawValue) : rawValue;
129
+ processNullifyMap?.(nullifyMap, value);
130
+ }
131
+ return result;
132
+ }, {});
133
+ if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
134
+ for (const [objectName, tableName] of Object.entries(nullifyMap)) if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) result[objectName] = null;
135
+ }
136
+ return result;
137
+ }));
138
+ }
139
+ /** @internal */
140
+ function orderSelectedFields(fields, pathPrefix, codecs) {
41
141
  return Object.entries(fields).reduce((result, [name, field]) => {
42
142
  if (typeof name !== "string") return result;
43
143
  const newPath = pathPrefix ? [...pathPrefix, name] : [name];
44
- if (require_entity.is(field, require_column.Column) || require_entity.is(field, require_sql_sql.SQL) || require_entity.is(field, require_sql_sql.SQL.Aliased) || require_entity.is(field, require_subquery.Subquery)) result.push({
144
+ if (require_entity.is(field, require_column.Column)) result.push({
145
+ path: newPath,
146
+ field,
147
+ codec: codecs?.get(field, "normalize"),
148
+ arrayDimensions: field.dimensions
149
+ });
150
+ else if (require_entity.is(field, require_column.Column) || require_entity.is(field, require_sql_sql.SQL) || require_entity.is(field, require_sql_sql.SQL.Aliased) || require_entity.is(field, require_subquery.Subquery)) result.push({
45
151
  path: newPath,
46
152
  field
47
153
  });
48
- else if (require_entity.is(field, require_table.Table)) result.push(...orderSelectedFields(field[require_table.Table.Symbol.Columns], newPath));
49
- else result.push(...orderSelectedFields(field, newPath));
154
+ else if (require_entity.is(field, require_table.Table)) result.push(...orderSelectedFields(field[require_table.Table.Symbol.Columns], newPath, codecs));
155
+ else result.push(...orderSelectedFields(field, newPath, codecs));
50
156
  return result;
51
157
  }, []);
52
158
  }
@@ -134,6 +240,11 @@ function isConfig(data) {
134
240
  if (type !== "object" && type !== "function" && type !== "undefined") return false;
135
241
  return true;
136
242
  }
243
+ if ("useJitMapper" in data) {
244
+ const type = typeof data["useJitMapper"];
245
+ if (type !== "boolean" && type !== "undefined") return false;
246
+ return true;
247
+ }
137
248
  if (Object.keys(data).length === 0) return true;
138
249
  return false;
139
250
  }
@@ -164,11 +275,20 @@ const CONSTANTS = {
164
275
  INT64_MAX: 9223372036854775807n,
165
276
  INT64_UNSIGNED_MAX: 18446744073709551615n
166
277
  };
278
+ function base64ToUint8Array(base64) {
279
+ if (!base64) return new Uint8Array(0);
280
+ const binary = atob(base64);
281
+ const len = binary.length;
282
+ const bytes = new Uint8Array(len);
283
+ for (let i = 0; i < len; ++i) bytes[i] = binary.charCodeAt(i);
284
+ return bytes;
285
+ }
167
286
 
168
287
  //#endregion
169
288
  exports.CONSTANTS = CONSTANTS;
170
289
  exports.applyMixins = applyMixins;
171
290
  exports.assertUnreachable = assertUnreachable;
291
+ exports.base64ToUint8Array = base64ToUint8Array;
172
292
  exports.getColumnNameAndConfig = getColumnNameAndConfig;
173
293
  exports.getColumns = getColumns;
174
294
  exports.getTableColumns = getTableColumns;
@@ -177,6 +297,8 @@ exports.getViewSelectedFields = getViewSelectedFields;
177
297
  exports.haveSameKeys = haveSameKeys;
178
298
  exports.isConfig = isConfig;
179
299
  exports.isWithEnum = isWithEnum;
300
+ exports.makeDefaultQueryMapper = makeDefaultQueryMapper;
301
+ exports.makeJitQueryMapper = makeJitQueryMapper;
180
302
  exports.mapResultRow = mapResultRow;
181
303
  exports.mapUpdateSet = mapUpdateSet;
182
304
  exports.orderSelectedFields = orderSelectedFields;