@congzhen/changewayguard 6.8.12

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 (329) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +270 -0
  3. package/dashboard-dist/api/104.index.js +1420 -0
  4. package/dashboard-dist/api/104.index.js.map +1 -0
  5. package/dashboard-dist/api/113.index.js +496 -0
  6. package/dashboard-dist/api/113.index.js.map +1 -0
  7. package/dashboard-dist/api/18.index.js +67 -0
  8. package/dashboard-dist/api/18.index.js.map +1 -0
  9. package/dashboard-dist/api/217.index.js +44 -0
  10. package/dashboard-dist/api/217.index.js.map +1 -0
  11. package/dashboard-dist/api/222.index.js +90 -0
  12. package/dashboard-dist/api/222.index.js.map +1 -0
  13. package/dashboard-dist/api/25.index.js +3562 -0
  14. package/dashboard-dist/api/25.index.js.map +1 -0
  15. package/dashboard-dist/api/280.index.js +206 -0
  16. package/dashboard-dist/api/280.index.js.map +1 -0
  17. package/dashboard-dist/api/369.index.js +115 -0
  18. package/dashboard-dist/api/369.index.js.map +1 -0
  19. package/dashboard-dist/api/377.index.js +1176 -0
  20. package/dashboard-dist/api/377.index.js.map +1 -0
  21. package/dashboard-dist/api/411.index.js +4250 -0
  22. package/dashboard-dist/api/411.index.js.map +1 -0
  23. package/dashboard-dist/api/424.index.js +135 -0
  24. package/dashboard-dist/api/424.index.js.map +1 -0
  25. package/dashboard-dist/api/573.index.js +806 -0
  26. package/dashboard-dist/api/573.index.js.map +1 -0
  27. package/dashboard-dist/api/598.index.js +328 -0
  28. package/dashboard-dist/api/598.index.js.map +1 -0
  29. package/dashboard-dist/api/62.index.js +4151 -0
  30. package/dashboard-dist/api/62.index.js.map +1 -0
  31. package/dashboard-dist/api/67.index.js +23383 -0
  32. package/dashboard-dist/api/67.index.js.map +1 -0
  33. package/dashboard-dist/api/678.index.js +2734 -0
  34. package/dashboard-dist/api/678.index.js.map +1 -0
  35. package/dashboard-dist/api/698.index.js +1896 -0
  36. package/dashboard-dist/api/698.index.js.map +1 -0
  37. package/dashboard-dist/api/720.index.js +98 -0
  38. package/dashboard-dist/api/720.index.js.map +1 -0
  39. package/dashboard-dist/api/830.index.js +95 -0
  40. package/dashboard-dist/api/830.index.js.map +1 -0
  41. package/dashboard-dist/api/831.index.js +99 -0
  42. package/dashboard-dist/api/831.index.js.map +1 -0
  43. package/dashboard-dist/api/84.index.js +64 -0
  44. package/dashboard-dist/api/84.index.js.map +1 -0
  45. package/dashboard-dist/api/900.index.js +65 -0
  46. package/dashboard-dist/api/900.index.js.map +1 -0
  47. package/dashboard-dist/api/917.index.js +88 -0
  48. package/dashboard-dist/api/917.index.js.map +1 -0
  49. package/dashboard-dist/api/948.index.js +64 -0
  50. package/dashboard-dist/api/948.index.js.map +1 -0
  51. package/dashboard-dist/api/953.index.js +67 -0
  52. package/dashboard-dist/api/953.index.js.map +1 -0
  53. package/dashboard-dist/api/975.index.js +374 -0
  54. package/dashboard-dist/api/975.index.js.map +1 -0
  55. package/dashboard-dist/api/drizzle/sqlite/0000_short_captain_stacy.sql +70 -0
  56. package/dashboard-dist/api/drizzle/sqlite/0001_closed_magus.sql +10 -0
  57. package/dashboard-dist/api/drizzle/sqlite/0002_agent_capability_observation.sql +38 -0
  58. package/dashboard-dist/api/drizzle/sqlite/0003_auth_magic_link.sql +28 -0
  59. package/dashboard-dist/api/drizzle/sqlite/0004_static_scan_fields.sql +8 -0
  60. package/dashboard-dist/api/drizzle/sqlite/0005_gateway_activity.sql +24 -0
  61. package/dashboard-dist/api/drizzle/sqlite/0006_sour_marauders.sql +41 -0
  62. package/dashboard-dist/api/drizzle/sqlite/meta/0000_snapshot.json +460 -0
  63. package/dashboard-dist/api/drizzle/sqlite/meta/0001_snapshot.json +536 -0
  64. package/dashboard-dist/api/drizzle/sqlite/meta/0006_snapshot.json +1249 -0
  65. package/dashboard-dist/api/drizzle/sqlite/meta/_journal.json +55 -0
  66. package/dashboard-dist/api/index.js +27340 -0
  67. package/dashboard-dist/api/index.js.map +1 -0
  68. package/dashboard-dist/api/package.json +16 -0
  69. package/dashboard-dist/api/sourcemap-register.cjs +1 -0
  70. package/dashboard-dist/web/assets/index-CqWIeBTD.js +158 -0
  71. package/dashboard-dist/web/assets/index-Dw7--9q4.css +1 -0
  72. package/dashboard-dist/web/changeway-logo.png +0 -0
  73. package/dashboard-dist/web/favicon.svg +29 -0
  74. package/dashboard-dist/web/index.html +14 -0
  75. package/dashboard-dist/web/logo.svg +16 -0
  76. package/dist/agent/auth.d.ts +37 -0
  77. package/dist/agent/auth.d.ts.map +1 -0
  78. package/dist/agent/auth.js +151 -0
  79. package/dist/agent/auth.js.map +1 -0
  80. package/dist/agent/behavior-detector.d.ts +150 -0
  81. package/dist/agent/behavior-detector.d.ts.map +1 -0
  82. package/dist/agent/behavior-detector.js +573 -0
  83. package/dist/agent/behavior-detector.js.map +1 -0
  84. package/dist/agent/business-reporter.d.ts +114 -0
  85. package/dist/agent/business-reporter.d.ts.map +1 -0
  86. package/dist/agent/business-reporter.js +359 -0
  87. package/dist/agent/business-reporter.js.map +1 -0
  88. package/dist/agent/config-sync.d.ts +70 -0
  89. package/dist/agent/config-sync.d.ts.map +1 -0
  90. package/dist/agent/config-sync.js +133 -0
  91. package/dist/agent/config-sync.js.map +1 -0
  92. package/dist/agent/config.d.ts +97 -0
  93. package/dist/agent/config.d.ts.map +1 -0
  94. package/dist/agent/config.js +359 -0
  95. package/dist/agent/config.js.map +1 -0
  96. package/dist/agent/content-injection-scanner.d.ts +35 -0
  97. package/dist/agent/content-injection-scanner.d.ts.map +1 -0
  98. package/dist/agent/content-injection-scanner.js +270 -0
  99. package/dist/agent/content-injection-scanner.js.map +1 -0
  100. package/dist/agent/engine-log-writer.d.ts +6 -0
  101. package/dist/agent/engine-log-writer.d.ts.map +1 -0
  102. package/dist/agent/engine-log-writer.js +18 -0
  103. package/dist/agent/engine-log-writer.js.map +1 -0
  104. package/dist/agent/env.d.ts +19 -0
  105. package/dist/agent/env.d.ts.map +1 -0
  106. package/dist/agent/env.js +43 -0
  107. package/dist/agent/env.js.map +1 -0
  108. package/dist/agent/event-reporter.d.ts +87 -0
  109. package/dist/agent/event-reporter.d.ts.map +1 -0
  110. package/dist/agent/event-reporter.js +315 -0
  111. package/dist/agent/event-reporter.js.map +1 -0
  112. package/dist/agent/file-watcher.d.ts +50 -0
  113. package/dist/agent/file-watcher.d.ts.map +1 -0
  114. package/dist/agent/file-watcher.js +135 -0
  115. package/dist/agent/file-watcher.js.map +1 -0
  116. package/dist/agent/fs-utils.d.ts +22 -0
  117. package/dist/agent/fs-utils.d.ts.map +1 -0
  118. package/dist/agent/fs-utils.js +41 -0
  119. package/dist/agent/fs-utils.js.map +1 -0
  120. package/dist/agent/gateway-manager.d.ts +59 -0
  121. package/dist/agent/gateway-manager.d.ts.map +1 -0
  122. package/dist/agent/gateway-manager.js +583 -0
  123. package/dist/agent/gateway-manager.js.map +1 -0
  124. package/dist/agent/hook-types.d.ts +276 -0
  125. package/dist/agent/hook-types.d.ts.map +1 -0
  126. package/dist/agent/hook-types.js +51 -0
  127. package/dist/agent/hook-types.js.map +1 -0
  128. package/dist/agent/index.d.ts +8 -0
  129. package/dist/agent/index.d.ts.map +1 -0
  130. package/dist/agent/index.js +8 -0
  131. package/dist/agent/index.js.map +1 -0
  132. package/dist/agent/prompt-gate.d.ts +13 -0
  133. package/dist/agent/prompt-gate.d.ts.map +1 -0
  134. package/dist/agent/prompt-gate.js +28 -0
  135. package/dist/agent/prompt-gate.js.map +1 -0
  136. package/dist/agent/prompt-input.d.ts +9 -0
  137. package/dist/agent/prompt-input.d.ts.map +1 -0
  138. package/dist/agent/prompt-input.js +158 -0
  139. package/dist/agent/prompt-input.js.map +1 -0
  140. package/dist/agent/prompt-output.d.ts +4 -0
  141. package/dist/agent/prompt-output.d.ts.map +1 -0
  142. package/dist/agent/prompt-output.js +19 -0
  143. package/dist/agent/prompt-output.js.map +1 -0
  144. package/dist/agent/runner.d.ts +23 -0
  145. package/dist/agent/runner.d.ts.map +1 -0
  146. package/dist/agent/runner.js +154 -0
  147. package/dist/agent/runner.js.map +1 -0
  148. package/dist/agent/sanitizer.d.ts +10 -0
  149. package/dist/agent/sanitizer.d.ts.map +1 -0
  150. package/dist/agent/sanitizer.js +175 -0
  151. package/dist/agent/sanitizer.js.map +1 -0
  152. package/dist/agent/scan-activity.d.ts +18 -0
  153. package/dist/agent/scan-activity.d.ts.map +1 -0
  154. package/dist/agent/scan-activity.js +32 -0
  155. package/dist/agent/scan-activity.js.map +1 -0
  156. package/dist/agent/types.d.ts +177 -0
  157. package/dist/agent/types.d.ts.map +1 -0
  158. package/dist/agent/types.js +5 -0
  159. package/dist/agent/types.js.map +1 -0
  160. package/dist/agent/workspace-scanner.d.ts +35 -0
  161. package/dist/agent/workspace-scanner.d.ts.map +1 -0
  162. package/dist/agent/workspace-scanner.js +137 -0
  163. package/dist/agent/workspace-scanner.js.map +1 -0
  164. package/dist/dashboard-launcher.d.ts +52 -0
  165. package/dist/dashboard-launcher.d.ts.map +1 -0
  166. package/dist/dashboard-launcher.js +363 -0
  167. package/dist/dashboard-launcher.js.map +1 -0
  168. package/dist/gateway/activity.d.ts +52 -0
  169. package/dist/gateway/activity.d.ts.map +1 -0
  170. package/dist/gateway/activity.js +111 -0
  171. package/dist/gateway/activity.js.map +1 -0
  172. package/dist/gateway/config.d.ts +50 -0
  173. package/dist/gateway/config.d.ts.map +1 -0
  174. package/dist/gateway/config.js +200 -0
  175. package/dist/gateway/config.js.map +1 -0
  176. package/dist/gateway/gateway/activity.d.ts +52 -0
  177. package/dist/gateway/gateway/activity.d.ts.map +1 -0
  178. package/dist/gateway/gateway/activity.js +111 -0
  179. package/dist/gateway/gateway/activity.js.map +1 -0
  180. package/dist/gateway/gateway/config.d.ts +50 -0
  181. package/dist/gateway/gateway/config.d.ts.map +1 -0
  182. package/dist/gateway/gateway/config.js +200 -0
  183. package/dist/gateway/gateway/config.js.map +1 -0
  184. package/dist/gateway/gateway/handlers/anthropic.d.ts +12 -0
  185. package/dist/gateway/gateway/handlers/anthropic.d.ts.map +1 -0
  186. package/dist/gateway/gateway/handlers/anthropic.js +254 -0
  187. package/dist/gateway/gateway/handlers/anthropic.js.map +1 -0
  188. package/dist/gateway/gateway/handlers/gemini.d.ts +12 -0
  189. package/dist/gateway/gateway/handlers/gemini.d.ts.map +1 -0
  190. package/dist/gateway/gateway/handlers/gemini.js +101 -0
  191. package/dist/gateway/gateway/handlers/gemini.js.map +1 -0
  192. package/dist/gateway/gateway/handlers/models.d.ts +4 -0
  193. package/dist/gateway/gateway/handlers/models.d.ts.map +1 -0
  194. package/dist/gateway/gateway/handlers/models.js +36 -0
  195. package/dist/gateway/gateway/handlers/models.js.map +1 -0
  196. package/dist/gateway/gateway/handlers/openai.d.ts +16 -0
  197. package/dist/gateway/gateway/handlers/openai.d.ts.map +1 -0
  198. package/dist/gateway/gateway/handlers/openai.js +254 -0
  199. package/dist/gateway/gateway/handlers/openai.js.map +1 -0
  200. package/dist/gateway/gateway/index.d.ts +27 -0
  201. package/dist/gateway/gateway/index.d.ts.map +1 -0
  202. package/dist/gateway/gateway/index.js +293 -0
  203. package/dist/gateway/gateway/index.js.map +1 -0
  204. package/dist/gateway/gateway/mapping-store.d.ts +38 -0
  205. package/dist/gateway/gateway/mapping-store.d.ts.map +1 -0
  206. package/dist/gateway/gateway/mapping-store.js +74 -0
  207. package/dist/gateway/gateway/mapping-store.js.map +1 -0
  208. package/dist/gateway/gateway/restorer.d.ts +63 -0
  209. package/dist/gateway/gateway/restorer.d.ts.map +1 -0
  210. package/dist/gateway/gateway/restorer.js +284 -0
  211. package/dist/gateway/gateway/restorer.js.map +1 -0
  212. package/dist/gateway/gateway/sanitizer.d.ts +17 -0
  213. package/dist/gateway/gateway/sanitizer.d.ts.map +1 -0
  214. package/dist/gateway/gateway/sanitizer.js +228 -0
  215. package/dist/gateway/gateway/sanitizer.js.map +1 -0
  216. package/dist/gateway/gateway/types.d.ts +53 -0
  217. package/dist/gateway/gateway/types.d.ts.map +1 -0
  218. package/dist/gateway/gateway/types.js +5 -0
  219. package/dist/gateway/gateway/types.js.map +1 -0
  220. package/dist/gateway/handlers/anthropic.d.ts +12 -0
  221. package/dist/gateway/handlers/anthropic.d.ts.map +1 -0
  222. package/dist/gateway/handlers/anthropic.js +254 -0
  223. package/dist/gateway/handlers/anthropic.js.map +1 -0
  224. package/dist/gateway/handlers/gemini.d.ts +12 -0
  225. package/dist/gateway/handlers/gemini.d.ts.map +1 -0
  226. package/dist/gateway/handlers/gemini.js +101 -0
  227. package/dist/gateway/handlers/gemini.js.map +1 -0
  228. package/dist/gateway/handlers/models.d.ts +4 -0
  229. package/dist/gateway/handlers/models.d.ts.map +1 -0
  230. package/dist/gateway/handlers/models.js +36 -0
  231. package/dist/gateway/handlers/models.js.map +1 -0
  232. package/dist/gateway/handlers/openai.d.ts +16 -0
  233. package/dist/gateway/handlers/openai.d.ts.map +1 -0
  234. package/dist/gateway/handlers/openai.js +254 -0
  235. package/dist/gateway/handlers/openai.js.map +1 -0
  236. package/dist/gateway/index.d.ts +27 -0
  237. package/dist/gateway/index.d.ts.map +1 -0
  238. package/dist/gateway/index.js +293 -0
  239. package/dist/gateway/index.js.map +1 -0
  240. package/dist/gateway/mapping-store.d.ts +38 -0
  241. package/dist/gateway/mapping-store.d.ts.map +1 -0
  242. package/dist/gateway/mapping-store.js +74 -0
  243. package/dist/gateway/mapping-store.js.map +1 -0
  244. package/dist/gateway/restorer.d.ts +63 -0
  245. package/dist/gateway/restorer.d.ts.map +1 -0
  246. package/dist/gateway/restorer.js +284 -0
  247. package/dist/gateway/restorer.js.map +1 -0
  248. package/dist/gateway/sanitizer.d.ts +17 -0
  249. package/dist/gateway/sanitizer.d.ts.map +1 -0
  250. package/dist/gateway/sanitizer.js +228 -0
  251. package/dist/gateway/sanitizer.js.map +1 -0
  252. package/dist/gateway/types.d.ts +53 -0
  253. package/dist/gateway/types.d.ts.map +1 -0
  254. package/dist/gateway/types.js +5 -0
  255. package/dist/gateway/types.js.map +1 -0
  256. package/dist/index.d.ts +19 -0
  257. package/dist/index.d.ts.map +1 -0
  258. package/dist/index.js +2084 -0
  259. package/dist/index.js.map +1 -0
  260. package/dist/memory/index.d.ts +5 -0
  261. package/dist/memory/index.d.ts.map +1 -0
  262. package/dist/memory/index.js +5 -0
  263. package/dist/memory/index.js.map +1 -0
  264. package/dist/memory/store.d.ts +82 -0
  265. package/dist/memory/store.d.ts.map +1 -0
  266. package/dist/memory/store.js +194 -0
  267. package/dist/memory/store.js.map +1 -0
  268. package/dist/platform-client/index.d.ts +63 -0
  269. package/dist/platform-client/index.d.ts.map +1 -0
  270. package/dist/platform-client/index.js +294 -0
  271. package/dist/platform-client/index.js.map +1 -0
  272. package/dist/platform-client/types.d.ts +109 -0
  273. package/dist/platform-client/types.d.ts.map +1 -0
  274. package/dist/platform-client/types.js +3 -0
  275. package/dist/platform-client/types.js.map +1 -0
  276. package/gateway/activity.d.ts +52 -0
  277. package/gateway/activity.d.ts.map +1 -0
  278. package/gateway/activity.js +111 -0
  279. package/gateway/activity.js.map +1 -0
  280. package/gateway/config.d.ts +50 -0
  281. package/gateway/config.d.ts.map +1 -0
  282. package/gateway/config.js +200 -0
  283. package/gateway/config.js.map +1 -0
  284. package/gateway/handlers/anthropic.d.ts +12 -0
  285. package/gateway/handlers/anthropic.d.ts.map +1 -0
  286. package/gateway/handlers/anthropic.js +254 -0
  287. package/gateway/handlers/anthropic.js.map +1 -0
  288. package/gateway/handlers/gemini.d.ts +12 -0
  289. package/gateway/handlers/gemini.d.ts.map +1 -0
  290. package/gateway/handlers/gemini.js +101 -0
  291. package/gateway/handlers/gemini.js.map +1 -0
  292. package/gateway/handlers/models.d.ts +4 -0
  293. package/gateway/handlers/models.d.ts.map +1 -0
  294. package/gateway/handlers/models.js +36 -0
  295. package/gateway/handlers/models.js.map +1 -0
  296. package/gateway/handlers/openai.d.ts +16 -0
  297. package/gateway/handlers/openai.d.ts.map +1 -0
  298. package/gateway/handlers/openai.js +254 -0
  299. package/gateway/handlers/openai.js.map +1 -0
  300. package/gateway/index.d.ts +27 -0
  301. package/gateway/index.d.ts.map +1 -0
  302. package/gateway/index.js +293 -0
  303. package/gateway/index.js.map +1 -0
  304. package/gateway/mapping-store.d.ts +38 -0
  305. package/gateway/mapping-store.d.ts.map +1 -0
  306. package/gateway/mapping-store.js +74 -0
  307. package/gateway/mapping-store.js.map +1 -0
  308. package/gateway/restorer.d.ts +63 -0
  309. package/gateway/restorer.d.ts.map +1 -0
  310. package/gateway/restorer.js +284 -0
  311. package/gateway/restorer.js.map +1 -0
  312. package/gateway/sanitizer.d.ts +17 -0
  313. package/gateway/sanitizer.d.ts.map +1 -0
  314. package/gateway/sanitizer.js +228 -0
  315. package/gateway/sanitizer.js.map +1 -0
  316. package/gateway/types.d.ts +53 -0
  317. package/gateway/types.d.ts.map +1 -0
  318. package/gateway/types.js +5 -0
  319. package/gateway/types.js.map +1 -0
  320. package/openclaw.plugin.json +86 -0
  321. package/package.json +74 -0
  322. package/samples/Untitled +1 -0
  323. package/samples/clean-email.txt +20 -0
  324. package/samples/test-document.md +53 -0
  325. package/samples/test-email-popup.txt +44 -0
  326. package/samples/test-email.txt +32 -0
  327. package/samples/test-webpage.html +51 -0
  328. package/scripts/enterprise-enroll.sh +89 -0
  329. package/scripts/enterprise-unenroll.sh +75 -0
@@ -0,0 +1,3562 @@
1
+ export const id = 25;
2
+ export const ids = [25];
3
+ export const modules = {
4
+
5
+ /***/ 8575:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ Hs: () => (/* binding */ mapColumnsInAliasedSQLToAlias),
10
+ /* harmony export */ Ht: () => (/* binding */ ColumnAliasProxyHandler),
11
+ /* harmony export */ h_: () => (/* binding */ TableAliasProxyHandler),
12
+ /* harmony export */ oG: () => (/* binding */ aliasedTable),
13
+ /* harmony export */ ug: () => (/* binding */ aliasedTableColumn),
14
+ /* harmony export */ yY: () => (/* binding */ mapColumnsInSQLToAlias)
15
+ /* harmony export */ });
16
+ /* unused harmony exports RelationTableAliasProxyHandler, aliasedRelation */
17
+ /* harmony import */ var _column_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2345);
18
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
19
+ /* harmony import */ var _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(183);
20
+ /* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407);
21
+ /* harmony import */ var _view_common_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6146);
22
+
23
+
24
+
25
+
26
+
27
+ class ColumnAliasProxyHandler {
28
+ constructor(table) {
29
+ this.table = table;
30
+ }
31
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "ColumnAliasProxyHandler";
32
+ get(columnObj, prop) {
33
+ if (prop === "table") {
34
+ return this.table;
35
+ }
36
+ return columnObj[prop];
37
+ }
38
+ }
39
+ class TableAliasProxyHandler {
40
+ constructor(alias, replaceOriginalName) {
41
+ this.alias = alias;
42
+ this.replaceOriginalName = replaceOriginalName;
43
+ }
44
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TableAliasProxyHandler";
45
+ get(target, prop) {
46
+ if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.IsAlias) {
47
+ return true;
48
+ }
49
+ if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Name) {
50
+ return this.alias;
51
+ }
52
+ if (this.replaceOriginalName && prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName) {
53
+ return this.alias;
54
+ }
55
+ if (prop === _view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n) {
56
+ return {
57
+ ...target[_view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n],
58
+ name: this.alias,
59
+ isAlias: true
60
+ };
61
+ }
62
+ if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns) {
63
+ const columns = target[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns];
64
+ if (!columns) {
65
+ return columns;
66
+ }
67
+ const proxiedColumns = {};
68
+ Object.keys(columns).map((key) => {
69
+ proxiedColumns[key] = new Proxy(
70
+ columns[key],
71
+ new ColumnAliasProxyHandler(new Proxy(target, this))
72
+ );
73
+ });
74
+ return proxiedColumns;
75
+ }
76
+ const value = target[prop];
77
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) {
78
+ return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
79
+ }
80
+ return value;
81
+ }
82
+ }
83
+ class RelationTableAliasProxyHandler {
84
+ constructor(alias) {
85
+ this.alias = alias;
86
+ }
87
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = (/* unused pure expression or super */ null && ("RelationTableAliasProxyHandler"));
88
+ get(target, prop) {
89
+ if (prop === "sourceTable") {
90
+ return aliasedTable(target.sourceTable, this.alias);
91
+ }
92
+ return target[prop];
93
+ }
94
+ }
95
+ function aliasedTable(table, tableAlias) {
96
+ return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
97
+ }
98
+ function aliasedRelation(relation, tableAlias) {
99
+ return new Proxy(relation, new RelationTableAliasProxyHandler(tableAlias));
100
+ }
101
+ function aliasedTableColumn(column, tableAlias) {
102
+ return new Proxy(
103
+ column,
104
+ new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false)))
105
+ );
106
+ }
107
+ function mapColumnsInAliasedSQLToAlias(query, alias) {
108
+ return new _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
109
+ }
110
+ function mapColumnsInSQLToAlias(query, alias) {
111
+ return _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .sql */ .ll.join(query.queryChunks.map((c) => {
112
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) {
113
+ return aliasedTableColumn(c, alias);
114
+ }
115
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs)) {
116
+ return mapColumnsInSQLToAlias(c, alias);
117
+ }
118
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased)) {
119
+ return mapColumnsInAliasedSQLToAlias(c, alias);
120
+ }
121
+ return c;
122
+ }));
123
+ }
124
+
125
+ //# sourceMappingURL=alias.js.map
126
+
127
+ /***/ }),
128
+
129
+ /***/ 568:
130
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
131
+
132
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
133
+ /* harmony export */ Yn: () => (/* binding */ CasingCache)
134
+ /* harmony export */ });
135
+ /* unused harmony exports toCamelCase, toSnakeCase */
136
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
137
+ /* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407);
138
+
139
+
140
+ function toSnakeCase(input) {
141
+ const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
142
+ return words.map((word) => word.toLowerCase()).join("_");
143
+ }
144
+ function toCamelCase(input) {
145
+ const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
146
+ return words.reduce((acc, word, i) => {
147
+ const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;
148
+ return acc + formattedWord;
149
+ }, "");
150
+ }
151
+ function noopCase(input) {
152
+ return input;
153
+ }
154
+ class CasingCache {
155
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "CasingCache";
156
+ /** @internal */
157
+ cache = {};
158
+ cachedTables = {};
159
+ convert;
160
+ constructor(casing) {
161
+ this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
162
+ }
163
+ getColumnCasing(column) {
164
+ if (!column.keyAsName)
165
+ return column.name;
166
+ const schema = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public";
167
+ const tableName = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName];
168
+ const key = `${schema}.${tableName}.${column.name}`;
169
+ if (!this.cache[key]) {
170
+ this.cacheTable(column.table);
171
+ }
172
+ return this.cache[key];
173
+ }
174
+ cacheTable(table) {
175
+ const schema = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public";
176
+ const tableName = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName];
177
+ const tableKey = `${schema}.${tableName}`;
178
+ if (!this.cachedTables[tableKey]) {
179
+ for (const column of Object.values(table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns])) {
180
+ const columnKey = `${tableKey}.${column.name}`;
181
+ this.cache[columnKey] = this.convert(column.name);
182
+ }
183
+ this.cachedTables[tableKey] = true;
184
+ }
185
+ }
186
+ clearCache() {
187
+ this.cache = {};
188
+ this.cachedTables = {};
189
+ }
190
+ }
191
+
192
+ //# sourceMappingURL=casing.js.map
193
+
194
+ /***/ }),
195
+
196
+ /***/ 6920:
197
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
198
+
199
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
200
+ /* harmony export */ j: () => (/* binding */ TransactionRollbackError),
201
+ /* harmony export */ n: () => (/* binding */ DrizzleError)
202
+ /* harmony export */ });
203
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
204
+
205
+ class DrizzleError extends Error {
206
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "DrizzleError";
207
+ constructor({ message, cause }) {
208
+ super(message);
209
+ this.name = "DrizzleError";
210
+ this.cause = cause;
211
+ }
212
+ }
213
+ class TransactionRollbackError extends DrizzleError {
214
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TransactionRollbackError";
215
+ constructor() {
216
+ super({ message: "Rollback" });
217
+ }
218
+ }
219
+
220
+ //# sourceMappingURL=errors.js.map
221
+
222
+ /***/ }),
223
+
224
+ /***/ 6743:
225
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
226
+
227
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
228
+ /* harmony export */ Pv: () => (/* binding */ NoopLogger),
229
+ /* harmony export */ w: () => (/* binding */ DefaultLogger)
230
+ /* harmony export */ });
231
+ /* unused harmony export ConsoleLogWriter */
232
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
233
+
234
+ class ConsoleLogWriter {
235
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "ConsoleLogWriter";
236
+ write(message) {
237
+ console.log(message);
238
+ }
239
+ }
240
+ class DefaultLogger {
241
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "DefaultLogger";
242
+ writer;
243
+ constructor(config) {
244
+ this.writer = config?.writer ?? new ConsoleLogWriter();
245
+ }
246
+ logQuery(query, params) {
247
+ const stringifiedParams = params.map((p) => {
248
+ try {
249
+ return JSON.stringify(p);
250
+ } catch {
251
+ return String(p);
252
+ }
253
+ });
254
+ const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
255
+ this.writer.write(`Query: ${query}${paramsStr}`);
256
+ }
257
+ }
258
+ class NoopLogger {
259
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "NoopLogger";
260
+ logQuery() {
261
+ }
262
+ }
263
+
264
+ //# sourceMappingURL=logger.js.map
265
+
266
+ /***/ }),
267
+
268
+ /***/ 3025:
269
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
270
+
271
+
272
+ // EXPORTS
273
+ __webpack_require__.d(__webpack_exports__, {
274
+ drizzle: () => (/* reexport */ drizzle)
275
+ });
276
+
277
+ // UNUSED EXPORTS: MySql2Database, MySql2Driver, MySql2PreparedQuery, MySql2Session, MySql2Transaction, MySqlDatabase
278
+
279
+ // EXTERNAL MODULE: external "mysql2"
280
+ var external_mysql2_ = __webpack_require__(2530);
281
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/entity.js
282
+ var entity = __webpack_require__(9724);
283
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/logger.js
284
+ var drizzle_orm_logger = __webpack_require__(6743);
285
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/selection-proxy.js
286
+ var selection_proxy = __webpack_require__(8296);
287
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/sql.js + 1 modules
288
+ var sql = __webpack_require__(183);
289
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/subquery.js
290
+ var subquery = __webpack_require__(6453);
291
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/count.js
292
+
293
+
294
+ class MySqlCountBuilder extends sql/* SQL */.Xs {
295
+ constructor(params) {
296
+ super(MySqlCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
297
+ this.params = params;
298
+ this.mapWith(Number);
299
+ this.session = params.session;
300
+ this.sql = MySqlCountBuilder.buildCount(
301
+ params.source,
302
+ params.filters
303
+ );
304
+ }
305
+ sql;
306
+ static [entity/* entityKind */.i] = "MySqlCountBuilder";
307
+ [Symbol.toStringTag] = "MySqlCountBuilder";
308
+ session;
309
+ static buildEmbeddedCount(source, filters) {
310
+ return (0,sql/* sql */.ll)`(select count(*) from ${source}${sql/* sql */.ll.raw(" where ").if(filters)}${filters})`;
311
+ }
312
+ static buildCount(source, filters) {
313
+ return (0,sql/* sql */.ll)`select count(*) as count from ${source}${sql/* sql */.ll.raw(" where ").if(filters)}${filters}`;
314
+ }
315
+ then(onfulfilled, onrejected) {
316
+ return Promise.resolve(this.session.count(this.sql)).then(
317
+ onfulfilled,
318
+ onrejected
319
+ );
320
+ }
321
+ catch(onRejected) {
322
+ return this.then(void 0, onRejected);
323
+ }
324
+ finally(onFinally) {
325
+ return this.then(
326
+ (value) => {
327
+ onFinally?.();
328
+ return value;
329
+ },
330
+ (reason) => {
331
+ onFinally?.();
332
+ throw reason;
333
+ }
334
+ );
335
+ }
336
+ }
337
+
338
+ //# sourceMappingURL=count.js.map
339
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/alias.js
340
+ var alias = __webpack_require__(8575);
341
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/casing.js
342
+ var casing = __webpack_require__(568);
343
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/column.js
344
+ var drizzle_orm_column = __webpack_require__(2345);
345
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/errors.js
346
+ var errors = __webpack_require__(6920);
347
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/conditions.js
348
+ var conditions = __webpack_require__(420);
349
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/relations.js + 1 modules
350
+ var relations = __webpack_require__(4750);
351
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/table.js
352
+ var drizzle_orm_table = __webpack_require__(8407);
353
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/utils.js
354
+ var utils = __webpack_require__(3853);
355
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/view-common.js
356
+ var view_common = __webpack_require__(6146);
357
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/columns/common.js + 2 modules
358
+ var common = __webpack_require__(9498);
359
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/table.js + 19 modules
360
+ var mysql_core_table = __webpack_require__(2104);
361
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/view-base.js
362
+
363
+
364
+ class MySqlViewBase extends sql/* View */.Ss {
365
+ static [entity/* entityKind */.i] = "MySqlViewBase";
366
+ }
367
+
368
+ //# sourceMappingURL=view-base.js.map
369
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/dialect.js
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+ class MySqlDialect {
386
+ static [entity/* entityKind */.i] = "MySqlDialect";
387
+ /** @internal */
388
+ casing;
389
+ constructor(config) {
390
+ this.casing = new casing/* CasingCache */.Yn(config?.casing);
391
+ }
392
+ async migrate(migrations, session, config) {
393
+ const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";
394
+ const migrationTableCreate = (0,sql/* sql */.ll)`
395
+ create table if not exists ${sql/* sql */.ll.identifier(migrationsTable)} (
396
+ id serial primary key,
397
+ hash text not null,
398
+ created_at bigint
399
+ )
400
+ `;
401
+ await session.execute(migrationTableCreate);
402
+ const dbMigrations = await session.all(
403
+ (0,sql/* sql */.ll)`select id, hash, created_at from ${sql/* sql */.ll.identifier(migrationsTable)} order by created_at desc limit 1`
404
+ );
405
+ const lastDbMigration = dbMigrations[0];
406
+ await session.transaction(async (tx) => {
407
+ for (const migration of migrations) {
408
+ if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
409
+ for (const stmt of migration.sql) {
410
+ await tx.execute(sql/* sql */.ll.raw(stmt));
411
+ }
412
+ await tx.execute(
413
+ (0,sql/* sql */.ll)`insert into ${sql/* sql */.ll.identifier(migrationsTable)} (\`hash\`, \`created_at\`) values(${migration.hash}, ${migration.folderMillis})`
414
+ );
415
+ }
416
+ }
417
+ });
418
+ }
419
+ escapeName(name) {
420
+ return `\`${name}\``;
421
+ }
422
+ escapeParam(_num) {
423
+ return `?`;
424
+ }
425
+ escapeString(str) {
426
+ return `'${str.replace(/'/g, "''")}'`;
427
+ }
428
+ buildWithCTE(queries) {
429
+ if (!queries?.length)
430
+ return void 0;
431
+ const withSqlChunks = [(0,sql/* sql */.ll)`with `];
432
+ for (const [i, w] of queries.entries()) {
433
+ withSqlChunks.push((0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(w._.alias)} as (${w._.sql})`);
434
+ if (i < queries.length - 1) {
435
+ withSqlChunks.push((0,sql/* sql */.ll)`, `);
436
+ }
437
+ }
438
+ withSqlChunks.push((0,sql/* sql */.ll)` `);
439
+ return sql/* sql */.ll.join(withSqlChunks);
440
+ }
441
+ buildDeleteQuery({ table, where, returning, withList, limit, orderBy }) {
442
+ const withSql = this.buildWithCTE(withList);
443
+ const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
444
+ const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
445
+ const orderBySql = this.buildOrderBy(orderBy);
446
+ const limitSql = this.buildLimit(limit);
447
+ return (0,sql/* sql */.ll)`${withSql}delete from ${table}${whereSql}${orderBySql}${limitSql}${returningSql}`;
448
+ }
449
+ buildUpdateSet(table, set) {
450
+ const tableColumns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
451
+ const columnNames = Object.keys(tableColumns).filter(
452
+ (colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0
453
+ );
454
+ const setSize = columnNames.length;
455
+ return sql/* sql */.ll.join(columnNames.flatMap((colName, i) => {
456
+ const col = tableColumns[colName];
457
+ const value = set[colName] ?? sql/* sql */.ll.param(col.onUpdateFn(), col);
458
+ const res = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(this.casing.getColumnCasing(col))} = ${value}`;
459
+ if (i < setSize - 1) {
460
+ return [res, sql/* sql */.ll.raw(", ")];
461
+ }
462
+ return [res];
463
+ }));
464
+ }
465
+ buildUpdateQuery({ table, set, where, returning, withList, limit, orderBy }) {
466
+ const withSql = this.buildWithCTE(withList);
467
+ const setSql = this.buildUpdateSet(table, set);
468
+ const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
469
+ const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
470
+ const orderBySql = this.buildOrderBy(orderBy);
471
+ const limitSql = this.buildLimit(limit);
472
+ return (0,sql/* sql */.ll)`${withSql}update ${table} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;
473
+ }
474
+ /**
475
+ * Builds selection SQL with provided fields/expressions
476
+ *
477
+ * Examples:
478
+ *
479
+ * `select <selection> from`
480
+ *
481
+ * `insert ... returning <selection>`
482
+ *
483
+ * If `isSingleTable` is true, then columns won't be prefixed with table name
484
+ */
485
+ buildSelection(fields, { isSingleTable = false } = {}) {
486
+ const columnsLen = fields.length;
487
+ const chunks = fields.flatMap(({ field }, i) => {
488
+ const chunk = [];
489
+ if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) && field.isSelectionField) {
490
+ chunk.push(sql/* sql */.ll.identifier(field.fieldAlias));
491
+ } else if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) || (0,entity.is)(field, sql/* SQL */.Xs)) {
492
+ const query = (0,entity.is)(field, sql/* SQL */.Xs.Aliased) ? field.sql : field;
493
+ if (isSingleTable) {
494
+ chunk.push(
495
+ new sql/* SQL */.Xs(
496
+ query.queryChunks.map((c) => {
497
+ if ((0,entity.is)(c, common/* MySqlColumn */.rI)) {
498
+ return sql/* sql */.ll.identifier(this.casing.getColumnCasing(c));
499
+ }
500
+ return c;
501
+ })
502
+ )
503
+ );
504
+ } else {
505
+ chunk.push(query);
506
+ }
507
+ if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased)) {
508
+ chunk.push((0,sql/* sql */.ll)` as ${sql/* sql */.ll.identifier(field.fieldAlias)}`);
509
+ }
510
+ } else if ((0,entity.is)(field, drizzle_orm_column/* Column */.V)) {
511
+ if (isSingleTable) {
512
+ chunk.push(sql/* sql */.ll.identifier(this.casing.getColumnCasing(field)));
513
+ } else {
514
+ chunk.push(field);
515
+ }
516
+ }
517
+ if (i < columnsLen - 1) {
518
+ chunk.push((0,sql/* sql */.ll)`, `);
519
+ }
520
+ return chunk;
521
+ });
522
+ return sql/* sql */.ll.join(chunks);
523
+ }
524
+ buildLimit(limit) {
525
+ return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0;
526
+ }
527
+ buildOrderBy(orderBy) {
528
+ return orderBy && orderBy.length > 0 ? (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderBy, (0,sql/* sql */.ll)`, `)}` : void 0;
529
+ }
530
+ buildSelectQuery({
531
+ withList,
532
+ fields,
533
+ fieldsFlat,
534
+ where,
535
+ having,
536
+ table,
537
+ joins,
538
+ orderBy,
539
+ groupBy,
540
+ limit,
541
+ offset,
542
+ lockingClause,
543
+ distinct,
544
+ setOperators
545
+ }) {
546
+ const fieldsList = fieldsFlat ?? (0,utils/* orderSelectedFields */.He)(fields);
547
+ for (const f of fieldsList) {
548
+ if ((0,entity.is)(f.field, drizzle_orm_column/* Column */.V) && (0,drizzle_orm_table/* getTableName */.Io)(f.field.table) !== ((0,entity.is)(table, subquery/* Subquery */.n) ? table._.alias : (0,entity.is)(table, MySqlViewBase) ? table[view_common/* ViewBaseConfig */.n].name : (0,entity.is)(table, sql/* SQL */.Xs) ? void 0 : (0,drizzle_orm_table/* getTableName */.Io)(table)) && !((table2) => joins?.some(
549
+ ({ alias }) => alias === (table2[drizzle_orm_table/* Table */.XI.Symbol.IsAlias] ? (0,drizzle_orm_table/* getTableName */.Io)(table2) : table2[drizzle_orm_table/* Table */.XI.Symbol.BaseName])
550
+ ))(f.field.table)) {
551
+ const tableName = (0,drizzle_orm_table/* getTableName */.Io)(f.field.table);
552
+ throw new Error(
553
+ `Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`
554
+ );
555
+ }
556
+ }
557
+ const isSingleTable = !joins || joins.length === 0;
558
+ const withSql = this.buildWithCTE(withList);
559
+ const distinctSql = distinct ? (0,sql/* sql */.ll)` distinct` : void 0;
560
+ const selection = this.buildSelection(fieldsList, { isSingleTable });
561
+ const tableSql = (() => {
562
+ if ((0,entity.is)(table, drizzle_orm_table/* Table */.XI) && table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName] !== table[drizzle_orm_table/* Table */.XI.Symbol.Name]) {
563
+ return (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName])} ${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.Name])}`;
564
+ }
565
+ return table;
566
+ })();
567
+ const joinsArray = [];
568
+ if (joins) {
569
+ for (const [index, joinMeta] of joins.entries()) {
570
+ if (index === 0) {
571
+ joinsArray.push((0,sql/* sql */.ll)` `);
572
+ }
573
+ const table2 = joinMeta.table;
574
+ const lateralSql = joinMeta.lateral ? (0,sql/* sql */.ll)` lateral` : void 0;
575
+ if ((0,entity.is)(table2, mysql_core_table/* MySqlTable */.B$)) {
576
+ const tableName = table2[mysql_core_table/* MySqlTable */.B$.Symbol.Name];
577
+ const tableSchema = table2[mysql_core_table/* MySqlTable */.B$.Symbol.Schema];
578
+ const origTableName = table2[mysql_core_table/* MySqlTable */.B$.Symbol.OriginalName];
579
+ const alias = tableName === origTableName ? void 0 : joinMeta.alias;
580
+ joinsArray.push(
581
+ (0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(tableSchema)}.` : void 0}${sql/* sql */.ll.identifier(origTableName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`} on ${joinMeta.on}`
582
+ );
583
+ } else if ((0,entity.is)(table2, sql/* View */.Ss)) {
584
+ const viewName = table2[view_common/* ViewBaseConfig */.n].name;
585
+ const viewSchema = table2[view_common/* ViewBaseConfig */.n].schema;
586
+ const origViewName = table2[view_common/* ViewBaseConfig */.n].originalName;
587
+ const alias = viewName === origViewName ? void 0 : joinMeta.alias;
588
+ joinsArray.push(
589
+ (0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(viewSchema)}.` : void 0}${sql/* sql */.ll.identifier(origViewName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`} on ${joinMeta.on}`
590
+ );
591
+ } else {
592
+ joinsArray.push(
593
+ (0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${table2} on ${joinMeta.on}`
594
+ );
595
+ }
596
+ if (index < joins.length - 1) {
597
+ joinsArray.push((0,sql/* sql */.ll)` `);
598
+ }
599
+ }
600
+ }
601
+ const joinsSql = sql/* sql */.ll.join(joinsArray);
602
+ const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
603
+ const havingSql = having ? (0,sql/* sql */.ll)` having ${having}` : void 0;
604
+ const orderBySql = this.buildOrderBy(orderBy);
605
+ const groupBySql = groupBy && groupBy.length > 0 ? (0,sql/* sql */.ll)` group by ${sql/* sql */.ll.join(groupBy, (0,sql/* sql */.ll)`, `)}` : void 0;
606
+ const limitSql = this.buildLimit(limit);
607
+ const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0;
608
+ let lockingClausesSql;
609
+ if (lockingClause) {
610
+ const { config, strength } = lockingClause;
611
+ lockingClausesSql = (0,sql/* sql */.ll)` for ${sql/* sql */.ll.raw(strength)}`;
612
+ if (config.noWait) {
613
+ lockingClausesSql.append((0,sql/* sql */.ll)` no wait`);
614
+ } else if (config.skipLocked) {
615
+ lockingClausesSql.append((0,sql/* sql */.ll)` skip locked`);
616
+ }
617
+ }
618
+ const finalQuery = (0,sql/* sql */.ll)`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
619
+ if (setOperators.length > 0) {
620
+ return this.buildSetOperations(finalQuery, setOperators);
621
+ }
622
+ return finalQuery;
623
+ }
624
+ buildSetOperations(leftSelect, setOperators) {
625
+ const [setOperator, ...rest] = setOperators;
626
+ if (!setOperator) {
627
+ throw new Error("Cannot pass undefined values to any set operator");
628
+ }
629
+ if (rest.length === 0) {
630
+ return this.buildSetOperationQuery({ leftSelect, setOperator });
631
+ }
632
+ return this.buildSetOperations(
633
+ this.buildSetOperationQuery({ leftSelect, setOperator }),
634
+ rest
635
+ );
636
+ }
637
+ buildSetOperationQuery({
638
+ leftSelect,
639
+ setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
640
+ }) {
641
+ const leftChunk = (0,sql/* sql */.ll)`(${leftSelect.getSQL()}) `;
642
+ const rightChunk = (0,sql/* sql */.ll)`(${rightSelect.getSQL()})`;
643
+ let orderBySql;
644
+ if (orderBy && orderBy.length > 0) {
645
+ const orderByValues = [];
646
+ for (const orderByUnit of orderBy) {
647
+ if ((0,entity.is)(orderByUnit, common/* MySqlColumn */.rI)) {
648
+ orderByValues.push(sql/* sql */.ll.identifier(this.casing.getColumnCasing(orderByUnit)));
649
+ } else if ((0,entity.is)(orderByUnit, sql/* SQL */.Xs)) {
650
+ for (let i = 0; i < orderByUnit.queryChunks.length; i++) {
651
+ const chunk = orderByUnit.queryChunks[i];
652
+ if ((0,entity.is)(chunk, common/* MySqlColumn */.rI)) {
653
+ orderByUnit.queryChunks[i] = sql/* sql */.ll.identifier(this.casing.getColumnCasing(chunk));
654
+ }
655
+ }
656
+ orderByValues.push((0,sql/* sql */.ll)`${orderByUnit}`);
657
+ } else {
658
+ orderByValues.push((0,sql/* sql */.ll)`${orderByUnit}`);
659
+ }
660
+ }
661
+ orderBySql = (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderByValues, (0,sql/* sql */.ll)`, `)} `;
662
+ }
663
+ const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0;
664
+ const operatorChunk = sql/* sql */.ll.raw(`${type} ${isAll ? "all " : ""}`);
665
+ const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0;
666
+ return (0,sql/* sql */.ll)`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
667
+ }
668
+ buildInsertQuery({ table, values: valuesOrSelect, ignore, onConflict, select }) {
669
+ const valuesSqlList = [];
670
+ const columns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
671
+ const colEntries = Object.entries(columns).filter(
672
+ ([_, col]) => !col.shouldDisableInsert()
673
+ );
674
+ const insertOrder = colEntries.map(([, column]) => sql/* sql */.ll.identifier(this.casing.getColumnCasing(column)));
675
+ const generatedIdsResponse = [];
676
+ if (select) {
677
+ const select2 = valuesOrSelect;
678
+ if ((0,entity.is)(select2, sql/* SQL */.Xs)) {
679
+ valuesSqlList.push(select2);
680
+ } else {
681
+ valuesSqlList.push(select2.getSQL());
682
+ }
683
+ } else {
684
+ const values = valuesOrSelect;
685
+ valuesSqlList.push(sql/* sql */.ll.raw("values "));
686
+ for (const [valueIndex, value] of values.entries()) {
687
+ const generatedIds = {};
688
+ const valueList = [];
689
+ for (const [fieldName, col] of colEntries) {
690
+ const colValue = value[fieldName];
691
+ if (colValue === void 0 || (0,entity.is)(colValue, sql/* Param */.Iw) && colValue.value === void 0) {
692
+ if (col.defaultFn !== void 0) {
693
+ const defaultFnResult = col.defaultFn();
694
+ generatedIds[fieldName] = defaultFnResult;
695
+ const defaultValue = (0,entity.is)(defaultFnResult, sql/* SQL */.Xs) ? defaultFnResult : sql/* sql */.ll.param(defaultFnResult, col);
696
+ valueList.push(defaultValue);
697
+ } else if (!col.default && col.onUpdateFn !== void 0) {
698
+ const onUpdateFnResult = col.onUpdateFn();
699
+ const newValue = (0,entity.is)(onUpdateFnResult, sql/* SQL */.Xs) ? onUpdateFnResult : sql/* sql */.ll.param(onUpdateFnResult, col);
700
+ valueList.push(newValue);
701
+ } else {
702
+ valueList.push((0,sql/* sql */.ll)`default`);
703
+ }
704
+ } else {
705
+ if (col.defaultFn && (0,entity.is)(colValue, sql/* Param */.Iw)) {
706
+ generatedIds[fieldName] = colValue.value;
707
+ }
708
+ valueList.push(colValue);
709
+ }
710
+ }
711
+ generatedIdsResponse.push(generatedIds);
712
+ valuesSqlList.push(valueList);
713
+ if (valueIndex < values.length - 1) {
714
+ valuesSqlList.push((0,sql/* sql */.ll)`, `);
715
+ }
716
+ }
717
+ }
718
+ const valuesSql = sql/* sql */.ll.join(valuesSqlList);
719
+ const ignoreSql = ignore ? (0,sql/* sql */.ll)` ignore` : void 0;
720
+ const onConflictSql = onConflict ? (0,sql/* sql */.ll)` on duplicate key ${onConflict}` : void 0;
721
+ return {
722
+ sql: (0,sql/* sql */.ll)`insert${ignoreSql} into ${table} ${insertOrder} ${valuesSql}${onConflictSql}`,
723
+ generatedIds: generatedIdsResponse
724
+ };
725
+ }
726
+ sqlToQuery(sql2, invokeSource) {
727
+ return sql2.toQuery({
728
+ casing: this.casing,
729
+ escapeName: this.escapeName,
730
+ escapeParam: this.escapeParam,
731
+ escapeString: this.escapeString,
732
+ invokeSource
733
+ });
734
+ }
735
+ buildRelationalQuery({
736
+ fullSchema,
737
+ schema,
738
+ tableNamesMap,
739
+ table,
740
+ tableConfig,
741
+ queryConfig: config,
742
+ tableAlias,
743
+ nestedQueryRelation,
744
+ joinOn
745
+ }) {
746
+ let selection = [];
747
+ let limit, offset, orderBy, where;
748
+ const joins = [];
749
+ if (config === true) {
750
+ const selectionEntries = Object.entries(tableConfig.columns);
751
+ selection = selectionEntries.map(([key, value]) => ({
752
+ dbKey: value.name,
753
+ tsKey: key,
754
+ field: (0,alias/* aliasedTableColumn */.ug)(value, tableAlias),
755
+ relationTableTsKey: void 0,
756
+ isJson: false,
757
+ selection: []
758
+ }));
759
+ } else {
760
+ const aliasedColumns = Object.fromEntries(
761
+ Object.entries(tableConfig.columns).map(([key, value]) => [key, (0,alias/* aliasedTableColumn */.ug)(value, tableAlias)])
762
+ );
763
+ if (config.where) {
764
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0,relations/* getOperators */.mm)()) : config.where;
765
+ where = whereSql && (0,alias/* mapColumnsInSQLToAlias */.yY)(whereSql, tableAlias);
766
+ }
767
+ const fieldsSelection = [];
768
+ let selectedColumns = [];
769
+ if (config.columns) {
770
+ let isIncludeMode = false;
771
+ for (const [field, value] of Object.entries(config.columns)) {
772
+ if (value === void 0) {
773
+ continue;
774
+ }
775
+ if (field in tableConfig.columns) {
776
+ if (!isIncludeMode && value === true) {
777
+ isIncludeMode = true;
778
+ }
779
+ selectedColumns.push(field);
780
+ }
781
+ }
782
+ if (selectedColumns.length > 0) {
783
+ selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
784
+ }
785
+ } else {
786
+ selectedColumns = Object.keys(tableConfig.columns);
787
+ }
788
+ for (const field of selectedColumns) {
789
+ const column = tableConfig.columns[field];
790
+ fieldsSelection.push({ tsKey: field, value: column });
791
+ }
792
+ let selectedRelations = [];
793
+ if (config.with) {
794
+ selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
795
+ }
796
+ let extras;
797
+ if (config.extras) {
798
+ extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql: sql/* sql */.ll }) : config.extras;
799
+ for (const [tsKey, value] of Object.entries(extras)) {
800
+ fieldsSelection.push({
801
+ tsKey,
802
+ value: (0,alias/* mapColumnsInAliasedSQLToAlias */.Hs)(value, tableAlias)
803
+ });
804
+ }
805
+ }
806
+ for (const { tsKey, value } of fieldsSelection) {
807
+ selection.push({
808
+ dbKey: (0,entity.is)(value, sql/* SQL */.Xs.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
809
+ tsKey,
810
+ field: (0,entity.is)(value, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(value, tableAlias) : value,
811
+ relationTableTsKey: void 0,
812
+ isJson: false,
813
+ selection: []
814
+ });
815
+ }
816
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0,relations/* getOrderByOperators */.rl)()) : config.orderBy ?? [];
817
+ if (!Array.isArray(orderByOrig)) {
818
+ orderByOrig = [orderByOrig];
819
+ }
820
+ orderBy = orderByOrig.map((orderByValue) => {
821
+ if ((0,entity.is)(orderByValue, drizzle_orm_column/* Column */.V)) {
822
+ return (0,alias/* aliasedTableColumn */.ug)(orderByValue, tableAlias);
823
+ }
824
+ return (0,alias/* mapColumnsInSQLToAlias */.yY)(orderByValue, tableAlias);
825
+ });
826
+ limit = config.limit;
827
+ offset = config.offset;
828
+ for (const {
829
+ tsKey: selectedRelationTsKey,
830
+ queryConfig: selectedRelationConfigValue,
831
+ relation
832
+ } of selectedRelations) {
833
+ const normalizedRelation = (0,relations/* normalizeRelation */.W0)(schema, tableNamesMap, relation);
834
+ const relationTableName = (0,drizzle_orm_table/* getTableUniqueName */.Lf)(relation.referencedTable);
835
+ const relationTableTsName = tableNamesMap[relationTableName];
836
+ const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
837
+ const joinOn2 = (0,conditions/* and */.Uo)(
838
+ ...normalizedRelation.fields.map(
839
+ (field2, i) => (0,conditions.eq)(
840
+ (0,alias/* aliasedTableColumn */.ug)(normalizedRelation.references[i], relationTableAlias),
841
+ (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias)
842
+ )
843
+ )
844
+ );
845
+ const builtRelation = this.buildRelationalQuery({
846
+ fullSchema,
847
+ schema,
848
+ tableNamesMap,
849
+ table: fullSchema[relationTableTsName],
850
+ tableConfig: schema[relationTableTsName],
851
+ queryConfig: (0,entity.is)(relation, relations/* One */.pD) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
852
+ tableAlias: relationTableAlias,
853
+ joinOn: joinOn2,
854
+ nestedQueryRelation: relation
855
+ });
856
+ const field = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(relationTableAlias)}.${sql/* sql */.ll.identifier("data")}`.as(selectedRelationTsKey);
857
+ joins.push({
858
+ on: (0,sql/* sql */.ll)`true`,
859
+ table: new subquery/* Subquery */.n(builtRelation.sql, {}, relationTableAlias),
860
+ alias: relationTableAlias,
861
+ joinType: "left",
862
+ lateral: true
863
+ });
864
+ selection.push({
865
+ dbKey: selectedRelationTsKey,
866
+ tsKey: selectedRelationTsKey,
867
+ field,
868
+ relationTableTsKey: relationTableTsName,
869
+ isJson: true,
870
+ selection: builtRelation.selection
871
+ });
872
+ }
873
+ }
874
+ if (selection.length === 0) {
875
+ throw new errors/* DrizzleError */.n({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
876
+ }
877
+ let result;
878
+ where = (0,conditions/* and */.Uo)(joinOn, where);
879
+ if (nestedQueryRelation) {
880
+ let field = (0,sql/* sql */.ll)`json_array(${sql/* sql */.ll.join(
881
+ selection.map(
882
+ ({ field: field2, tsKey, isJson }) => isJson ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(`${tableAlias}_${tsKey}`)}.${sql/* sql */.ll.identifier("data")}` : (0,entity.is)(field2, sql/* SQL */.Xs.Aliased) ? field2.sql : field2
883
+ ),
884
+ (0,sql/* sql */.ll)`, `
885
+ )})`;
886
+ if ((0,entity.is)(nestedQueryRelation, relations/* Many */.iv)) {
887
+ field = (0,sql/* sql */.ll)`coalesce(json_arrayagg(${field}), json_array())`;
888
+ }
889
+ const nestedSelection = [{
890
+ dbKey: "data",
891
+ tsKey: "data",
892
+ field: field.as("data"),
893
+ isJson: true,
894
+ relationTableTsKey: tableConfig.tsName,
895
+ selection
896
+ }];
897
+ const needsSubquery = limit !== void 0 || offset !== void 0 || (orderBy?.length ?? 0) > 0;
898
+ if (needsSubquery) {
899
+ result = this.buildSelectQuery({
900
+ table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
901
+ fields: {},
902
+ fieldsFlat: [
903
+ {
904
+ path: [],
905
+ field: sql/* sql */.ll.raw("*")
906
+ },
907
+ ...((orderBy?.length ?? 0) > 0 ? [{
908
+ path: [],
909
+ field: (0,sql/* sql */.ll)`row_number() over (order by ${sql/* sql */.ll.join(orderBy, (0,sql/* sql */.ll)`, `)})`
910
+ }] : [])
911
+ ],
912
+ where,
913
+ limit,
914
+ offset,
915
+ setOperators: []
916
+ });
917
+ where = void 0;
918
+ limit = void 0;
919
+ offset = void 0;
920
+ orderBy = void 0;
921
+ } else {
922
+ result = (0,alias/* aliasedTable */.oG)(table, tableAlias);
923
+ }
924
+ result = this.buildSelectQuery({
925
+ table: (0,entity.is)(result, mysql_core_table/* MySqlTable */.B$) ? result : new subquery/* Subquery */.n(result, {}, tableAlias),
926
+ fields: {},
927
+ fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
928
+ path: [],
929
+ field: (0,entity.is)(field2, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias) : field2
930
+ })),
931
+ joins,
932
+ where,
933
+ limit,
934
+ offset,
935
+ orderBy,
936
+ setOperators: []
937
+ });
938
+ } else {
939
+ result = this.buildSelectQuery({
940
+ table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
941
+ fields: {},
942
+ fieldsFlat: selection.map(({ field }) => ({
943
+ path: [],
944
+ field: (0,entity.is)(field, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field, tableAlias) : field
945
+ })),
946
+ joins,
947
+ where,
948
+ limit,
949
+ offset,
950
+ orderBy,
951
+ setOperators: []
952
+ });
953
+ }
954
+ return {
955
+ tableTsKey: tableConfig.tsName,
956
+ sql: result,
957
+ selection
958
+ };
959
+ }
960
+ buildRelationalQueryWithoutLateralSubqueries({
961
+ fullSchema,
962
+ schema,
963
+ tableNamesMap,
964
+ table,
965
+ tableConfig,
966
+ queryConfig: config,
967
+ tableAlias,
968
+ nestedQueryRelation,
969
+ joinOn
970
+ }) {
971
+ let selection = [];
972
+ let limit, offset, orderBy = [], where;
973
+ if (config === true) {
974
+ const selectionEntries = Object.entries(tableConfig.columns);
975
+ selection = selectionEntries.map(([key, value]) => ({
976
+ dbKey: value.name,
977
+ tsKey: key,
978
+ field: (0,alias/* aliasedTableColumn */.ug)(value, tableAlias),
979
+ relationTableTsKey: void 0,
980
+ isJson: false,
981
+ selection: []
982
+ }));
983
+ } else {
984
+ const aliasedColumns = Object.fromEntries(
985
+ Object.entries(tableConfig.columns).map(([key, value]) => [key, (0,alias/* aliasedTableColumn */.ug)(value, tableAlias)])
986
+ );
987
+ if (config.where) {
988
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0,relations/* getOperators */.mm)()) : config.where;
989
+ where = whereSql && (0,alias/* mapColumnsInSQLToAlias */.yY)(whereSql, tableAlias);
990
+ }
991
+ const fieldsSelection = [];
992
+ let selectedColumns = [];
993
+ if (config.columns) {
994
+ let isIncludeMode = false;
995
+ for (const [field, value] of Object.entries(config.columns)) {
996
+ if (value === void 0) {
997
+ continue;
998
+ }
999
+ if (field in tableConfig.columns) {
1000
+ if (!isIncludeMode && value === true) {
1001
+ isIncludeMode = true;
1002
+ }
1003
+ selectedColumns.push(field);
1004
+ }
1005
+ }
1006
+ if (selectedColumns.length > 0) {
1007
+ selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
1008
+ }
1009
+ } else {
1010
+ selectedColumns = Object.keys(tableConfig.columns);
1011
+ }
1012
+ for (const field of selectedColumns) {
1013
+ const column = tableConfig.columns[field];
1014
+ fieldsSelection.push({ tsKey: field, value: column });
1015
+ }
1016
+ let selectedRelations = [];
1017
+ if (config.with) {
1018
+ selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
1019
+ }
1020
+ let extras;
1021
+ if (config.extras) {
1022
+ extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql: sql/* sql */.ll }) : config.extras;
1023
+ for (const [tsKey, value] of Object.entries(extras)) {
1024
+ fieldsSelection.push({
1025
+ tsKey,
1026
+ value: (0,alias/* mapColumnsInAliasedSQLToAlias */.Hs)(value, tableAlias)
1027
+ });
1028
+ }
1029
+ }
1030
+ for (const { tsKey, value } of fieldsSelection) {
1031
+ selection.push({
1032
+ dbKey: (0,entity.is)(value, sql/* SQL */.Xs.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
1033
+ tsKey,
1034
+ field: (0,entity.is)(value, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(value, tableAlias) : value,
1035
+ relationTableTsKey: void 0,
1036
+ isJson: false,
1037
+ selection: []
1038
+ });
1039
+ }
1040
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0,relations/* getOrderByOperators */.rl)()) : config.orderBy ?? [];
1041
+ if (!Array.isArray(orderByOrig)) {
1042
+ orderByOrig = [orderByOrig];
1043
+ }
1044
+ orderBy = orderByOrig.map((orderByValue) => {
1045
+ if ((0,entity.is)(orderByValue, drizzle_orm_column/* Column */.V)) {
1046
+ return (0,alias/* aliasedTableColumn */.ug)(orderByValue, tableAlias);
1047
+ }
1048
+ return (0,alias/* mapColumnsInSQLToAlias */.yY)(orderByValue, tableAlias);
1049
+ });
1050
+ limit = config.limit;
1051
+ offset = config.offset;
1052
+ for (const {
1053
+ tsKey: selectedRelationTsKey,
1054
+ queryConfig: selectedRelationConfigValue,
1055
+ relation
1056
+ } of selectedRelations) {
1057
+ const normalizedRelation = (0,relations/* normalizeRelation */.W0)(schema, tableNamesMap, relation);
1058
+ const relationTableName = (0,drizzle_orm_table/* getTableUniqueName */.Lf)(relation.referencedTable);
1059
+ const relationTableTsName = tableNamesMap[relationTableName];
1060
+ const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
1061
+ const joinOn2 = (0,conditions/* and */.Uo)(
1062
+ ...normalizedRelation.fields.map(
1063
+ (field2, i) => (0,conditions.eq)(
1064
+ (0,alias/* aliasedTableColumn */.ug)(normalizedRelation.references[i], relationTableAlias),
1065
+ (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias)
1066
+ )
1067
+ )
1068
+ );
1069
+ const builtRelation = this.buildRelationalQueryWithoutLateralSubqueries({
1070
+ fullSchema,
1071
+ schema,
1072
+ tableNamesMap,
1073
+ table: fullSchema[relationTableTsName],
1074
+ tableConfig: schema[relationTableTsName],
1075
+ queryConfig: (0,entity.is)(relation, relations/* One */.pD) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
1076
+ tableAlias: relationTableAlias,
1077
+ joinOn: joinOn2,
1078
+ nestedQueryRelation: relation
1079
+ });
1080
+ let fieldSql = (0,sql/* sql */.ll)`(${builtRelation.sql})`;
1081
+ if ((0,entity.is)(relation, relations/* Many */.iv)) {
1082
+ fieldSql = (0,sql/* sql */.ll)`coalesce(${fieldSql}, json_array())`;
1083
+ }
1084
+ const field = fieldSql.as(selectedRelationTsKey);
1085
+ selection.push({
1086
+ dbKey: selectedRelationTsKey,
1087
+ tsKey: selectedRelationTsKey,
1088
+ field,
1089
+ relationTableTsKey: relationTableTsName,
1090
+ isJson: true,
1091
+ selection: builtRelation.selection
1092
+ });
1093
+ }
1094
+ }
1095
+ if (selection.length === 0) {
1096
+ throw new errors/* DrizzleError */.n({
1097
+ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`
1098
+ });
1099
+ }
1100
+ let result;
1101
+ where = (0,conditions/* and */.Uo)(joinOn, where);
1102
+ if (nestedQueryRelation) {
1103
+ let field = (0,sql/* sql */.ll)`json_array(${sql/* sql */.ll.join(
1104
+ selection.map(
1105
+ ({ field: field2 }) => (0,entity.is)(field2, common/* MySqlColumn */.rI) ? sql/* sql */.ll.identifier(this.casing.getColumnCasing(field2)) : (0,entity.is)(field2, sql/* SQL */.Xs.Aliased) ? field2.sql : field2
1106
+ ),
1107
+ (0,sql/* sql */.ll)`, `
1108
+ )})`;
1109
+ if ((0,entity.is)(nestedQueryRelation, relations/* Many */.iv)) {
1110
+ field = (0,sql/* sql */.ll)`json_arrayagg(${field})`;
1111
+ }
1112
+ const nestedSelection = [{
1113
+ dbKey: "data",
1114
+ tsKey: "data",
1115
+ field,
1116
+ isJson: true,
1117
+ relationTableTsKey: tableConfig.tsName,
1118
+ selection
1119
+ }];
1120
+ const needsSubquery = limit !== void 0 || offset !== void 0 || orderBy.length > 0;
1121
+ if (needsSubquery) {
1122
+ result = this.buildSelectQuery({
1123
+ table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
1124
+ fields: {},
1125
+ fieldsFlat: [
1126
+ {
1127
+ path: [],
1128
+ field: sql/* sql */.ll.raw("*")
1129
+ },
1130
+ ...(orderBy.length > 0 ? [{
1131
+ path: [],
1132
+ field: (0,sql/* sql */.ll)`row_number() over (order by ${sql/* sql */.ll.join(orderBy, (0,sql/* sql */.ll)`, `)})`
1133
+ }] : [])
1134
+ ],
1135
+ where,
1136
+ limit,
1137
+ offset,
1138
+ setOperators: []
1139
+ });
1140
+ where = void 0;
1141
+ limit = void 0;
1142
+ offset = void 0;
1143
+ orderBy = void 0;
1144
+ } else {
1145
+ result = (0,alias/* aliasedTable */.oG)(table, tableAlias);
1146
+ }
1147
+ result = this.buildSelectQuery({
1148
+ table: (0,entity.is)(result, mysql_core_table/* MySqlTable */.B$) ? result : new subquery/* Subquery */.n(result, {}, tableAlias),
1149
+ fields: {},
1150
+ fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
1151
+ path: [],
1152
+ field: (0,entity.is)(field2, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias) : field2
1153
+ })),
1154
+ where,
1155
+ limit,
1156
+ offset,
1157
+ orderBy,
1158
+ setOperators: []
1159
+ });
1160
+ } else {
1161
+ result = this.buildSelectQuery({
1162
+ table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
1163
+ fields: {},
1164
+ fieldsFlat: selection.map(({ field }) => ({
1165
+ path: [],
1166
+ field: (0,entity.is)(field, drizzle_orm_column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field, tableAlias) : field
1167
+ })),
1168
+ where,
1169
+ limit,
1170
+ offset,
1171
+ orderBy,
1172
+ setOperators: []
1173
+ });
1174
+ }
1175
+ return {
1176
+ tableTsKey: tableConfig.tsName,
1177
+ sql: result,
1178
+ selection
1179
+ };
1180
+ }
1181
+ }
1182
+
1183
+ //# sourceMappingURL=dialect.js.map
1184
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-builders/query-builder.js
1185
+ var query_builder = __webpack_require__(6685);
1186
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-promise.js
1187
+ var query_promise = __webpack_require__(4579);
1188
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/select.js
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+ class MySqlSelectBuilder {
1201
+ static [entity/* entityKind */.i] = "MySqlSelectBuilder";
1202
+ fields;
1203
+ session;
1204
+ dialect;
1205
+ withList = [];
1206
+ distinct;
1207
+ constructor(config) {
1208
+ this.fields = config.fields;
1209
+ this.session = config.session;
1210
+ this.dialect = config.dialect;
1211
+ if (config.withList) {
1212
+ this.withList = config.withList;
1213
+ }
1214
+ this.distinct = config.distinct;
1215
+ }
1216
+ from(source) {
1217
+ const isPartialSelect = !!this.fields;
1218
+ let fields;
1219
+ if (this.fields) {
1220
+ fields = this.fields;
1221
+ } else if ((0,entity.is)(source, subquery/* Subquery */.n)) {
1222
+ fields = Object.fromEntries(
1223
+ Object.keys(source._.selectedFields).map((key) => [key, source[key]])
1224
+ );
1225
+ } else if ((0,entity.is)(source, MySqlViewBase)) {
1226
+ fields = source[view_common/* ViewBaseConfig */.n].selectedFields;
1227
+ } else if ((0,entity.is)(source, sql/* SQL */.Xs)) {
1228
+ fields = {};
1229
+ } else {
1230
+ fields = (0,utils/* getTableColumns */.YD)(source);
1231
+ }
1232
+ return new MySqlSelectBase(
1233
+ {
1234
+ table: source,
1235
+ fields,
1236
+ isPartialSelect,
1237
+ session: this.session,
1238
+ dialect: this.dialect,
1239
+ withList: this.withList,
1240
+ distinct: this.distinct
1241
+ }
1242
+ );
1243
+ }
1244
+ }
1245
+ class MySqlSelectQueryBuilderBase extends query_builder/* TypedQueryBuilder */.O {
1246
+ static [entity/* entityKind */.i] = "MySqlSelectQueryBuilder";
1247
+ _;
1248
+ config;
1249
+ joinsNotNullableMap;
1250
+ tableName;
1251
+ isPartialSelect;
1252
+ /** @internal */
1253
+ session;
1254
+ dialect;
1255
+ constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
1256
+ super();
1257
+ this.config = {
1258
+ withList,
1259
+ table,
1260
+ fields: { ...fields },
1261
+ distinct,
1262
+ setOperators: []
1263
+ };
1264
+ this.isPartialSelect = isPartialSelect;
1265
+ this.session = session;
1266
+ this.dialect = dialect;
1267
+ this._ = {
1268
+ selectedFields: fields
1269
+ };
1270
+ this.tableName = (0,utils/* getTableLikeName */.zN)(table);
1271
+ this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
1272
+ }
1273
+ createJoin(joinType) {
1274
+ return (table, on) => {
1275
+ const baseTableName = this.tableName;
1276
+ const tableName = (0,utils/* getTableLikeName */.zN)(table);
1277
+ if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
1278
+ throw new Error(`Alias "${tableName}" is already used in this query`);
1279
+ }
1280
+ if (!this.isPartialSelect) {
1281
+ if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
1282
+ this.config.fields = {
1283
+ [baseTableName]: this.config.fields
1284
+ };
1285
+ }
1286
+ if (typeof tableName === "string" && !(0,entity.is)(table, sql/* SQL */.Xs)) {
1287
+ const selection = (0,entity.is)(table, subquery/* Subquery */.n) ? table._.selectedFields : (0,entity.is)(table, sql/* View */.Ss) ? table[view_common/* ViewBaseConfig */.n].selectedFields : table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
1288
+ this.config.fields[tableName] = selection;
1289
+ }
1290
+ }
1291
+ if (typeof on === "function") {
1292
+ on = on(
1293
+ new Proxy(
1294
+ this.config.fields,
1295
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1296
+ )
1297
+ );
1298
+ }
1299
+ if (!this.config.joins) {
1300
+ this.config.joins = [];
1301
+ }
1302
+ this.config.joins.push({ on, table, joinType, alias: tableName });
1303
+ if (typeof tableName === "string") {
1304
+ switch (joinType) {
1305
+ case "left": {
1306
+ this.joinsNotNullableMap[tableName] = false;
1307
+ break;
1308
+ }
1309
+ case "right": {
1310
+ this.joinsNotNullableMap = Object.fromEntries(
1311
+ Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
1312
+ );
1313
+ this.joinsNotNullableMap[tableName] = true;
1314
+ break;
1315
+ }
1316
+ case "inner": {
1317
+ this.joinsNotNullableMap[tableName] = true;
1318
+ break;
1319
+ }
1320
+ case "full": {
1321
+ this.joinsNotNullableMap = Object.fromEntries(
1322
+ Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
1323
+ );
1324
+ this.joinsNotNullableMap[tableName] = false;
1325
+ break;
1326
+ }
1327
+ }
1328
+ }
1329
+ return this;
1330
+ };
1331
+ }
1332
+ /**
1333
+ * Executes a `left join` operation by adding another table to the current query.
1334
+ *
1335
+ * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
1336
+ *
1337
+ * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
1338
+ *
1339
+ * @param table the table to join.
1340
+ * @param on the `on` clause.
1341
+ *
1342
+ * @example
1343
+ *
1344
+ * ```ts
1345
+ * // Select all users and their pets
1346
+ * const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
1347
+ * .from(users)
1348
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
1349
+ *
1350
+ * // Select userId and petId
1351
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
1352
+ * userId: users.id,
1353
+ * petId: pets.id,
1354
+ * })
1355
+ * .from(users)
1356
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
1357
+ * ```
1358
+ */
1359
+ leftJoin = this.createJoin("left");
1360
+ /**
1361
+ * Executes a `right join` operation by adding another table to the current query.
1362
+ *
1363
+ * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
1364
+ *
1365
+ * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
1366
+ *
1367
+ * @param table the table to join.
1368
+ * @param on the `on` clause.
1369
+ *
1370
+ * @example
1371
+ *
1372
+ * ```ts
1373
+ * // Select all users and their pets
1374
+ * const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
1375
+ * .from(users)
1376
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
1377
+ *
1378
+ * // Select userId and petId
1379
+ * const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
1380
+ * userId: users.id,
1381
+ * petId: pets.id,
1382
+ * })
1383
+ * .from(users)
1384
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
1385
+ * ```
1386
+ */
1387
+ rightJoin = this.createJoin("right");
1388
+ /**
1389
+ * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
1390
+ *
1391
+ * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
1392
+ *
1393
+ * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
1394
+ *
1395
+ * @param table the table to join.
1396
+ * @param on the `on` clause.
1397
+ *
1398
+ * @example
1399
+ *
1400
+ * ```ts
1401
+ * // Select all users and their pets
1402
+ * const usersWithPets: { user: User; pets: Pet }[] = await db.select()
1403
+ * .from(users)
1404
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
1405
+ *
1406
+ * // Select userId and petId
1407
+ * const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
1408
+ * userId: users.id,
1409
+ * petId: pets.id,
1410
+ * })
1411
+ * .from(users)
1412
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
1413
+ * ```
1414
+ */
1415
+ innerJoin = this.createJoin("inner");
1416
+ /**
1417
+ * Executes a `full join` operation by combining rows from two tables into a new table.
1418
+ *
1419
+ * Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
1420
+ *
1421
+ * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
1422
+ *
1423
+ * @param table the table to join.
1424
+ * @param on the `on` clause.
1425
+ *
1426
+ * @example
1427
+ *
1428
+ * ```ts
1429
+ * // Select all users and their pets
1430
+ * const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
1431
+ * .from(users)
1432
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
1433
+ *
1434
+ * // Select userId and petId
1435
+ * const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
1436
+ * userId: users.id,
1437
+ * petId: pets.id,
1438
+ * })
1439
+ * .from(users)
1440
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
1441
+ * ```
1442
+ */
1443
+ fullJoin = this.createJoin("full");
1444
+ createSetOperator(type, isAll) {
1445
+ return (rightSelection) => {
1446
+ const rightSelect = typeof rightSelection === "function" ? rightSelection(getMySqlSetOperators()) : rightSelection;
1447
+ if (!(0,utils/* haveSameKeys */.DV)(this.getSelectedFields(), rightSelect.getSelectedFields())) {
1448
+ throw new Error(
1449
+ "Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
1450
+ );
1451
+ }
1452
+ this.config.setOperators.push({ type, isAll, rightSelect });
1453
+ return this;
1454
+ };
1455
+ }
1456
+ /**
1457
+ * Adds `union` set operator to the query.
1458
+ *
1459
+ * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
1460
+ *
1461
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
1462
+ *
1463
+ * @example
1464
+ *
1465
+ * ```ts
1466
+ * // Select all unique names from customers and users tables
1467
+ * await db.select({ name: users.name })
1468
+ * .from(users)
1469
+ * .union(
1470
+ * db.select({ name: customers.name }).from(customers)
1471
+ * );
1472
+ * // or
1473
+ * import { union } from 'drizzle-orm/mysql-core'
1474
+ *
1475
+ * await union(
1476
+ * db.select({ name: users.name }).from(users),
1477
+ * db.select({ name: customers.name }).from(customers)
1478
+ * );
1479
+ * ```
1480
+ */
1481
+ union = this.createSetOperator("union", false);
1482
+ /**
1483
+ * Adds `union all` set operator to the query.
1484
+ *
1485
+ * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
1486
+ *
1487
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
1488
+ *
1489
+ * @example
1490
+ *
1491
+ * ```ts
1492
+ * // Select all transaction ids from both online and in-store sales
1493
+ * await db.select({ transaction: onlineSales.transactionId })
1494
+ * .from(onlineSales)
1495
+ * .unionAll(
1496
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
1497
+ * );
1498
+ * // or
1499
+ * import { unionAll } from 'drizzle-orm/mysql-core'
1500
+ *
1501
+ * await unionAll(
1502
+ * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
1503
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
1504
+ * );
1505
+ * ```
1506
+ */
1507
+ unionAll = this.createSetOperator("union", true);
1508
+ /**
1509
+ * Adds `intersect` set operator to the query.
1510
+ *
1511
+ * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
1512
+ *
1513
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
1514
+ *
1515
+ * @example
1516
+ *
1517
+ * ```ts
1518
+ * // Select course names that are offered in both departments A and B
1519
+ * await db.select({ courseName: depA.courseName })
1520
+ * .from(depA)
1521
+ * .intersect(
1522
+ * db.select({ courseName: depB.courseName }).from(depB)
1523
+ * );
1524
+ * // or
1525
+ * import { intersect } from 'drizzle-orm/mysql-core'
1526
+ *
1527
+ * await intersect(
1528
+ * db.select({ courseName: depA.courseName }).from(depA),
1529
+ * db.select({ courseName: depB.courseName }).from(depB)
1530
+ * );
1531
+ * ```
1532
+ */
1533
+ intersect = this.createSetOperator("intersect", false);
1534
+ /**
1535
+ * Adds `intersect all` set operator to the query.
1536
+ *
1537
+ * Calling this method will retain only the rows that are present in both result sets including all duplicates.
1538
+ *
1539
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
1540
+ *
1541
+ * @example
1542
+ *
1543
+ * ```ts
1544
+ * // Select all products and quantities that are ordered by both regular and VIP customers
1545
+ * await db.select({
1546
+ * productId: regularCustomerOrders.productId,
1547
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
1548
+ * })
1549
+ * .from(regularCustomerOrders)
1550
+ * .intersectAll(
1551
+ * db.select({
1552
+ * productId: vipCustomerOrders.productId,
1553
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
1554
+ * })
1555
+ * .from(vipCustomerOrders)
1556
+ * );
1557
+ * // or
1558
+ * import { intersectAll } from 'drizzle-orm/mysql-core'
1559
+ *
1560
+ * await intersectAll(
1561
+ * db.select({
1562
+ * productId: regularCustomerOrders.productId,
1563
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
1564
+ * })
1565
+ * .from(regularCustomerOrders),
1566
+ * db.select({
1567
+ * productId: vipCustomerOrders.productId,
1568
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
1569
+ * })
1570
+ * .from(vipCustomerOrders)
1571
+ * );
1572
+ * ```
1573
+ */
1574
+ intersectAll = this.createSetOperator("intersect", true);
1575
+ /**
1576
+ * Adds `except` set operator to the query.
1577
+ *
1578
+ * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
1579
+ *
1580
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
1581
+ *
1582
+ * @example
1583
+ *
1584
+ * ```ts
1585
+ * // Select all courses offered in department A but not in department B
1586
+ * await db.select({ courseName: depA.courseName })
1587
+ * .from(depA)
1588
+ * .except(
1589
+ * db.select({ courseName: depB.courseName }).from(depB)
1590
+ * );
1591
+ * // or
1592
+ * import { except } from 'drizzle-orm/mysql-core'
1593
+ *
1594
+ * await except(
1595
+ * db.select({ courseName: depA.courseName }).from(depA),
1596
+ * db.select({ courseName: depB.courseName }).from(depB)
1597
+ * );
1598
+ * ```
1599
+ */
1600
+ except = this.createSetOperator("except", false);
1601
+ /**
1602
+ * Adds `except all` set operator to the query.
1603
+ *
1604
+ * Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
1605
+ *
1606
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
1607
+ *
1608
+ * @example
1609
+ *
1610
+ * ```ts
1611
+ * // Select all products that are ordered by regular customers but not by VIP customers
1612
+ * await db.select({
1613
+ * productId: regularCustomerOrders.productId,
1614
+ * quantityOrdered: regularCustomerOrders.quantityOrdered,
1615
+ * })
1616
+ * .from(regularCustomerOrders)
1617
+ * .exceptAll(
1618
+ * db.select({
1619
+ * productId: vipCustomerOrders.productId,
1620
+ * quantityOrdered: vipCustomerOrders.quantityOrdered,
1621
+ * })
1622
+ * .from(vipCustomerOrders)
1623
+ * );
1624
+ * // or
1625
+ * import { exceptAll } from 'drizzle-orm/mysql-core'
1626
+ *
1627
+ * await exceptAll(
1628
+ * db.select({
1629
+ * productId: regularCustomerOrders.productId,
1630
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
1631
+ * })
1632
+ * .from(regularCustomerOrders),
1633
+ * db.select({
1634
+ * productId: vipCustomerOrders.productId,
1635
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
1636
+ * })
1637
+ * .from(vipCustomerOrders)
1638
+ * );
1639
+ * ```
1640
+ */
1641
+ exceptAll = this.createSetOperator("except", true);
1642
+ /** @internal */
1643
+ addSetOperators(setOperators) {
1644
+ this.config.setOperators.push(...setOperators);
1645
+ return this;
1646
+ }
1647
+ /**
1648
+ * Adds a `where` clause to the query.
1649
+ *
1650
+ * Calling this method will select only those rows that fulfill a specified condition.
1651
+ *
1652
+ * See docs: {@link https://orm.drizzle.team/docs/select#filtering}
1653
+ *
1654
+ * @param where the `where` clause.
1655
+ *
1656
+ * @example
1657
+ * You can use conditional operators and `sql function` to filter the rows to be selected.
1658
+ *
1659
+ * ```ts
1660
+ * // Select all cars with green color
1661
+ * await db.select().from(cars).where(eq(cars.color, 'green'));
1662
+ * // or
1663
+ * await db.select().from(cars).where(sql`${cars.color} = 'green'`)
1664
+ * ```
1665
+ *
1666
+ * You can logically combine conditional operators with `and()` and `or()` operators:
1667
+ *
1668
+ * ```ts
1669
+ * // Select all BMW cars with a green color
1670
+ * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
1671
+ *
1672
+ * // Select all cars with the green or blue color
1673
+ * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
1674
+ * ```
1675
+ */
1676
+ where(where) {
1677
+ if (typeof where === "function") {
1678
+ where = where(
1679
+ new Proxy(
1680
+ this.config.fields,
1681
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1682
+ )
1683
+ );
1684
+ }
1685
+ this.config.where = where;
1686
+ return this;
1687
+ }
1688
+ /**
1689
+ * Adds a `having` clause to the query.
1690
+ *
1691
+ * Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
1692
+ *
1693
+ * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
1694
+ *
1695
+ * @param having the `having` clause.
1696
+ *
1697
+ * @example
1698
+ *
1699
+ * ```ts
1700
+ * // Select all brands with more than one car
1701
+ * await db.select({
1702
+ * brand: cars.brand,
1703
+ * count: sql<number>`cast(count(${cars.id}) as int)`,
1704
+ * })
1705
+ * .from(cars)
1706
+ * .groupBy(cars.brand)
1707
+ * .having(({ count }) => gt(count, 1));
1708
+ * ```
1709
+ */
1710
+ having(having) {
1711
+ if (typeof having === "function") {
1712
+ having = having(
1713
+ new Proxy(
1714
+ this.config.fields,
1715
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1716
+ )
1717
+ );
1718
+ }
1719
+ this.config.having = having;
1720
+ return this;
1721
+ }
1722
+ groupBy(...columns) {
1723
+ if (typeof columns[0] === "function") {
1724
+ const groupBy = columns[0](
1725
+ new Proxy(
1726
+ this.config.fields,
1727
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
1728
+ )
1729
+ );
1730
+ this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
1731
+ } else {
1732
+ this.config.groupBy = columns;
1733
+ }
1734
+ return this;
1735
+ }
1736
+ orderBy(...columns) {
1737
+ if (typeof columns[0] === "function") {
1738
+ const orderBy = columns[0](
1739
+ new Proxy(
1740
+ this.config.fields,
1741
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
1742
+ )
1743
+ );
1744
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
1745
+ if (this.config.setOperators.length > 0) {
1746
+ this.config.setOperators.at(-1).orderBy = orderByArray;
1747
+ } else {
1748
+ this.config.orderBy = orderByArray;
1749
+ }
1750
+ } else {
1751
+ const orderByArray = columns;
1752
+ if (this.config.setOperators.length > 0) {
1753
+ this.config.setOperators.at(-1).orderBy = orderByArray;
1754
+ } else {
1755
+ this.config.orderBy = orderByArray;
1756
+ }
1757
+ }
1758
+ return this;
1759
+ }
1760
+ /**
1761
+ * Adds a `limit` clause to the query.
1762
+ *
1763
+ * Calling this method will set the maximum number of rows that will be returned by this query.
1764
+ *
1765
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
1766
+ *
1767
+ * @param limit the `limit` clause.
1768
+ *
1769
+ * @example
1770
+ *
1771
+ * ```ts
1772
+ * // Get the first 10 people from this query.
1773
+ * await db.select().from(people).limit(10);
1774
+ * ```
1775
+ */
1776
+ limit(limit) {
1777
+ if (this.config.setOperators.length > 0) {
1778
+ this.config.setOperators.at(-1).limit = limit;
1779
+ } else {
1780
+ this.config.limit = limit;
1781
+ }
1782
+ return this;
1783
+ }
1784
+ /**
1785
+ * Adds an `offset` clause to the query.
1786
+ *
1787
+ * Calling this method will skip a number of rows when returning results from this query.
1788
+ *
1789
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
1790
+ *
1791
+ * @param offset the `offset` clause.
1792
+ *
1793
+ * @example
1794
+ *
1795
+ * ```ts
1796
+ * // Get the 10th-20th people from this query.
1797
+ * await db.select().from(people).offset(10).limit(10);
1798
+ * ```
1799
+ */
1800
+ offset(offset) {
1801
+ if (this.config.setOperators.length > 0) {
1802
+ this.config.setOperators.at(-1).offset = offset;
1803
+ } else {
1804
+ this.config.offset = offset;
1805
+ }
1806
+ return this;
1807
+ }
1808
+ /**
1809
+ * Adds a `for` clause to the query.
1810
+ *
1811
+ * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.
1812
+ *
1813
+ * See docs: {@link https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html}
1814
+ *
1815
+ * @param strength the lock strength.
1816
+ * @param config the lock configuration.
1817
+ */
1818
+ for(strength, config = {}) {
1819
+ this.config.lockingClause = { strength, config };
1820
+ return this;
1821
+ }
1822
+ /** @internal */
1823
+ getSQL() {
1824
+ return this.dialect.buildSelectQuery(this.config);
1825
+ }
1826
+ toSQL() {
1827
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
1828
+ return rest;
1829
+ }
1830
+ as(alias) {
1831
+ return new Proxy(
1832
+ new subquery/* Subquery */.n(this.getSQL(), this.config.fields, alias),
1833
+ new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1834
+ );
1835
+ }
1836
+ /** @internal */
1837
+ getSelectedFields() {
1838
+ return new Proxy(
1839
+ this.config.fields,
1840
+ new selection_proxy/* SelectionProxyHandler */.b({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1841
+ );
1842
+ }
1843
+ $dynamic() {
1844
+ return this;
1845
+ }
1846
+ }
1847
+ class MySqlSelectBase extends MySqlSelectQueryBuilderBase {
1848
+ static [entity/* entityKind */.i] = "MySqlSelect";
1849
+ prepare() {
1850
+ if (!this.session) {
1851
+ throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
1852
+ }
1853
+ const fieldsList = (0,utils/* orderSelectedFields */.He)(this.config.fields);
1854
+ const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), fieldsList);
1855
+ query.joinsNotNullableMap = this.joinsNotNullableMap;
1856
+ return query;
1857
+ }
1858
+ execute = (placeholderValues) => {
1859
+ return this.prepare().execute(placeholderValues);
1860
+ };
1861
+ createIterator = () => {
1862
+ const self = this;
1863
+ return async function* (placeholderValues) {
1864
+ yield* self.prepare().iterator(placeholderValues);
1865
+ };
1866
+ };
1867
+ iterator = this.createIterator();
1868
+ }
1869
+ (0,utils/* applyMixins */.XJ)(MySqlSelectBase, [query_promise/* QueryPromise */.k]);
1870
+ function createSetOperator(type, isAll) {
1871
+ return (leftSelect, rightSelect, ...restSelects) => {
1872
+ const setOperators = [rightSelect, ...restSelects].map((select) => ({
1873
+ type,
1874
+ isAll,
1875
+ rightSelect: select
1876
+ }));
1877
+ for (const setOperator of setOperators) {
1878
+ if (!(0,utils/* haveSameKeys */.DV)(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
1879
+ throw new Error(
1880
+ "Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
1881
+ );
1882
+ }
1883
+ }
1884
+ return leftSelect.addSetOperators(setOperators);
1885
+ };
1886
+ }
1887
+ const getMySqlSetOperators = () => ({
1888
+ union,
1889
+ unionAll,
1890
+ intersect,
1891
+ intersectAll,
1892
+ except,
1893
+ exceptAll
1894
+ });
1895
+ const union = createSetOperator("union", false);
1896
+ const unionAll = createSetOperator("union", true);
1897
+ const intersect = createSetOperator("intersect", false);
1898
+ const intersectAll = createSetOperator("intersect", true);
1899
+ const except = createSetOperator("except", false);
1900
+ const exceptAll = createSetOperator("except", true);
1901
+
1902
+ //# sourceMappingURL=select.js.map
1903
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/query-builder.js
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+ class QueryBuilder {
1910
+ static [entity/* entityKind */.i] = "MySqlQueryBuilder";
1911
+ dialect;
1912
+ dialectConfig;
1913
+ constructor(dialect) {
1914
+ this.dialect = (0,entity.is)(dialect, MySqlDialect) ? dialect : void 0;
1915
+ this.dialectConfig = (0,entity.is)(dialect, MySqlDialect) ? void 0 : dialect;
1916
+ }
1917
+ $with(alias) {
1918
+ const queryBuilder = this;
1919
+ return {
1920
+ as(qb) {
1921
+ if (typeof qb === "function") {
1922
+ qb = qb(queryBuilder);
1923
+ }
1924
+ return new Proxy(
1925
+ new subquery/* WithSubquery */.J(qb.getSQL(), qb.getSelectedFields(), alias, true),
1926
+ new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1927
+ );
1928
+ }
1929
+ };
1930
+ }
1931
+ with(...queries) {
1932
+ const self = this;
1933
+ function select(fields) {
1934
+ return new MySqlSelectBuilder({
1935
+ fields: fields ?? void 0,
1936
+ session: void 0,
1937
+ dialect: self.getDialect(),
1938
+ withList: queries
1939
+ });
1940
+ }
1941
+ function selectDistinct(fields) {
1942
+ return new MySqlSelectBuilder({
1943
+ fields: fields ?? void 0,
1944
+ session: void 0,
1945
+ dialect: self.getDialect(),
1946
+ withList: queries,
1947
+ distinct: true
1948
+ });
1949
+ }
1950
+ return { select, selectDistinct };
1951
+ }
1952
+ select(fields) {
1953
+ return new MySqlSelectBuilder({ fields: fields ?? void 0, session: void 0, dialect: this.getDialect() });
1954
+ }
1955
+ selectDistinct(fields) {
1956
+ return new MySqlSelectBuilder({
1957
+ fields: fields ?? void 0,
1958
+ session: void 0,
1959
+ dialect: this.getDialect(),
1960
+ distinct: true
1961
+ });
1962
+ }
1963
+ // Lazy load dialect to avoid circular dependency
1964
+ getDialect() {
1965
+ if (!this.dialect) {
1966
+ this.dialect = new MySqlDialect(this.dialectConfig);
1967
+ }
1968
+ return this.dialect;
1969
+ }
1970
+ }
1971
+
1972
+ //# sourceMappingURL=query-builder.js.map
1973
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/update.js
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+ class MySqlUpdateBuilder {
1980
+ constructor(table, session, dialect, withList) {
1981
+ this.table = table;
1982
+ this.session = session;
1983
+ this.dialect = dialect;
1984
+ this.withList = withList;
1985
+ }
1986
+ static [entity/* entityKind */.i] = "MySqlUpdateBuilder";
1987
+ set(values) {
1988
+ return new MySqlUpdateBase(this.table, (0,utils/* mapUpdateSet */.q)(this.table, values), this.session, this.dialect, this.withList);
1989
+ }
1990
+ }
1991
+ class MySqlUpdateBase extends query_promise/* QueryPromise */.k {
1992
+ constructor(table, set, session, dialect, withList) {
1993
+ super();
1994
+ this.session = session;
1995
+ this.dialect = dialect;
1996
+ this.config = { set, table, withList };
1997
+ }
1998
+ static [entity/* entityKind */.i] = "MySqlUpdate";
1999
+ config;
2000
+ /**
2001
+ * Adds a 'where' clause to the query.
2002
+ *
2003
+ * Calling this method will update only those rows that fulfill a specified condition.
2004
+ *
2005
+ * See docs: {@link https://orm.drizzle.team/docs/update}
2006
+ *
2007
+ * @param where the 'where' clause.
2008
+ *
2009
+ * @example
2010
+ * You can use conditional operators and `sql function` to filter the rows to be updated.
2011
+ *
2012
+ * ```ts
2013
+ * // Update all cars with green color
2014
+ * db.update(cars).set({ color: 'red' })
2015
+ * .where(eq(cars.color, 'green'));
2016
+ * // or
2017
+ * db.update(cars).set({ color: 'red' })
2018
+ * .where(sql`${cars.color} = 'green'`)
2019
+ * ```
2020
+ *
2021
+ * You can logically combine conditional operators with `and()` and `or()` operators:
2022
+ *
2023
+ * ```ts
2024
+ * // Update all BMW cars with a green color
2025
+ * db.update(cars).set({ color: 'red' })
2026
+ * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
2027
+ *
2028
+ * // Update all cars with the green or blue color
2029
+ * db.update(cars).set({ color: 'red' })
2030
+ * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
2031
+ * ```
2032
+ */
2033
+ where(where) {
2034
+ this.config.where = where;
2035
+ return this;
2036
+ }
2037
+ orderBy(...columns) {
2038
+ if (typeof columns[0] === "function") {
2039
+ const orderBy = columns[0](
2040
+ new Proxy(
2041
+ this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns],
2042
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
2043
+ )
2044
+ );
2045
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
2046
+ this.config.orderBy = orderByArray;
2047
+ } else {
2048
+ const orderByArray = columns;
2049
+ this.config.orderBy = orderByArray;
2050
+ }
2051
+ return this;
2052
+ }
2053
+ limit(limit) {
2054
+ this.config.limit = limit;
2055
+ return this;
2056
+ }
2057
+ /** @internal */
2058
+ getSQL() {
2059
+ return this.dialect.buildUpdateQuery(this.config);
2060
+ }
2061
+ toSQL() {
2062
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
2063
+ return rest;
2064
+ }
2065
+ prepare() {
2066
+ return this.session.prepareQuery(
2067
+ this.dialect.sqlToQuery(this.getSQL()),
2068
+ this.config.returning
2069
+ );
2070
+ }
2071
+ execute = (placeholderValues) => {
2072
+ return this.prepare().execute(placeholderValues);
2073
+ };
2074
+ createIterator = () => {
2075
+ const self = this;
2076
+ return async function* (placeholderValues) {
2077
+ yield* self.prepare().iterator(placeholderValues);
2078
+ };
2079
+ };
2080
+ iterator = this.createIterator();
2081
+ $dynamic() {
2082
+ return this;
2083
+ }
2084
+ }
2085
+
2086
+ //# sourceMappingURL=update.js.map
2087
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/delete.js
2088
+
2089
+
2090
+
2091
+
2092
+ class MySqlDeleteBase extends query_promise/* QueryPromise */.k {
2093
+ constructor(table, session, dialect, withList) {
2094
+ super();
2095
+ this.table = table;
2096
+ this.session = session;
2097
+ this.dialect = dialect;
2098
+ this.config = { table, withList };
2099
+ }
2100
+ static [entity/* entityKind */.i] = "MySqlDelete";
2101
+ config;
2102
+ /**
2103
+ * Adds a `where` clause to the query.
2104
+ *
2105
+ * Calling this method will delete only those rows that fulfill a specified condition.
2106
+ *
2107
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
2108
+ *
2109
+ * @param where the `where` clause.
2110
+ *
2111
+ * @example
2112
+ * You can use conditional operators and `sql function` to filter the rows to be deleted.
2113
+ *
2114
+ * ```ts
2115
+ * // Delete all cars with green color
2116
+ * db.delete(cars).where(eq(cars.color, 'green'));
2117
+ * // or
2118
+ * db.delete(cars).where(sql`${cars.color} = 'green'`)
2119
+ * ```
2120
+ *
2121
+ * You can logically combine conditional operators with `and()` and `or()` operators:
2122
+ *
2123
+ * ```ts
2124
+ * // Delete all BMW cars with a green color
2125
+ * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
2126
+ *
2127
+ * // Delete all cars with the green or blue color
2128
+ * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
2129
+ * ```
2130
+ */
2131
+ where(where) {
2132
+ this.config.where = where;
2133
+ return this;
2134
+ }
2135
+ orderBy(...columns) {
2136
+ if (typeof columns[0] === "function") {
2137
+ const orderBy = columns[0](
2138
+ new Proxy(
2139
+ this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns],
2140
+ new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
2141
+ )
2142
+ );
2143
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
2144
+ this.config.orderBy = orderByArray;
2145
+ } else {
2146
+ const orderByArray = columns;
2147
+ this.config.orderBy = orderByArray;
2148
+ }
2149
+ return this;
2150
+ }
2151
+ limit(limit) {
2152
+ this.config.limit = limit;
2153
+ return this;
2154
+ }
2155
+ /** @internal */
2156
+ getSQL() {
2157
+ return this.dialect.buildDeleteQuery(this.config);
2158
+ }
2159
+ toSQL() {
2160
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
2161
+ return rest;
2162
+ }
2163
+ prepare() {
2164
+ return this.session.prepareQuery(
2165
+ this.dialect.sqlToQuery(this.getSQL()),
2166
+ this.config.returning
2167
+ );
2168
+ }
2169
+ execute = (placeholderValues) => {
2170
+ return this.prepare().execute(placeholderValues);
2171
+ };
2172
+ createIterator = () => {
2173
+ const self = this;
2174
+ return async function* (placeholderValues) {
2175
+ yield* self.prepare().iterator(placeholderValues);
2176
+ };
2177
+ };
2178
+ iterator = this.createIterator();
2179
+ $dynamic() {
2180
+ return this;
2181
+ }
2182
+ }
2183
+
2184
+ //# sourceMappingURL=delete.js.map
2185
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/insert.js
2186
+
2187
+
2188
+
2189
+
2190
+
2191
+
2192
+ class MySqlInsertBuilder {
2193
+ constructor(table, session, dialect) {
2194
+ this.table = table;
2195
+ this.session = session;
2196
+ this.dialect = dialect;
2197
+ }
2198
+ static [entity/* entityKind */.i] = "MySqlInsertBuilder";
2199
+ shouldIgnore = false;
2200
+ ignore() {
2201
+ this.shouldIgnore = true;
2202
+ return this;
2203
+ }
2204
+ values(values) {
2205
+ values = Array.isArray(values) ? values : [values];
2206
+ if (values.length === 0) {
2207
+ throw new Error("values() must be called with at least one value");
2208
+ }
2209
+ const mappedValues = values.map((entry) => {
2210
+ const result = {};
2211
+ const cols = this.table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
2212
+ for (const colKey of Object.keys(entry)) {
2213
+ const colValue = entry[colKey];
2214
+ result[colKey] = (0,entity.is)(colValue, sql/* SQL */.Xs) ? colValue : new sql/* Param */.Iw(colValue, cols[colKey]);
2215
+ }
2216
+ return result;
2217
+ });
2218
+ return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
2219
+ }
2220
+ select(selectQuery) {
2221
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
2222
+ if (!(0,entity.is)(select, sql/* SQL */.Xs) && !(0,utils/* haveSameKeys */.DV)(this.table[drizzle_orm_table/* Columns */.e], select._.selectedFields)) {
2223
+ throw new Error(
2224
+ "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
2225
+ );
2226
+ }
2227
+ return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
2228
+ }
2229
+ }
2230
+ class MySqlInsertBase extends query_promise/* QueryPromise */.k {
2231
+ constructor(table, values, ignore, session, dialect, select) {
2232
+ super();
2233
+ this.session = session;
2234
+ this.dialect = dialect;
2235
+ this.config = { table, values, select, ignore };
2236
+ }
2237
+ static [entity/* entityKind */.i] = "MySqlInsert";
2238
+ config;
2239
+ /**
2240
+ * Adds an `on duplicate key update` clause to the query.
2241
+ *
2242
+ * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
2243
+ *
2244
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
2245
+ *
2246
+ * @param config The `set` clause
2247
+ *
2248
+ * @example
2249
+ * ```ts
2250
+ * await db.insert(cars)
2251
+ * .values({ id: 1, brand: 'BMW'})
2252
+ * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
2253
+ * ```
2254
+ *
2255
+ * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
2256
+ *
2257
+ * ```ts
2258
+ * import { sql } from 'drizzle-orm';
2259
+ *
2260
+ * await db.insert(cars)
2261
+ * .values({ id: 1, brand: 'BMW' })
2262
+ * .onDuplicateKeyUpdate({ set: { id: sql`id` } });
2263
+ * ```
2264
+ */
2265
+ onDuplicateKeyUpdate(config) {
2266
+ const setSql = this.dialect.buildUpdateSet(this.config.table, (0,utils/* mapUpdateSet */.q)(this.config.table, config.set));
2267
+ this.config.onConflict = (0,sql/* sql */.ll)`update ${setSql}`;
2268
+ return this;
2269
+ }
2270
+ $returningId() {
2271
+ const returning = [];
2272
+ for (const [key, value] of Object.entries(this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns])) {
2273
+ if (value.primary) {
2274
+ returning.push({ field: value, path: [key] });
2275
+ }
2276
+ }
2277
+ this.config.returning = returning;
2278
+ return this;
2279
+ }
2280
+ /** @internal */
2281
+ getSQL() {
2282
+ return this.dialect.buildInsertQuery(this.config).sql;
2283
+ }
2284
+ toSQL() {
2285
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
2286
+ return rest;
2287
+ }
2288
+ prepare() {
2289
+ const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
2290
+ return this.session.prepareQuery(
2291
+ this.dialect.sqlToQuery(sql2),
2292
+ void 0,
2293
+ void 0,
2294
+ generatedIds,
2295
+ this.config.returning
2296
+ );
2297
+ }
2298
+ execute = (placeholderValues) => {
2299
+ return this.prepare().execute(placeholderValues);
2300
+ };
2301
+ createIterator = () => {
2302
+ const self = this;
2303
+ return async function* (placeholderValues) {
2304
+ yield* self.prepare().iterator(placeholderValues);
2305
+ };
2306
+ };
2307
+ iterator = this.createIterator();
2308
+ $dynamic() {
2309
+ return this;
2310
+ }
2311
+ }
2312
+
2313
+ //# sourceMappingURL=insert.js.map
2314
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/query-builders/query.js
2315
+
2316
+
2317
+
2318
+ class RelationalQueryBuilder {
2319
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, mode) {
2320
+ this.fullSchema = fullSchema;
2321
+ this.schema = schema;
2322
+ this.tableNamesMap = tableNamesMap;
2323
+ this.table = table;
2324
+ this.tableConfig = tableConfig;
2325
+ this.dialect = dialect;
2326
+ this.session = session;
2327
+ this.mode = mode;
2328
+ }
2329
+ static [entity/* entityKind */.i] = "MySqlRelationalQueryBuilder";
2330
+ findMany(config) {
2331
+ return new MySqlRelationalQuery(
2332
+ this.fullSchema,
2333
+ this.schema,
2334
+ this.tableNamesMap,
2335
+ this.table,
2336
+ this.tableConfig,
2337
+ this.dialect,
2338
+ this.session,
2339
+ config ? config : {},
2340
+ "many",
2341
+ this.mode
2342
+ );
2343
+ }
2344
+ findFirst(config) {
2345
+ return new MySqlRelationalQuery(
2346
+ this.fullSchema,
2347
+ this.schema,
2348
+ this.tableNamesMap,
2349
+ this.table,
2350
+ this.tableConfig,
2351
+ this.dialect,
2352
+ this.session,
2353
+ config ? { ...config, limit: 1 } : { limit: 1 },
2354
+ "first",
2355
+ this.mode
2356
+ );
2357
+ }
2358
+ }
2359
+ class MySqlRelationalQuery extends query_promise/* QueryPromise */.k {
2360
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, queryMode, mode) {
2361
+ super();
2362
+ this.fullSchema = fullSchema;
2363
+ this.schema = schema;
2364
+ this.tableNamesMap = tableNamesMap;
2365
+ this.table = table;
2366
+ this.tableConfig = tableConfig;
2367
+ this.dialect = dialect;
2368
+ this.session = session;
2369
+ this.config = config;
2370
+ this.queryMode = queryMode;
2371
+ this.mode = mode;
2372
+ }
2373
+ static [entity/* entityKind */.i] = "MySqlRelationalQuery";
2374
+ prepare() {
2375
+ const { query, builtQuery } = this._toSQL();
2376
+ return this.session.prepareQuery(
2377
+ builtQuery,
2378
+ void 0,
2379
+ (rawRows) => {
2380
+ const rows = rawRows.map((row) => (0,relations/* mapRelationalRow */.I$)(this.schema, this.tableConfig, row, query.selection));
2381
+ if (this.queryMode === "first") {
2382
+ return rows[0];
2383
+ }
2384
+ return rows;
2385
+ }
2386
+ );
2387
+ }
2388
+ _getQuery() {
2389
+ const query = this.mode === "planetscale" ? this.dialect.buildRelationalQueryWithoutLateralSubqueries({
2390
+ fullSchema: this.fullSchema,
2391
+ schema: this.schema,
2392
+ tableNamesMap: this.tableNamesMap,
2393
+ table: this.table,
2394
+ tableConfig: this.tableConfig,
2395
+ queryConfig: this.config,
2396
+ tableAlias: this.tableConfig.tsName
2397
+ }) : this.dialect.buildRelationalQuery({
2398
+ fullSchema: this.fullSchema,
2399
+ schema: this.schema,
2400
+ tableNamesMap: this.tableNamesMap,
2401
+ table: this.table,
2402
+ tableConfig: this.tableConfig,
2403
+ queryConfig: this.config,
2404
+ tableAlias: this.tableConfig.tsName
2405
+ });
2406
+ return query;
2407
+ }
2408
+ _toSQL() {
2409
+ const query = this._getQuery();
2410
+ const builtQuery = this.dialect.sqlToQuery(query.sql);
2411
+ return { builtQuery, query };
2412
+ }
2413
+ /** @internal */
2414
+ getSQL() {
2415
+ return this._getQuery().sql;
2416
+ }
2417
+ toSQL() {
2418
+ return this._toSQL().builtQuery;
2419
+ }
2420
+ execute() {
2421
+ return this.prepare().execute();
2422
+ }
2423
+ }
2424
+
2425
+ //# sourceMappingURL=query.js.map
2426
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/db.js
2427
+
2428
+
2429
+
2430
+
2431
+
2432
+
2433
+
2434
+ class MySqlDatabase {
2435
+ constructor(dialect, session, schema, mode) {
2436
+ this.dialect = dialect;
2437
+ this.session = session;
2438
+ this.mode = mode;
2439
+ this._ = schema ? {
2440
+ schema: schema.schema,
2441
+ fullSchema: schema.fullSchema,
2442
+ tableNamesMap: schema.tableNamesMap
2443
+ } : {
2444
+ schema: void 0,
2445
+ fullSchema: {},
2446
+ tableNamesMap: {}
2447
+ };
2448
+ this.query = {};
2449
+ if (this._.schema) {
2450
+ for (const [tableName, columns] of Object.entries(this._.schema)) {
2451
+ this.query[tableName] = new RelationalQueryBuilder(
2452
+ schema.fullSchema,
2453
+ this._.schema,
2454
+ this._.tableNamesMap,
2455
+ schema.fullSchema[tableName],
2456
+ columns,
2457
+ dialect,
2458
+ session,
2459
+ this.mode
2460
+ );
2461
+ }
2462
+ }
2463
+ }
2464
+ static [entity/* entityKind */.i] = "MySqlDatabase";
2465
+ query;
2466
+ /**
2467
+ * Creates a subquery that defines a temporary named result set as a CTE.
2468
+ *
2469
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
2470
+ *
2471
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
2472
+ *
2473
+ * @param alias The alias for the subquery.
2474
+ *
2475
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
2476
+ *
2477
+ * @example
2478
+ *
2479
+ * ```ts
2480
+ * // Create a subquery with alias 'sq' and use it in the select query
2481
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
2482
+ *
2483
+ * const result = await db.with(sq).select().from(sq);
2484
+ * ```
2485
+ *
2486
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
2487
+ *
2488
+ * ```ts
2489
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
2490
+ * const sq = db.$with('sq').as(db.select({
2491
+ * name: sql<string>`upper(${users.name})`.as('name'),
2492
+ * })
2493
+ * .from(users));
2494
+ *
2495
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
2496
+ * ```
2497
+ */
2498
+ $with(alias) {
2499
+ const self = this;
2500
+ return {
2501
+ as(qb) {
2502
+ if (typeof qb === "function") {
2503
+ qb = qb(new QueryBuilder(self.dialect));
2504
+ }
2505
+ return new Proxy(
2506
+ new subquery/* WithSubquery */.J(qb.getSQL(), qb.getSelectedFields(), alias, true),
2507
+ new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
2508
+ );
2509
+ }
2510
+ };
2511
+ }
2512
+ $count(source, filters) {
2513
+ return new MySqlCountBuilder({ source, filters, session: this.session });
2514
+ }
2515
+ /**
2516
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
2517
+ *
2518
+ * This method allows the main query to reference a temporary named result set.
2519
+ *
2520
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
2521
+ *
2522
+ * @param queries The CTEs to incorporate into the main query.
2523
+ *
2524
+ * @example
2525
+ *
2526
+ * ```ts
2527
+ * // Define a subquery 'sq' as a CTE using $with
2528
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
2529
+ *
2530
+ * // Incorporate the CTE 'sq' into the main query and select from it
2531
+ * const result = await db.with(sq).select().from(sq);
2532
+ * ```
2533
+ */
2534
+ with(...queries) {
2535
+ const self = this;
2536
+ function select(fields) {
2537
+ return new MySqlSelectBuilder({
2538
+ fields: fields ?? void 0,
2539
+ session: self.session,
2540
+ dialect: self.dialect,
2541
+ withList: queries
2542
+ });
2543
+ }
2544
+ function selectDistinct(fields) {
2545
+ return new MySqlSelectBuilder({
2546
+ fields: fields ?? void 0,
2547
+ session: self.session,
2548
+ dialect: self.dialect,
2549
+ withList: queries,
2550
+ distinct: true
2551
+ });
2552
+ }
2553
+ function update(table) {
2554
+ return new MySqlUpdateBuilder(table, self.session, self.dialect, queries);
2555
+ }
2556
+ function delete_(table) {
2557
+ return new MySqlDeleteBase(table, self.session, self.dialect, queries);
2558
+ }
2559
+ return { select, selectDistinct, update, delete: delete_ };
2560
+ }
2561
+ select(fields) {
2562
+ return new MySqlSelectBuilder({ fields: fields ?? void 0, session: this.session, dialect: this.dialect });
2563
+ }
2564
+ selectDistinct(fields) {
2565
+ return new MySqlSelectBuilder({
2566
+ fields: fields ?? void 0,
2567
+ session: this.session,
2568
+ dialect: this.dialect,
2569
+ distinct: true
2570
+ });
2571
+ }
2572
+ /**
2573
+ * Creates an update query.
2574
+ *
2575
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
2576
+ *
2577
+ * Use `.set()` method to specify which values to update.
2578
+ *
2579
+ * See docs: {@link https://orm.drizzle.team/docs/update}
2580
+ *
2581
+ * @param table The table to update.
2582
+ *
2583
+ * @example
2584
+ *
2585
+ * ```ts
2586
+ * // Update all rows in the 'cars' table
2587
+ * await db.update(cars).set({ color: 'red' });
2588
+ *
2589
+ * // Update rows with filters and conditions
2590
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
2591
+ * ```
2592
+ */
2593
+ update(table) {
2594
+ return new MySqlUpdateBuilder(table, this.session, this.dialect);
2595
+ }
2596
+ /**
2597
+ * Creates an insert query.
2598
+ *
2599
+ * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
2600
+ *
2601
+ * See docs: {@link https://orm.drizzle.team/docs/insert}
2602
+ *
2603
+ * @param table The table to insert into.
2604
+ *
2605
+ * @example
2606
+ *
2607
+ * ```ts
2608
+ * // Insert one row
2609
+ * await db.insert(cars).values({ brand: 'BMW' });
2610
+ *
2611
+ * // Insert multiple rows
2612
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
2613
+ * ```
2614
+ */
2615
+ insert(table) {
2616
+ return new MySqlInsertBuilder(table, this.session, this.dialect);
2617
+ }
2618
+ /**
2619
+ * Creates a delete query.
2620
+ *
2621
+ * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
2622
+ *
2623
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
2624
+ *
2625
+ * @param table The table to delete from.
2626
+ *
2627
+ * @example
2628
+ *
2629
+ * ```ts
2630
+ * // Delete all rows in the 'cars' table
2631
+ * await db.delete(cars);
2632
+ *
2633
+ * // Delete rows with filters and conditions
2634
+ * await db.delete(cars).where(eq(cars.color, 'green'));
2635
+ * ```
2636
+ */
2637
+ delete(table) {
2638
+ return new MySqlDeleteBase(table, this.session, this.dialect);
2639
+ }
2640
+ execute(query) {
2641
+ return this.session.execute(typeof query === "string" ? sql/* sql */.ll.raw(query) : query.getSQL());
2642
+ }
2643
+ transaction(transaction, config) {
2644
+ return this.session.transaction(transaction, config);
2645
+ }
2646
+ }
2647
+ const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(Math.random() * replicas.length)]) => {
2648
+ const select = (...args) => getReplica(replicas).select(...args);
2649
+ const selectDistinct = (...args) => getReplica(replicas).selectDistinct(...args);
2650
+ const $with = (...args) => getReplica(replicas).with(...args);
2651
+ const update = (...args) => primary.update(...args);
2652
+ const insert = (...args) => primary.insert(...args);
2653
+ const $delete = (...args) => primary.delete(...args);
2654
+ const execute = (...args) => primary.execute(...args);
2655
+ const transaction = (...args) => primary.transaction(...args);
2656
+ return {
2657
+ ...primary,
2658
+ update,
2659
+ insert,
2660
+ delete: $delete,
2661
+ execute,
2662
+ transaction,
2663
+ $primary: primary,
2664
+ select,
2665
+ selectDistinct,
2666
+ with: $with,
2667
+ get query() {
2668
+ return getReplica(replicas).query;
2669
+ }
2670
+ };
2671
+ };
2672
+
2673
+ //# sourceMappingURL=db.js.map
2674
+ // EXTERNAL MODULE: external "node:events"
2675
+ var external_node_events_ = __webpack_require__(8474);
2676
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql-core/session.js
2677
+
2678
+
2679
+
2680
+
2681
+ class MySqlPreparedQuery {
2682
+ static [entity/* entityKind */.i] = "MySqlPreparedQuery";
2683
+ /** @internal */
2684
+ joinsNotNullableMap;
2685
+ }
2686
+ class MySqlSession {
2687
+ constructor(dialect) {
2688
+ this.dialect = dialect;
2689
+ }
2690
+ static [entity/* entityKind */.i] = "MySqlSession";
2691
+ execute(query) {
2692
+ return this.prepareQuery(
2693
+ this.dialect.sqlToQuery(query),
2694
+ void 0
2695
+ ).execute();
2696
+ }
2697
+ async count(sql2) {
2698
+ const res = await this.execute(sql2);
2699
+ return Number(
2700
+ res[0][0]["count"]
2701
+ );
2702
+ }
2703
+ getSetTransactionSQL(config) {
2704
+ const parts = [];
2705
+ if (config.isolationLevel) {
2706
+ parts.push(`isolation level ${config.isolationLevel}`);
2707
+ }
2708
+ return parts.length ? (0,sql/* sql */.ll)`set transaction ${sql/* sql */.ll.raw(parts.join(" "))}` : void 0;
2709
+ }
2710
+ getStartTransactionSQL(config) {
2711
+ const parts = [];
2712
+ if (config.withConsistentSnapshot) {
2713
+ parts.push("with consistent snapshot");
2714
+ }
2715
+ if (config.accessMode) {
2716
+ parts.push(config.accessMode);
2717
+ }
2718
+ return parts.length ? (0,sql/* sql */.ll)`start transaction ${sql/* sql */.ll.raw(parts.join(" "))}` : void 0;
2719
+ }
2720
+ }
2721
+ class MySqlTransaction extends MySqlDatabase {
2722
+ constructor(dialect, session, schema, nestedIndex, mode) {
2723
+ super(dialect, session, schema, mode);
2724
+ this.schema = schema;
2725
+ this.nestedIndex = nestedIndex;
2726
+ }
2727
+ static [entity/* entityKind */.i] = "MySqlTransaction";
2728
+ rollback() {
2729
+ throw new errors/* TransactionRollbackError */.j();
2730
+ }
2731
+ }
2732
+
2733
+ //# sourceMappingURL=session.js.map
2734
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql2/session.js
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+ class MySql2PreparedQuery extends MySqlPreparedQuery {
2743
+ constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {
2744
+ super();
2745
+ this.client = client;
2746
+ this.params = params;
2747
+ this.logger = logger;
2748
+ this.fields = fields;
2749
+ this.customResultMapper = customResultMapper;
2750
+ this.generatedIds = generatedIds;
2751
+ this.returningIds = returningIds;
2752
+ this.rawQuery = {
2753
+ sql: queryString,
2754
+ // rowsAsArray: true,
2755
+ typeCast: function(field, next) {
2756
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
2757
+ return field.string();
2758
+ }
2759
+ return next();
2760
+ }
2761
+ };
2762
+ this.query = {
2763
+ sql: queryString,
2764
+ rowsAsArray: true,
2765
+ typeCast: function(field, next) {
2766
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
2767
+ return field.string();
2768
+ }
2769
+ return next();
2770
+ }
2771
+ };
2772
+ }
2773
+ static [entity/* entityKind */.i] = "MySql2PreparedQuery";
2774
+ rawQuery;
2775
+ query;
2776
+ async execute(placeholderValues = {}) {
2777
+ const params = (0,sql/* fillPlaceholders */.Ct)(this.params, placeholderValues);
2778
+ this.logger.logQuery(this.rawQuery.sql, params);
2779
+ const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
2780
+ if (!fields && !customResultMapper) {
2781
+ const res = await client.query(rawQuery, params);
2782
+ const insertId = res[0].insertId;
2783
+ const affectedRows = res[0].affectedRows;
2784
+ if (returningIds) {
2785
+ const returningResponse = [];
2786
+ let j = 0;
2787
+ for (let i = insertId; i < insertId + affectedRows; i++) {
2788
+ for (const column of returningIds) {
2789
+ const key = returningIds[0].path[0];
2790
+ if ((0,entity.is)(column.field, drizzle_orm_column/* Column */.V)) {
2791
+ if (column.field.primary && column.field.autoIncrement) {
2792
+ returningResponse.push({ [key]: i });
2793
+ }
2794
+ if (column.field.defaultFn && generatedIds) {
2795
+ returningResponse.push({ [key]: generatedIds[j][key] });
2796
+ }
2797
+ }
2798
+ }
2799
+ j++;
2800
+ }
2801
+ return returningResponse;
2802
+ }
2803
+ return res;
2804
+ }
2805
+ const result = await client.query(query, params);
2806
+ const rows = result[0];
2807
+ if (customResultMapper) {
2808
+ return customResultMapper(rows);
2809
+ }
2810
+ return rows.map((row) => (0,utils/* mapResultRow */.a6)(fields, row, joinsNotNullableMap));
2811
+ }
2812
+ async *iterator(placeholderValues = {}) {
2813
+ const params = (0,sql/* fillPlaceholders */.Ct)(this.params, placeholderValues);
2814
+ const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
2815
+ const { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;
2816
+ const hasRowsMapper = Boolean(fields || customResultMapper);
2817
+ const driverQuery = hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params);
2818
+ const stream = driverQuery.stream();
2819
+ function dataListener() {
2820
+ stream.pause();
2821
+ }
2822
+ stream.on("data", dataListener);
2823
+ try {
2824
+ const onEnd = (0,external_node_events_.once)(stream, "end");
2825
+ const onError = (0,external_node_events_.once)(stream, "error");
2826
+ while (true) {
2827
+ stream.resume();
2828
+ const row = await Promise.race([onEnd, onError, new Promise((resolve) => stream.once("data", resolve))]);
2829
+ if (row === void 0 || Array.isArray(row) && row.length === 0) {
2830
+ break;
2831
+ } else if (row instanceof Error) {
2832
+ throw row;
2833
+ } else {
2834
+ if (hasRowsMapper) {
2835
+ if (customResultMapper) {
2836
+ const mappedRow = customResultMapper([row]);
2837
+ yield Array.isArray(mappedRow) ? mappedRow[0] : mappedRow;
2838
+ } else {
2839
+ yield (0,utils/* mapResultRow */.a6)(fields, row, joinsNotNullableMap);
2840
+ }
2841
+ } else {
2842
+ yield row;
2843
+ }
2844
+ }
2845
+ }
2846
+ } finally {
2847
+ stream.off("data", dataListener);
2848
+ if (isPool(client)) {
2849
+ conn.end();
2850
+ }
2851
+ }
2852
+ }
2853
+ }
2854
+ class MySql2Session extends MySqlSession {
2855
+ constructor(client, dialect, schema, options) {
2856
+ super(dialect);
2857
+ this.client = client;
2858
+ this.schema = schema;
2859
+ this.options = options;
2860
+ this.logger = options.logger ?? new drizzle_orm_logger/* NoopLogger */.Pv();
2861
+ this.mode = options.mode;
2862
+ }
2863
+ static [entity/* entityKind */.i] = "MySql2Session";
2864
+ logger;
2865
+ mode;
2866
+ prepareQuery(query, fields, customResultMapper, generatedIds, returningIds) {
2867
+ return new MySql2PreparedQuery(
2868
+ this.client,
2869
+ query.sql,
2870
+ query.params,
2871
+ this.logger,
2872
+ fields,
2873
+ customResultMapper,
2874
+ generatedIds,
2875
+ returningIds
2876
+ );
2877
+ }
2878
+ /**
2879
+ * @internal
2880
+ * What is its purpose?
2881
+ */
2882
+ async query(query, params) {
2883
+ this.logger.logQuery(query, params);
2884
+ const result = await this.client.query({
2885
+ sql: query,
2886
+ values: params,
2887
+ rowsAsArray: true,
2888
+ typeCast: function(field, next) {
2889
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
2890
+ return field.string();
2891
+ }
2892
+ return next();
2893
+ }
2894
+ });
2895
+ return result;
2896
+ }
2897
+ all(query) {
2898
+ const querySql = this.dialect.sqlToQuery(query);
2899
+ this.logger.logQuery(querySql.sql, querySql.params);
2900
+ return this.client.execute(querySql.sql, querySql.params).then((result) => result[0]);
2901
+ }
2902
+ async transaction(transaction, config) {
2903
+ const session = isPool(this.client) ? new MySql2Session(
2904
+ await this.client.getConnection(),
2905
+ this.dialect,
2906
+ this.schema,
2907
+ this.options
2908
+ ) : this;
2909
+ const tx = new MySql2Transaction(
2910
+ this.dialect,
2911
+ session,
2912
+ this.schema,
2913
+ 0,
2914
+ this.mode
2915
+ );
2916
+ if (config) {
2917
+ const setTransactionConfigSql = this.getSetTransactionSQL(config);
2918
+ if (setTransactionConfigSql) {
2919
+ await tx.execute(setTransactionConfigSql);
2920
+ }
2921
+ const startTransactionSql = this.getStartTransactionSQL(config);
2922
+ await (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute((0,sql/* sql */.ll)`begin`));
2923
+ } else {
2924
+ await tx.execute((0,sql/* sql */.ll)`begin`);
2925
+ }
2926
+ try {
2927
+ const result = await transaction(tx);
2928
+ await tx.execute((0,sql/* sql */.ll)`commit`);
2929
+ return result;
2930
+ } catch (err) {
2931
+ await tx.execute((0,sql/* sql */.ll)`rollback`);
2932
+ throw err;
2933
+ } finally {
2934
+ if (isPool(this.client)) {
2935
+ session.client.release();
2936
+ }
2937
+ }
2938
+ }
2939
+ }
2940
+ class MySql2Transaction extends MySqlTransaction {
2941
+ static [entity/* entityKind */.i] = "MySql2Transaction";
2942
+ async transaction(transaction) {
2943
+ const savepointName = `sp${this.nestedIndex + 1}`;
2944
+ const tx = new MySql2Transaction(
2945
+ this.dialect,
2946
+ this.session,
2947
+ this.schema,
2948
+ this.nestedIndex + 1,
2949
+ this.mode
2950
+ );
2951
+ await tx.execute(sql/* sql */.ll.raw(`savepoint ${savepointName}`));
2952
+ try {
2953
+ const result = await transaction(tx);
2954
+ await tx.execute(sql/* sql */.ll.raw(`release savepoint ${savepointName}`));
2955
+ return result;
2956
+ } catch (err) {
2957
+ await tx.execute(sql/* sql */.ll.raw(`rollback to savepoint ${savepointName}`));
2958
+ throw err;
2959
+ }
2960
+ }
2961
+ }
2962
+ function isPool(client) {
2963
+ return "getConnection" in client;
2964
+ }
2965
+
2966
+ //# sourceMappingURL=session.js.map
2967
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql2/driver.js
2968
+
2969
+
2970
+
2971
+
2972
+
2973
+
2974
+
2975
+
2976
+
2977
+ class MySql2Driver {
2978
+ constructor(client, dialect, options = {}) {
2979
+ this.client = client;
2980
+ this.dialect = dialect;
2981
+ this.options = options;
2982
+ }
2983
+ static [entity/* entityKind */.i] = "MySql2Driver";
2984
+ createSession(schema, mode) {
2985
+ return new MySql2Session(this.client, this.dialect, schema, { logger: this.options.logger, mode });
2986
+ }
2987
+ }
2988
+
2989
+ class MySql2Database extends MySqlDatabase {
2990
+ static [entity/* entityKind */.i] = "MySql2Database";
2991
+ }
2992
+ function construct(client, config = {}) {
2993
+ const dialect = new MySqlDialect({ casing: config.casing });
2994
+ let logger;
2995
+ if (config.logger === true) {
2996
+ logger = new drizzle_orm_logger/* DefaultLogger */.w();
2997
+ } else if (config.logger !== false) {
2998
+ logger = config.logger;
2999
+ }
3000
+ const clientForInstance = isCallbackClient(client) ? client.promise() : client;
3001
+ let schema;
3002
+ if (config.schema) {
3003
+ if (config.mode === void 0) {
3004
+ throw new errors/* DrizzleError */.n({
3005
+ message: 'You need to specify "mode": "planetscale" or "default" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes'
3006
+ });
3007
+ }
3008
+ const tablesConfig = (0,relations/* extractTablesRelationalConfig */._k)(
3009
+ config.schema,
3010
+ relations/* createTableRelationsHelpers */.DZ
3011
+ );
3012
+ schema = {
3013
+ fullSchema: config.schema,
3014
+ schema: tablesConfig.tables,
3015
+ tableNamesMap: tablesConfig.tableNamesMap
3016
+ };
3017
+ }
3018
+ const mode = config.mode ?? "default";
3019
+ const driver = new MySql2Driver(clientForInstance, dialect, { logger });
3020
+ const session = driver.createSession(schema, mode);
3021
+ const db = new MySql2Database(dialect, session, schema, mode);
3022
+ db.$client = client;
3023
+ return db;
3024
+ }
3025
+ function isCallbackClient(client) {
3026
+ return typeof client.promise === "function";
3027
+ }
3028
+ function drizzle(...params) {
3029
+ if (typeof params[0] === "string") {
3030
+ const connectionString = params[0];
3031
+ const instance = (0,external_mysql2_.createPool)({
3032
+ uri: connectionString
3033
+ });
3034
+ return construct(instance, params[1]);
3035
+ }
3036
+ if ((0,utils/* isConfig */.Lq)(params[0])) {
3037
+ const { connection, client, ...drizzleConfig } = params[0];
3038
+ if (client)
3039
+ return construct(client, drizzleConfig);
3040
+ const instance = typeof connection === "string" ? (0,external_mysql2_.createPool)({
3041
+ uri: connection
3042
+ }) : (0,external_mysql2_.createPool)(connection);
3043
+ const db = construct(instance, drizzleConfig);
3044
+ return db;
3045
+ }
3046
+ return construct(params[0], params[1]);
3047
+ }
3048
+ ((drizzle2) => {
3049
+ function mock(config) {
3050
+ return construct({}, config);
3051
+ }
3052
+ drizzle2.mock = mock;
3053
+ })(drizzle || (drizzle = {}));
3054
+
3055
+ //# sourceMappingURL=driver.js.map
3056
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/mysql2/index.js
3057
+
3058
+
3059
+ //# sourceMappingURL=index.js.map
3060
+
3061
+ /***/ }),
3062
+
3063
+ /***/ 6685:
3064
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3065
+
3066
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3067
+ /* harmony export */ O: () => (/* binding */ TypedQueryBuilder)
3068
+ /* harmony export */ });
3069
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
3070
+
3071
+ class TypedQueryBuilder {
3072
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TypedQueryBuilder";
3073
+ /** @internal */
3074
+ getSelectedFields() {
3075
+ return this._.selectedFields;
3076
+ }
3077
+ }
3078
+
3079
+ //# sourceMappingURL=query-builder.js.map
3080
+
3081
+ /***/ }),
3082
+
3083
+ /***/ 4579:
3084
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3085
+
3086
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3087
+ /* harmony export */ k: () => (/* binding */ QueryPromise)
3088
+ /* harmony export */ });
3089
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
3090
+
3091
+ class QueryPromise {
3092
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "QueryPromise";
3093
+ [Symbol.toStringTag] = "QueryPromise";
3094
+ catch(onRejected) {
3095
+ return this.then(void 0, onRejected);
3096
+ }
3097
+ finally(onFinally) {
3098
+ return this.then(
3099
+ (value) => {
3100
+ onFinally?.();
3101
+ return value;
3102
+ },
3103
+ (reason) => {
3104
+ onFinally?.();
3105
+ throw reason;
3106
+ }
3107
+ );
3108
+ }
3109
+ then(onFulfilled, onRejected) {
3110
+ return this.execute().then(onFulfilled, onRejected);
3111
+ }
3112
+ }
3113
+
3114
+ //# sourceMappingURL=query-promise.js.map
3115
+
3116
+ /***/ }),
3117
+
3118
+ /***/ 4750:
3119
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3120
+
3121
+
3122
+ // EXPORTS
3123
+ __webpack_require__.d(__webpack_exports__, {
3124
+ iv: () => (/* binding */ Many),
3125
+ pD: () => (/* binding */ One),
3126
+ DZ: () => (/* binding */ createTableRelationsHelpers),
3127
+ _k: () => (/* binding */ extractTablesRelationalConfig),
3128
+ mm: () => (/* binding */ getOperators),
3129
+ rl: () => (/* binding */ getOrderByOperators),
3130
+ I$: () => (/* binding */ mapRelationalRow),
3131
+ W0: () => (/* binding */ normalizeRelation)
3132
+ });
3133
+
3134
+ // UNUSED EXPORTS: Relation, Relations, createMany, createOne, relations
3135
+
3136
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/table.js
3137
+ var table = __webpack_require__(8407);
3138
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/column.js
3139
+ var column = __webpack_require__(2345);
3140
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/entity.js
3141
+ var entity = __webpack_require__(9724);
3142
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/table.js + 22 modules
3143
+ var pg_core_table = __webpack_require__(698);
3144
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/primary-keys.js
3145
+
3146
+
3147
+ function primaryKey(...config) {
3148
+ if (config[0].columns) {
3149
+ return new PrimaryKeyBuilder(config[0].columns, config[0].name);
3150
+ }
3151
+ return new PrimaryKeyBuilder(config);
3152
+ }
3153
+ class PrimaryKeyBuilder {
3154
+ static [entity/* entityKind */.i] = "PgPrimaryKeyBuilder";
3155
+ /** @internal */
3156
+ columns;
3157
+ /** @internal */
3158
+ name;
3159
+ constructor(columns, name) {
3160
+ this.columns = columns;
3161
+ this.name = name;
3162
+ }
3163
+ /** @internal */
3164
+ build(table) {
3165
+ return new PrimaryKey(table, this.columns, this.name);
3166
+ }
3167
+ }
3168
+ class PrimaryKey {
3169
+ constructor(table, columns, name) {
3170
+ this.table = table;
3171
+ this.columns = columns;
3172
+ this.name = name;
3173
+ }
3174
+ static [entity/* entityKind */.i] = "PgPrimaryKey";
3175
+ columns;
3176
+ name;
3177
+ getName() {
3178
+ return this.name ?? `${this.table[pg_core_table/* PgTable */.mu.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
3179
+ }
3180
+ }
3181
+
3182
+ //# sourceMappingURL=primary-keys.js.map
3183
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/conditions.js
3184
+ var conditions = __webpack_require__(420);
3185
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/select.js
3186
+ var expressions_select = __webpack_require__(7038);
3187
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/sql.js + 1 modules
3188
+ var sql = __webpack_require__(183);
3189
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/relations.js
3190
+
3191
+
3192
+
3193
+
3194
+
3195
+
3196
+ class Relation {
3197
+ constructor(sourceTable, referencedTable, relationName) {
3198
+ this.sourceTable = sourceTable;
3199
+ this.referencedTable = referencedTable;
3200
+ this.relationName = relationName;
3201
+ this.referencedTableName = referencedTable[table/* Table */.XI.Symbol.Name];
3202
+ }
3203
+ static [entity/* entityKind */.i] = "Relation";
3204
+ referencedTableName;
3205
+ fieldName;
3206
+ }
3207
+ class Relations {
3208
+ constructor(table, config) {
3209
+ this.table = table;
3210
+ this.config = config;
3211
+ }
3212
+ static [entity/* entityKind */.i] = "Relations";
3213
+ }
3214
+ class One extends Relation {
3215
+ constructor(sourceTable, referencedTable, config, isNullable) {
3216
+ super(sourceTable, referencedTable, config?.relationName);
3217
+ this.config = config;
3218
+ this.isNullable = isNullable;
3219
+ }
3220
+ static [entity/* entityKind */.i] = "One";
3221
+ withFieldName(fieldName) {
3222
+ const relation = new One(
3223
+ this.sourceTable,
3224
+ this.referencedTable,
3225
+ this.config,
3226
+ this.isNullable
3227
+ );
3228
+ relation.fieldName = fieldName;
3229
+ return relation;
3230
+ }
3231
+ }
3232
+ class Many extends Relation {
3233
+ constructor(sourceTable, referencedTable, config) {
3234
+ super(sourceTable, referencedTable, config?.relationName);
3235
+ this.config = config;
3236
+ }
3237
+ static [entity/* entityKind */.i] = "Many";
3238
+ withFieldName(fieldName) {
3239
+ const relation = new Many(
3240
+ this.sourceTable,
3241
+ this.referencedTable,
3242
+ this.config
3243
+ );
3244
+ relation.fieldName = fieldName;
3245
+ return relation;
3246
+ }
3247
+ }
3248
+ function getOperators() {
3249
+ return {
3250
+ and: conditions/* and */.Uo,
3251
+ between: conditions/* between */.Tq,
3252
+ eq: conditions.eq,
3253
+ exists: conditions/* exists */.t2,
3254
+ gt: conditions.gt,
3255
+ gte: conditions/* gte */.RO,
3256
+ ilike: conditions/* ilike */.B3,
3257
+ inArray: conditions/* inArray */.RV,
3258
+ isNull: conditions/* isNull */.kZ,
3259
+ isNotNull: conditions/* isNotNull */.Pe,
3260
+ like: conditions/* like */.mj,
3261
+ lt: conditions.lt,
3262
+ lte: conditions/* lte */.wJ,
3263
+ ne: conditions.ne,
3264
+ not: conditions/* not */.AU,
3265
+ notBetween: conditions/* notBetween */.o8,
3266
+ notExists: conditions/* notExists */.KJ,
3267
+ notLike: conditions/* notLike */.RK,
3268
+ notIlike: conditions/* notIlike */.q1,
3269
+ notInArray: conditions/* notInArray */.KL,
3270
+ or: conditions.or,
3271
+ sql: sql/* sql */.ll
3272
+ };
3273
+ }
3274
+ function getOrderByOperators() {
3275
+ return {
3276
+ sql: sql/* sql */.ll,
3277
+ asc: expressions_select/* asc */.Y,
3278
+ desc: expressions_select/* desc */.i
3279
+ };
3280
+ }
3281
+ function extractTablesRelationalConfig(schema, configHelpers) {
3282
+ if (Object.keys(schema).length === 1 && "default" in schema && !(0,entity.is)(schema["default"], table/* Table */.XI)) {
3283
+ schema = schema["default"];
3284
+ }
3285
+ const tableNamesMap = {};
3286
+ const relationsBuffer = {};
3287
+ const tablesConfig = {};
3288
+ for (const [key, value] of Object.entries(schema)) {
3289
+ if ((0,entity.is)(value, table/* Table */.XI)) {
3290
+ const dbName = (0,table/* getTableUniqueName */.Lf)(value);
3291
+ const bufferedRelations = relationsBuffer[dbName];
3292
+ tableNamesMap[dbName] = key;
3293
+ tablesConfig[key] = {
3294
+ tsName: key,
3295
+ dbName: value[table/* Table */.XI.Symbol.Name],
3296
+ schema: value[table/* Table */.XI.Symbol.Schema],
3297
+ columns: value[table/* Table */.XI.Symbol.Columns],
3298
+ relations: bufferedRelations?.relations ?? {},
3299
+ primaryKey: bufferedRelations?.primaryKey ?? []
3300
+ };
3301
+ for (const column of Object.values(
3302
+ value[table/* Table */.XI.Symbol.Columns]
3303
+ )) {
3304
+ if (column.primary) {
3305
+ tablesConfig[key].primaryKey.push(column);
3306
+ }
3307
+ }
3308
+ const extraConfig = value[table/* Table */.XI.Symbol.ExtraConfigBuilder]?.(value[table/* Table */.XI.Symbol.ExtraConfigColumns]);
3309
+ if (extraConfig) {
3310
+ for (const configEntry of Object.values(extraConfig)) {
3311
+ if ((0,entity.is)(configEntry, PrimaryKeyBuilder)) {
3312
+ tablesConfig[key].primaryKey.push(...configEntry.columns);
3313
+ }
3314
+ }
3315
+ }
3316
+ } else if ((0,entity.is)(value, Relations)) {
3317
+ const dbName = (0,table/* getTableUniqueName */.Lf)(value.table);
3318
+ const tableName = tableNamesMap[dbName];
3319
+ const relations2 = value.config(
3320
+ configHelpers(value.table)
3321
+ );
3322
+ let primaryKey;
3323
+ for (const [relationName, relation] of Object.entries(relations2)) {
3324
+ if (tableName) {
3325
+ const tableConfig = tablesConfig[tableName];
3326
+ tableConfig.relations[relationName] = relation;
3327
+ if (primaryKey) {
3328
+ tableConfig.primaryKey.push(...primaryKey);
3329
+ }
3330
+ } else {
3331
+ if (!(dbName in relationsBuffer)) {
3332
+ relationsBuffer[dbName] = {
3333
+ relations: {},
3334
+ primaryKey
3335
+ };
3336
+ }
3337
+ relationsBuffer[dbName].relations[relationName] = relation;
3338
+ }
3339
+ }
3340
+ }
3341
+ }
3342
+ return { tables: tablesConfig, tableNamesMap };
3343
+ }
3344
+ function relations(table, relations2) {
3345
+ return new Relations(
3346
+ table,
3347
+ (helpers) => Object.fromEntries(
3348
+ Object.entries(relations2(helpers)).map(([key, value]) => [
3349
+ key,
3350
+ value.withFieldName(key)
3351
+ ])
3352
+ )
3353
+ );
3354
+ }
3355
+ function createOne(sourceTable) {
3356
+ return function one(table, config) {
3357
+ return new One(
3358
+ sourceTable,
3359
+ table,
3360
+ config,
3361
+ config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
3362
+ );
3363
+ };
3364
+ }
3365
+ function createMany(sourceTable) {
3366
+ return function many(referencedTable, config) {
3367
+ return new Many(sourceTable, referencedTable, config);
3368
+ };
3369
+ }
3370
+ function normalizeRelation(schema, tableNamesMap, relation) {
3371
+ if ((0,entity.is)(relation, One) && relation.config) {
3372
+ return {
3373
+ fields: relation.config.fields,
3374
+ references: relation.config.references
3375
+ };
3376
+ }
3377
+ const referencedTableTsName = tableNamesMap[(0,table/* getTableUniqueName */.Lf)(relation.referencedTable)];
3378
+ if (!referencedTableTsName) {
3379
+ throw new Error(
3380
+ `Table "${relation.referencedTable[table/* Table */.XI.Symbol.Name]}" not found in schema`
3381
+ );
3382
+ }
3383
+ const referencedTableConfig = schema[referencedTableTsName];
3384
+ if (!referencedTableConfig) {
3385
+ throw new Error(`Table "${referencedTableTsName}" not found in schema`);
3386
+ }
3387
+ const sourceTable = relation.sourceTable;
3388
+ const sourceTableTsName = tableNamesMap[(0,table/* getTableUniqueName */.Lf)(sourceTable)];
3389
+ if (!sourceTableTsName) {
3390
+ throw new Error(
3391
+ `Table "${sourceTable[table/* Table */.XI.Symbol.Name]}" not found in schema`
3392
+ );
3393
+ }
3394
+ const reverseRelations = [];
3395
+ for (const referencedTableRelation of Object.values(
3396
+ referencedTableConfig.relations
3397
+ )) {
3398
+ if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
3399
+ reverseRelations.push(referencedTableRelation);
3400
+ }
3401
+ }
3402
+ if (reverseRelations.length > 1) {
3403
+ throw relation.relationName ? new Error(
3404
+ `There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`
3405
+ ) : new Error(
3406
+ `There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[table/* Table */.XI.Symbol.Name]}". Please specify relation name`
3407
+ );
3408
+ }
3409
+ if (reverseRelations[0] && (0,entity.is)(reverseRelations[0], One) && reverseRelations[0].config) {
3410
+ return {
3411
+ fields: reverseRelations[0].config.references,
3412
+ references: reverseRelations[0].config.fields
3413
+ };
3414
+ }
3415
+ throw new Error(
3416
+ `There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`
3417
+ );
3418
+ }
3419
+ function createTableRelationsHelpers(sourceTable) {
3420
+ return {
3421
+ one: createOne(sourceTable),
3422
+ many: createMany(sourceTable)
3423
+ };
3424
+ }
3425
+ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
3426
+ const result = {};
3427
+ for (const [
3428
+ selectionItemIndex,
3429
+ selectionItem
3430
+ ] of buildQueryResultSelection.entries()) {
3431
+ if (selectionItem.isJson) {
3432
+ const relation = tableConfig.relations[selectionItem.tsKey];
3433
+ const rawSubRows = row[selectionItemIndex];
3434
+ const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
3435
+ result[selectionItem.tsKey] = (0,entity.is)(relation, One) ? subRows && mapRelationalRow(
3436
+ tablesConfig,
3437
+ tablesConfig[selectionItem.relationTableTsKey],
3438
+ subRows,
3439
+ selectionItem.selection,
3440
+ mapColumnValue
3441
+ ) : subRows.map(
3442
+ (subRow) => mapRelationalRow(
3443
+ tablesConfig,
3444
+ tablesConfig[selectionItem.relationTableTsKey],
3445
+ subRow,
3446
+ selectionItem.selection,
3447
+ mapColumnValue
3448
+ )
3449
+ );
3450
+ } else {
3451
+ const value = mapColumnValue(row[selectionItemIndex]);
3452
+ const field = selectionItem.field;
3453
+ let decoder;
3454
+ if ((0,entity.is)(field, column/* Column */.V)) {
3455
+ decoder = field;
3456
+ } else if ((0,entity.is)(field, sql/* SQL */.Xs)) {
3457
+ decoder = field.decoder;
3458
+ } else {
3459
+ decoder = field.sql.decoder;
3460
+ }
3461
+ result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
3462
+ }
3463
+ }
3464
+ return result;
3465
+ }
3466
+
3467
+ //# sourceMappingURL=relations.js.map
3468
+
3469
+ /***/ }),
3470
+
3471
+ /***/ 8296:
3472
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3473
+
3474
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3475
+ /* harmony export */ b: () => (/* binding */ SelectionProxyHandler)
3476
+ /* harmony export */ });
3477
+ /* harmony import */ var _alias_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8575);
3478
+ /* harmony import */ var _column_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2345);
3479
+ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
3480
+ /* harmony import */ var _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(183);
3481
+ /* harmony import */ var _subquery_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6453);
3482
+ /* harmony import */ var _view_common_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6146);
3483
+
3484
+
3485
+
3486
+
3487
+
3488
+
3489
+ class SelectionProxyHandler {
3490
+ static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "SelectionProxyHandler";
3491
+ config;
3492
+ constructor(config) {
3493
+ this.config = { ...config };
3494
+ }
3495
+ get(subquery, prop) {
3496
+ if (prop === "_") {
3497
+ return {
3498
+ ...subquery["_"],
3499
+ selectedFields: new Proxy(
3500
+ subquery._.selectedFields,
3501
+ this
3502
+ )
3503
+ };
3504
+ }
3505
+ if (prop === _view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n) {
3506
+ return {
3507
+ ...subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n],
3508
+ selectedFields: new Proxy(
3509
+ subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n].selectedFields,
3510
+ this
3511
+ )
3512
+ };
3513
+ }
3514
+ if (typeof prop === "symbol") {
3515
+ return subquery[prop];
3516
+ }
3517
+ const columns = (0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(subquery, _subquery_js__WEBPACK_IMPORTED_MODULE_2__/* .Subquery */ .n) ? subquery._.selectedFields : (0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(subquery, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .View */ .Ss) ? subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n].selectedFields : subquery;
3518
+ const value = columns[prop];
3519
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .SQL */ .Xs.Aliased)) {
3520
+ if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
3521
+ return value.sql;
3522
+ }
3523
+ const newValue = value.clone();
3524
+ newValue.isSelectionField = true;
3525
+ return newValue;
3526
+ }
3527
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .SQL */ .Xs)) {
3528
+ if (this.config.sqlBehavior === "sql") {
3529
+ return value;
3530
+ }
3531
+ throw new Error(
3532
+ `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`
3533
+ );
3534
+ }
3535
+ if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _column_js__WEBPACK_IMPORTED_MODULE_4__/* .Column */ .V)) {
3536
+ if (this.config.alias) {
3537
+ return new Proxy(
3538
+ value,
3539
+ new _alias_js__WEBPACK_IMPORTED_MODULE_5__/* .ColumnAliasProxyHandler */ .Ht(
3540
+ new Proxy(
3541
+ value.table,
3542
+ new _alias_js__WEBPACK_IMPORTED_MODULE_5__/* .TableAliasProxyHandler */ .h_(this.config.alias, this.config.replaceOriginalName ?? false)
3543
+ )
3544
+ )
3545
+ );
3546
+ }
3547
+ return value;
3548
+ }
3549
+ if (typeof value !== "object" || value === null) {
3550
+ return value;
3551
+ }
3552
+ return new Proxy(value, new SelectionProxyHandler(this.config));
3553
+ }
3554
+ }
3555
+
3556
+ //# sourceMappingURL=selection-proxy.js.map
3557
+
3558
+ /***/ })
3559
+
3560
+ };
3561
+
3562
+ //# sourceMappingURL=25.index.js.map