orcaq 1.0.20

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 (1018) hide show
  1. package/.output/nitro.json +15 -0
  2. package/.output/public/_nuxt/8qASMGdV.js +1 -0
  3. package/.output/public/_nuxt/9lJACZIQ.js +19 -0
  4. package/.output/public/_nuxt/B2DnNiWd.js +1 -0
  5. package/.output/public/_nuxt/B6E6ObS_.js +8 -0
  6. package/.output/public/_nuxt/BH83_dXo.js +39 -0
  7. package/.output/public/_nuxt/BIKqrFbQ.js +1 -0
  8. package/.output/public/_nuxt/BNjPC06x.js +1 -0
  9. package/.output/public/_nuxt/BPQ-Pz1w.js +39 -0
  10. package/.output/public/_nuxt/BRpgKkVT.js +51 -0
  11. package/.output/public/_nuxt/BTCLPbPY.js +4 -0
  12. package/.output/public/_nuxt/BUV-RarV.js +1 -0
  13. package/.output/public/_nuxt/Bh6RgYlO.js +1 -0
  14. package/.output/public/_nuxt/Bq3cyzOD.js +1 -0
  15. package/.output/public/_nuxt/Bt9sU68B.js +9 -0
  16. package/.output/public/_nuxt/BwpH2ZxJ.js +1 -0
  17. package/.output/public/_nuxt/C25Tmn1m.js +1 -0
  18. package/.output/public/_nuxt/C2HlI1ss.js +1 -0
  19. package/.output/public/_nuxt/CU3ZV9iV.js +1 -0
  20. package/.output/public/_nuxt/CbcyysXi.js +1 -0
  21. package/.output/public/_nuxt/CepyvMhE.js +1 -0
  22. package/.output/public/_nuxt/CrgoNCm2.js +2 -0
  23. package/.output/public/_nuxt/CuBKbBH_.js +1 -0
  24. package/.output/public/_nuxt/CulD8qYQ.js +193 -0
  25. package/.output/public/_nuxt/CustomEdge.BNBpjEHb.css +1 -0
  26. package/.output/public/_nuxt/CylkLpwm.js +1 -0
  27. package/.output/public/_nuxt/D-bWLYHw.js +1 -0
  28. package/.output/public/_nuxt/D-zecHND.js +1 -0
  29. package/.output/public/_nuxt/D8vj6kFe.js +160 -0
  30. package/.output/public/_nuxt/DIETYtCL.js +1 -0
  31. package/.output/public/_nuxt/DJ4vUzxS.js +1 -0
  32. package/.output/public/_nuxt/DK-itzXx.js +8 -0
  33. package/.output/public/_nuxt/DL3T5jYo.js +3867 -0
  34. package/.output/public/_nuxt/DUsuhY9i.js +1 -0
  35. package/.output/public/_nuxt/DXV2HFBA.js +224 -0
  36. package/.output/public/_nuxt/Dh2zppOR.js +1 -0
  37. package/.output/public/_nuxt/DlAUqK2U.js +1 -0
  38. package/.output/public/_nuxt/DlmSeCnw.js +5 -0
  39. package/.output/public/_nuxt/DswTpYG4.js +1 -0
  40. package/.output/public/_nuxt/DynamicTable.DJeANwbG.css +1 -0
  41. package/.output/public/_nuxt/G830WtVn.js +1 -0
  42. package/.output/public/_nuxt/ICwM1E4-.js +15 -0
  43. package/.output/public/_nuxt/QZbJy9YW.js +31 -0
  44. package/.output/public/_nuxt/QuickQueryTable.DS_ON57S.css +1 -0
  45. package/.output/public/_nuxt/UXhX8z2W.js +1 -0
  46. package/.output/public/_nuxt/WrapperErdDiagram.DwhUd9Wr.css +1 -0
  47. package/.output/public/_nuxt/_fileId_.DmPfwyyD.css +1 -0
  48. package/.output/public/_nuxt/_tabViewId_.9Axt3zoi.css +1 -0
  49. package/.output/public/_nuxt/builds/latest.json +1 -0
  50. package/.output/public/_nuxt/builds/meta/6364d5cf-4642-479f-ba12-6440c56702af.json +1 -0
  51. package/.output/public/_nuxt/default.DixIpIal.css +1 -0
  52. package/.output/public/_nuxt/entry.GqPNPe1e.css +1 -0
  53. package/.output/public/_nuxt/index.CrXmf4gr.css +1 -0
  54. package/.output/public/_nuxt/ivUnXl9B.js +1 -0
  55. package/.output/public/_nuxt/pAheHeBV.js +36 -0
  56. package/.output/public/_nuxt/s5fCn4j5.js +1 -0
  57. package/.output/public/favicon.ico +0 -0
  58. package/.output/public/logo.png +0 -0
  59. package/.output/public/manifest.json +25 -0
  60. package/.output/public/robots.txt +1 -0
  61. package/.output/public/vite.svg +1 -0
  62. package/.output/server/chunks/_/error-500.mjs +8 -0
  63. package/.output/server/chunks/_/error-500.mjs.map +1 -0
  64. package/.output/server/chunks/build/client.manifest.mjs +773 -0
  65. package/.output/server/chunks/build/client.manifest.mjs.map +1 -0
  66. package/.output/server/chunks/nitro/nitro.mjs +6432 -0
  67. package/.output/server/chunks/nitro/nitro.mjs.map +1 -0
  68. package/.output/server/chunks/routes/api/ai/chat.mjs +77 -0
  69. package/.output/server/chunks/routes/api/ai/chat.mjs.map +1 -0
  70. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs +100 -0
  71. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs.map +1 -0
  72. package/.output/server/chunks/routes/api/execute-bulk-update.mjs +105 -0
  73. package/.output/server/chunks/routes/api/execute-bulk-update.mjs.map +1 -0
  74. package/.output/server/chunks/routes/api/execute.mjs +47 -0
  75. package/.output/server/chunks/routes/api/execute.mjs.map +1 -0
  76. package/.output/server/chunks/routes/api/get-one-function.mjs +28 -0
  77. package/.output/server/chunks/routes/api/get-one-function.mjs.map +1 -0
  78. package/.output/server/chunks/routes/api/get-one-table.mjs +180 -0
  79. package/.output/server/chunks/routes/api/get-one-table.mjs.map +1 -0
  80. package/.output/server/chunks/routes/api/get-over-view-function.mjs +41 -0
  81. package/.output/server/chunks/routes/api/get-over-view-function.mjs.map +1 -0
  82. package/.output/server/chunks/routes/api/get-over-view-tables.mjs +53 -0
  83. package/.output/server/chunks/routes/api/get-over-view-tables.mjs.map +1 -0
  84. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs +112 -0
  85. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs.map +1 -0
  86. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs +152 -0
  87. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs.map +1 -0
  88. package/.output/server/chunks/routes/api/get-table-size.mjs +49 -0
  89. package/.output/server/chunks/routes/api/get-table-size.mjs.map +1 -0
  90. package/.output/server/chunks/routes/api/get-table-structure.mjs +111 -0
  91. package/.output/server/chunks/routes/api/get-table-structure.mjs.map +1 -0
  92. package/.output/server/chunks/routes/api/get-tables.mjs +287 -0
  93. package/.output/server/chunks/routes/api/get-tables.mjs.map +1 -0
  94. package/.output/server/chunks/routes/api/getMetricMonitor.mjs +46 -0
  95. package/.output/server/chunks/routes/api/getMetricMonitor.mjs.map +1 -0
  96. package/.output/server/chunks/routes/api/managment-connection/health-check.mjs +28 -0
  97. package/.output/server/chunks/routes/api/managment-connection/health-check.mjs.map +1 -0
  98. package/.output/server/chunks/routes/api/raw-execute.mjs +48 -0
  99. package/.output/server/chunks/routes/api/raw-execute.mjs.map +1 -0
  100. package/.output/server/chunks/routes/renderer.mjs +316 -0
  101. package/.output/server/chunks/routes/renderer.mjs.map +1 -0
  102. package/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
  103. package/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
  104. package/.output/server/index.mjs +14 -0
  105. package/.output/server/index.mjs.map +1 -0
  106. package/.output/server/node_modules/@ai-sdk/anthropic/dist/index.mjs +4374 -0
  107. package/.output/server/node_modules/@ai-sdk/anthropic/package.json +74 -0
  108. package/.output/server/node_modules/@ai-sdk/gateway/dist/index.mjs +1082 -0
  109. package/.output/server/node_modules/@ai-sdk/gateway/package.json +69 -0
  110. package/.output/server/node_modules/@ai-sdk/google/dist/index.mjs +2007 -0
  111. package/.output/server/node_modules/@ai-sdk/google/package.json +74 -0
  112. package/.output/server/node_modules/@ai-sdk/openai/dist/index.mjs +5956 -0
  113. package/.output/server/node_modules/@ai-sdk/openai/package.json +74 -0
  114. package/.output/server/node_modules/@ai-sdk/openai-compatible/dist/index.mjs +1551 -0
  115. package/.output/server/node_modules/@ai-sdk/openai-compatible/package.json +74 -0
  116. package/.output/server/node_modules/@ai-sdk/provider/dist/index.mjs +377 -0
  117. package/.output/server/node_modules/@ai-sdk/provider/package.json +57 -0
  118. package/.output/server/node_modules/@ai-sdk/provider-utils/dist/index.mjs +2549 -0
  119. package/.output/server/node_modules/@ai-sdk/provider-utils/package.json +75 -0
  120. package/.output/server/node_modules/@ai-sdk/xai/dist/index.mjs +2214 -0
  121. package/.output/server/node_modules/@ai-sdk/xai/package.json +68 -0
  122. package/.output/server/node_modules/@babel/parser/lib/index.js +14246 -0
  123. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  124. package/.output/server/node_modules/@iconify/utils/lib/colors/index.mjs +350 -0
  125. package/.output/server/node_modules/@iconify/utils/lib/colors/keywords.mjs +188 -0
  126. package/.output/server/node_modules/@iconify/utils/lib/css/common.mjs +90 -0
  127. package/.output/server/node_modules/@iconify/utils/lib/css/format.mjs +38 -0
  128. package/.output/server/node_modules/@iconify/utils/lib/css/icon.mjs +76 -0
  129. package/.output/server/node_modules/@iconify/utils/lib/css/icons.mjs +168 -0
  130. package/.output/server/node_modules/@iconify/utils/lib/customisations/bool.mjs +22 -0
  131. package/.output/server/node_modules/@iconify/utils/lib/customisations/defaults.mjs +14 -0
  132. package/.output/server/node_modules/@iconify/utils/lib/customisations/flip.mjs +16 -0
  133. package/.output/server/node_modules/@iconify/utils/lib/customisations/merge.mjs +22 -0
  134. package/.output/server/node_modules/@iconify/utils/lib/customisations/rotate.mjs +33 -0
  135. package/.output/server/node_modules/@iconify/utils/lib/emoji/cleanup.mjs +51 -0
  136. package/.output/server/node_modules/@iconify/utils/lib/emoji/convert.mjs +84 -0
  137. package/.output/server/node_modules/@iconify/utils/lib/emoji/data.mjs +16 -0
  138. package/.output/server/node_modules/@iconify/utils/lib/emoji/format.mjs +44 -0
  139. package/.output/server/node_modules/@iconify/utils/lib/emoji/parse.mjs +58 -0
  140. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/base.mjs +231 -0
  141. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/create.mjs +31 -0
  142. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.mjs +164 -0
  143. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/similar.mjs +216 -0
  144. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/tree.mjs +113 -0
  145. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/find.mjs +104 -0
  146. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/replace.mjs +34 -0
  147. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/components.mjs +75 -0
  148. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/missing.mjs +97 -0
  149. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/name.mjs +54 -0
  150. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/parse.mjs +97 -0
  151. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/similar.mjs +45 -0
  152. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/tree.mjs +105 -0
  153. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/variations.mjs +54 -0
  154. package/.output/server/node_modules/@iconify/utils/lib/icon/defaults.mjs +24 -0
  155. package/.output/server/node_modules/@iconify/utils/lib/icon/merge.mjs +20 -0
  156. package/.output/server/node_modules/@iconify/utils/lib/icon/name.mjs +53 -0
  157. package/.output/server/node_modules/@iconify/utils/lib/icon/square.mjs +23 -0
  158. package/.output/server/node_modules/@iconify/utils/lib/icon/transformations.mjs +16 -0
  159. package/.output/server/node_modules/@iconify/utils/lib/icon-set/convert-info.mjs +182 -0
  160. package/.output/server/node_modules/@iconify/utils/lib/icon-set/expand.mjs +22 -0
  161. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icon.mjs +28 -0
  162. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icons.mjs +46 -0
  163. package/.output/server/node_modules/@iconify/utils/lib/icon-set/minify.mjs +66 -0
  164. package/.output/server/node_modules/@iconify/utils/lib/icon-set/parse.mjs +51 -0
  165. package/.output/server/node_modules/@iconify/utils/lib/icon-set/tree.mjs +23 -0
  166. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.mjs +62 -0
  167. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate.mjs +161 -0
  168. package/.output/server/node_modules/@iconify/utils/lib/index.mjs +64 -0
  169. package/.output/server/node_modules/@iconify/utils/lib/loader/custom.mjs +50 -0
  170. package/.output/server/node_modules/@iconify/utils/lib/loader/loader.mjs +59 -0
  171. package/.output/server/node_modules/@iconify/utils/lib/loader/modern.mjs +80 -0
  172. package/.output/server/node_modules/@iconify/utils/lib/loader/utils.mjs +92 -0
  173. package/.output/server/node_modules/@iconify/utils/lib/misc/objects.mjs +30 -0
  174. package/.output/server/node_modules/@iconify/utils/lib/misc/strings.mjs +17 -0
  175. package/.output/server/node_modules/@iconify/utils/lib/misc/title.mjs +5 -0
  176. package/.output/server/node_modules/@iconify/utils/lib/svg/build.mjs +119 -0
  177. package/.output/server/node_modules/@iconify/utils/lib/svg/defs.mjs +30 -0
  178. package/.output/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.mjs +20 -0
  179. package/.output/server/node_modules/@iconify/utils/lib/svg/html.mjs +9 -0
  180. package/.output/server/node_modules/@iconify/utils/lib/svg/id.mjs +28 -0
  181. package/.output/server/node_modules/@iconify/utils/lib/svg/inner-html.mjs +19 -0
  182. package/.output/server/node_modules/@iconify/utils/lib/svg/parse.mjs +83 -0
  183. package/.output/server/node_modules/@iconify/utils/lib/svg/pretty.mjs +70 -0
  184. package/.output/server/node_modules/@iconify/utils/lib/svg/size.mjs +40 -0
  185. package/.output/server/node_modules/@iconify/utils/lib/svg/trim.mjs +5 -0
  186. package/.output/server/node_modules/@iconify/utils/lib/svg/url.mjs +11 -0
  187. package/.output/server/node_modules/@iconify/utils/lib/svg/viewbox.mjs +8 -0
  188. package/.output/server/node_modules/@iconify/utils/package.json +447 -0
  189. package/.output/server/node_modules/@ioredis/commands/built/commands.json +2447 -0
  190. package/.output/server/node_modules/@ioredis/commands/built/index.js +208 -0
  191. package/.output/server/node_modules/@ioredis/commands/package.json +52 -0
  192. package/.output/server/node_modules/@opentelemetry/api/build/src/api/context.js +81 -0
  193. package/.output/server/node_modules/@opentelemetry/api/build/src/api/diag.js +93 -0
  194. package/.output/server/node_modules/@opentelemetry/api/build/src/api/metrics.js +61 -0
  195. package/.output/server/node_modules/@opentelemetry/api/build/src/api/propagation.js +89 -0
  196. package/.output/server/node_modules/@opentelemetry/api/build/src/api/trace.js +79 -0
  197. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/context-helpers.js +63 -0
  198. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/internal/baggage-impl.js +55 -0
  199. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/internal/symbol.js +23 -0
  200. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/utils.js +51 -0
  201. package/.output/server/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js +38 -0
  202. package/.output/server/node_modules/@opentelemetry/api/build/src/context/context.js +55 -0
  203. package/.output/server/node_modules/@opentelemetry/api/build/src/context-api.js +24 -0
  204. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/ComponentLogger.js +59 -0
  205. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/consoleLogger.js +57 -0
  206. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/internal/logLevelLogger.js +45 -0
  207. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/types.js +44 -0
  208. package/.output/server/node_modules/@opentelemetry/api/build/src/diag-api.js +29 -0
  209. package/.output/server/node_modules/@opentelemetry/api/build/src/index.js +81 -0
  210. package/.output/server/node_modules/@opentelemetry/api/build/src/internal/global-utils.js +64 -0
  211. package/.output/server/node_modules/@opentelemetry/api/build/src/internal/semver.js +122 -0
  212. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/Metric.js +25 -0
  213. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/NoopMeter.js +127 -0
  214. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/NoopMeterProvider.js +31 -0
  215. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics-api.js +24 -0
  216. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/index.js +29 -0
  217. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js +22 -0
  218. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/node/index.js +29 -0
  219. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation/NoopTextMapPropagator.js +34 -0
  220. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation/TextMapPropagator.js +41 -0
  221. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation-api.js +24 -0
  222. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NonRecordingSpan.js +69 -0
  223. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js +75 -0
  224. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NoopTracerProvider.js +32 -0
  225. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js +55 -0
  226. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/ProxyTracerProvider.js +54 -0
  227. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/SamplingResult.js +42 -0
  228. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/context-utils.js +82 -0
  229. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/tracestate-impl.js +103 -0
  230. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/tracestate-validators.js +46 -0
  231. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/utils.js +24 -0
  232. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/invalid-span-constants.js +27 -0
  233. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/span_kind.js +46 -0
  234. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/spancontext-utils.js +49 -0
  235. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/status.js +23 -0
  236. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/trace_flags.js +26 -0
  237. package/.output/server/node_modules/@opentelemetry/api/build/src/trace-api.js +24 -0
  238. package/.output/server/node_modules/@opentelemetry/api/build/src/version.js +21 -0
  239. package/.output/server/node_modules/@opentelemetry/api/package.json +113 -0
  240. package/.output/server/node_modules/@sqltools/formatter/lib/core/Formatter.js +234 -0
  241. package/.output/server/node_modules/@sqltools/formatter/lib/core/Indentation.js +42 -0
  242. package/.output/server/node_modules/@sqltools/formatter/lib/core/InlineBlock.js +60 -0
  243. package/.output/server/node_modules/@sqltools/formatter/lib/core/Params.js +21 -0
  244. package/.output/server/node_modules/@sqltools/formatter/lib/core/Tokenizer.js +272 -0
  245. package/.output/server/node_modules/@sqltools/formatter/lib/core/escapeRegExp.js +10 -0
  246. package/.output/server/node_modules/@sqltools/formatter/lib/core/last.js +7 -0
  247. package/.output/server/node_modules/@sqltools/formatter/lib/core/types.js +22 -0
  248. package/.output/server/node_modules/@sqltools/formatter/lib/languages/Db2Formatter.js +585 -0
  249. package/.output/server/node_modules/@sqltools/formatter/lib/languages/N1qlFormatter.js +257 -0
  250. package/.output/server/node_modules/@sqltools/formatter/lib/languages/PlSqlFormatter.js +459 -0
  251. package/.output/server/node_modules/@sqltools/formatter/lib/languages/StandardSqlFormatter.js +369 -0
  252. package/.output/server/node_modules/@sqltools/formatter/lib/languages/utils/abstract.js +23 -0
  253. package/.output/server/node_modules/@sqltools/formatter/lib/sqlFormatter.js +34 -0
  254. package/.output/server/node_modules/@sqltools/formatter/package.json +59 -0
  255. package/.output/server/node_modules/@standard-schema/spec/dist/index.js +0 -0
  256. package/.output/server/node_modules/@standard-schema/spec/package.json +52 -0
  257. package/.output/server/node_modules/@vercel/oidc/dist/auth-config.js +84 -0
  258. package/.output/server/node_modules/@vercel/oidc/dist/get-context.js +34 -0
  259. package/.output/server/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js +80 -0
  260. package/.output/server/node_modules/@vercel/oidc/dist/index.js +33 -0
  261. package/.output/server/node_modules/@vercel/oidc/dist/oauth.js +88 -0
  262. package/.output/server/node_modules/@vercel/oidc/dist/token-error.js +40 -0
  263. package/.output/server/node_modules/@vercel/oidc/dist/token-io.js +78 -0
  264. package/.output/server/node_modules/@vercel/oidc/dist/token-util.js +198 -0
  265. package/.output/server/node_modules/@vercel/oidc/dist/token.js +53 -0
  266. package/.output/server/node_modules/@vercel/oidc/package.json +52 -0
  267. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6690 -0
  268. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  269. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +686 -0
  270. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  271. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1404 -0
  272. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  273. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1789 -0
  274. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  275. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6654 -0
  276. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  277. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1669 -0
  278. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  279. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +857 -0
  280. package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
  281. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +594 -0
  282. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  283. package/.output/server/node_modules/ai/dist/index.mjs +12363 -0
  284. package/.output/server/node_modules/ai/package.json +106 -0
  285. package/.output/server/node_modules/ansis/index.js +1 -0
  286. package/.output/server/node_modules/ansis/package.json +28 -0
  287. package/.output/server/node_modules/app-root-path/index.js +4 -0
  288. package/.output/server/node_modules/app-root-path/lib/app-root-path.js +30 -0
  289. package/.output/server/node_modules/app-root-path/lib/resolve.js +128 -0
  290. package/.output/server/node_modules/app-root-path/package.json +66 -0
  291. package/.output/server/node_modules/balanced-match/index.js +62 -0
  292. package/.output/server/node_modules/balanced-match/package.json +48 -0
  293. package/.output/server/node_modules/bindings/bindings.js +221 -0
  294. package/.output/server/node_modules/bindings/package.json +28 -0
  295. package/.output/server/node_modules/brace-expansion/index.js +203 -0
  296. package/.output/server/node_modules/brace-expansion/package.json +46 -0
  297. package/.output/server/node_modules/cluster-key-slot/lib/index.js +166 -0
  298. package/.output/server/node_modules/cluster-key-slot/package.json +56 -0
  299. package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  300. package/.output/server/node_modules/consola/dist/core.mjs +512 -0
  301. package/.output/server/node_modules/consola/dist/index.mjs +651 -0
  302. package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  303. package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  304. package/.output/server/node_modules/consola/package.json +136 -0
  305. package/.output/server/node_modules/dayjs/dayjs.min.js +1 -0
  306. package/.output/server/node_modules/dayjs/package.json +84 -0
  307. package/.output/server/node_modules/debug/package.json +65 -0
  308. package/.output/server/node_modules/debug/src/browser.js +272 -0
  309. package/.output/server/node_modules/debug/src/common.js +292 -0
  310. package/.output/server/node_modules/debug/src/index.js +10 -0
  311. package/.output/server/node_modules/debug/src/node.js +263 -0
  312. package/.output/server/node_modules/dedent/dist/dedent.js +73 -0
  313. package/.output/server/node_modules/dedent/package.json +119 -0
  314. package/.output/server/node_modules/denque/index.js +481 -0
  315. package/.output/server/node_modules/denque/package.json +58 -0
  316. package/.output/server/node_modules/devalue/index.js +3 -0
  317. package/.output/server/node_modules/devalue/package.json +34 -0
  318. package/.output/server/node_modules/devalue/src/base64.js +110 -0
  319. package/.output/server/node_modules/devalue/src/constants.js +6 -0
  320. package/.output/server/node_modules/devalue/src/parse.js +160 -0
  321. package/.output/server/node_modules/devalue/src/stringify.js +232 -0
  322. package/.output/server/node_modules/devalue/src/uneval.js +351 -0
  323. package/.output/server/node_modules/devalue/src/utils.js +113 -0
  324. package/.output/server/node_modules/dotenv/lib/main.js +361 -0
  325. package/.output/server/node_modules/dotenv/package.json +61 -0
  326. package/.output/server/node_modules/entities/lib/decode.js +536 -0
  327. package/.output/server/node_modules/entities/lib/decode_codepoint.js +76 -0
  328. package/.output/server/node_modules/entities/lib/generated/decode-data-html.js +9 -0
  329. package/.output/server/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
  330. package/.output/server/node_modules/entities/package.json +90 -0
  331. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  332. package/.output/server/node_modules/estree-walker/package.json +37 -0
  333. package/.output/server/node_modules/eventsource-parser/dist/index.js +106 -0
  334. package/.output/server/node_modules/eventsource-parser/dist/stream.js +29 -0
  335. package/.output/server/node_modules/eventsource-parser/package.json +115 -0
  336. package/.output/server/node_modules/file-uri-to-path/index.js +66 -0
  337. package/.output/server/node_modules/file-uri-to-path/package.json +32 -0
  338. package/.output/server/node_modules/glob/dist/commonjs/glob.js +247 -0
  339. package/.output/server/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  340. package/.output/server/node_modules/glob/dist/commonjs/ignore.js +119 -0
  341. package/.output/server/node_modules/glob/dist/commonjs/index.js +68 -0
  342. package/.output/server/node_modules/glob/dist/commonjs/package.json +3 -0
  343. package/.output/server/node_modules/glob/dist/commonjs/pattern.js +219 -0
  344. package/.output/server/node_modules/glob/dist/commonjs/processor.js +301 -0
  345. package/.output/server/node_modules/glob/dist/commonjs/walker.js +387 -0
  346. package/.output/server/node_modules/glob/package.json +99 -0
  347. package/.output/server/node_modules/has-flag/index.js +8 -0
  348. package/.output/server/node_modules/has-flag/package.json +46 -0
  349. package/.output/server/node_modules/hookable/dist/index.mjs +290 -0
  350. package/.output/server/node_modules/hookable/package.json +49 -0
  351. package/.output/server/node_modules/inherits/inherits.js +9 -0
  352. package/.output/server/node_modules/inherits/inherits_browser.js +27 -0
  353. package/.output/server/node_modules/inherits/package.json +29 -0
  354. package/.output/server/node_modules/ioredis/built/Command.js +349 -0
  355. package/.output/server/node_modules/ioredis/built/DataHandler.js +220 -0
  356. package/.output/server/node_modules/ioredis/built/Pipeline.js +334 -0
  357. package/.output/server/node_modules/ioredis/built/Redis.js +697 -0
  358. package/.output/server/node_modules/ioredis/built/ScanStream.js +51 -0
  359. package/.output/server/node_modules/ioredis/built/Script.js +62 -0
  360. package/.output/server/node_modules/ioredis/built/SubscriptionSet.js +41 -0
  361. package/.output/server/node_modules/ioredis/built/autoPipelining.js +159 -0
  362. package/.output/server/node_modules/ioredis/built/cluster/ClusterOptions.js +22 -0
  363. package/.output/server/node_modules/ioredis/built/cluster/ClusterSubscriber.js +202 -0
  364. package/.output/server/node_modules/ioredis/built/cluster/ClusterSubscriberGroup.js +224 -0
  365. package/.output/server/node_modules/ioredis/built/cluster/ConnectionPool.js +154 -0
  366. package/.output/server/node_modules/ioredis/built/cluster/DelayQueue.js +53 -0
  367. package/.output/server/node_modules/ioredis/built/cluster/index.js +862 -0
  368. package/.output/server/node_modules/ioredis/built/cluster/util.js +100 -0
  369. package/.output/server/node_modules/ioredis/built/connectors/AbstractConnector.js +26 -0
  370. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/FailoverDetector.js +45 -0
  371. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/SentinelIterator.js +37 -0
  372. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/index.js +305 -0
  373. package/.output/server/node_modules/ioredis/built/connectors/StandaloneConnector.js +69 -0
  374. package/.output/server/node_modules/ioredis/built/connectors/index.js +7 -0
  375. package/.output/server/node_modules/ioredis/built/constants/TLSProfiles.js +149 -0
  376. package/.output/server/node_modules/ioredis/built/errors/ClusterAllFailedError.js +15 -0
  377. package/.output/server/node_modules/ioredis/built/errors/MaxRetriesPerRequestError.js +14 -0
  378. package/.output/server/node_modules/ioredis/built/errors/index.js +5 -0
  379. package/.output/server/node_modules/ioredis/built/index.js +62 -0
  380. package/.output/server/node_modules/ioredis/built/redis/RedisOptions.js +55 -0
  381. package/.output/server/node_modules/ioredis/built/redis/event_handler.js +292 -0
  382. package/.output/server/node_modules/ioredis/built/transaction.js +93 -0
  383. package/.output/server/node_modules/ioredis/built/utils/Commander.js +117 -0
  384. package/.output/server/node_modules/ioredis/built/utils/applyMixin.js +8 -0
  385. package/.output/server/node_modules/ioredis/built/utils/debug.js +95 -0
  386. package/.output/server/node_modules/ioredis/built/utils/index.js +297 -0
  387. package/.output/server/node_modules/ioredis/built/utils/lodash.js +9 -0
  388. package/.output/server/node_modules/ioredis/package.json +100 -0
  389. package/.output/server/node_modules/lodash.defaults/index.js +668 -0
  390. package/.output/server/node_modules/lodash.defaults/package.json +19 -0
  391. package/.output/server/node_modules/lodash.isarguments/index.js +229 -0
  392. package/.output/server/node_modules/lodash.isarguments/package.json +19 -0
  393. package/.output/server/node_modules/lru-cache/dist/commonjs/index.js +1546 -0
  394. package/.output/server/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  395. package/.output/server/node_modules/lru-cache/package.json +116 -0
  396. package/.output/server/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  397. package/.output/server/node_modules/minimatch/dist/commonjs/ast.js +592 -0
  398. package/.output/server/node_modules/minimatch/dist/commonjs/brace-expressions.js +152 -0
  399. package/.output/server/node_modules/minimatch/dist/commonjs/escape.js +22 -0
  400. package/.output/server/node_modules/minimatch/dist/commonjs/index.js +1017 -0
  401. package/.output/server/node_modules/minimatch/dist/commonjs/package.json +3 -0
  402. package/.output/server/node_modules/minimatch/dist/commonjs/unescape.js +24 -0
  403. package/.output/server/node_modules/minimatch/package.json +82 -0
  404. package/.output/server/node_modules/minipass/dist/commonjs/index.js +1028 -0
  405. package/.output/server/node_modules/minipass/dist/commonjs/package.json +3 -0
  406. package/.output/server/node_modules/minipass/package.json +82 -0
  407. package/.output/server/node_modules/ms/index.js +162 -0
  408. package/.output/server/node_modules/ms/package.json +38 -0
  409. package/.output/server/node_modules/path-scurry/dist/commonjs/index.js +2014 -0
  410. package/.output/server/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  411. package/.output/server/node_modules/path-scurry/package.json +89 -0
  412. package/.output/server/node_modules/pg/lib/client.js +650 -0
  413. package/.output/server/node_modules/pg/lib/connection-parameters.js +167 -0
  414. package/.output/server/node_modules/pg/lib/connection.js +222 -0
  415. package/.output/server/node_modules/pg/lib/crypto/cert-signatures.js +121 -0
  416. package/.output/server/node_modules/pg/lib/crypto/sasl.js +212 -0
  417. package/.output/server/node_modules/pg/lib/crypto/utils-legacy.js +43 -0
  418. package/.output/server/node_modules/pg/lib/crypto/utils-webcrypto.js +88 -0
  419. package/.output/server/node_modules/pg/lib/crypto/utils.js +9 -0
  420. package/.output/server/node_modules/pg/lib/defaults.js +84 -0
  421. package/.output/server/node_modules/pg/lib/index.js +58 -0
  422. package/.output/server/node_modules/pg/lib/native/client.js +307 -0
  423. package/.output/server/node_modules/pg/lib/native/index.js +2 -0
  424. package/.output/server/node_modules/pg/lib/native/query.js +168 -0
  425. package/.output/server/node_modules/pg/lib/query.js +253 -0
  426. package/.output/server/node_modules/pg/lib/result.js +108 -0
  427. package/.output/server/node_modules/pg/lib/stream.js +81 -0
  428. package/.output/server/node_modules/pg/lib/type-overrides.js +35 -0
  429. package/.output/server/node_modules/pg/lib/utils.js +206 -0
  430. package/.output/server/node_modules/pg/package.json +62 -0
  431. package/.output/server/node_modules/pg-cloudflare/dist/empty.js +4 -0
  432. package/.output/server/node_modules/pg-cloudflare/package.json +32 -0
  433. package/.output/server/node_modules/pg-connection-string/index.js +112 -0
  434. package/.output/server/node_modules/pg-connection-string/package.json +40 -0
  435. package/.output/server/node_modules/pg-cursor/index.js +265 -0
  436. package/.output/server/node_modules/pg-cursor/package.json +38 -0
  437. package/.output/server/node_modules/pg-int8/index.js +100 -0
  438. package/.output/server/node_modules/pg-int8/package.json +24 -0
  439. package/.output/server/node_modules/pg-pool/index.js +471 -0
  440. package/.output/server/node_modules/pg-pool/package.json +41 -0
  441. package/.output/server/node_modules/pg-protocol/dist/buffer-reader.js +55 -0
  442. package/.output/server/node_modules/pg-protocol/dist/buffer-writer.js +81 -0
  443. package/.output/server/node_modules/pg-protocol/dist/index.js +15 -0
  444. package/.output/server/node_modules/pg-protocol/dist/messages.js +160 -0
  445. package/.output/server/node_modules/pg-protocol/dist/parser.js +304 -0
  446. package/.output/server/node_modules/pg-protocol/dist/serializer.js +189 -0
  447. package/.output/server/node_modules/pg-protocol/package.json +35 -0
  448. package/.output/server/node_modules/pg-query-stream/dist/index.js +48 -0
  449. package/.output/server/node_modules/pg-query-stream/package.json +60 -0
  450. package/.output/server/node_modules/pg-types/index.js +47 -0
  451. package/.output/server/node_modules/pg-types/lib/arrayParser.js +11 -0
  452. package/.output/server/node_modules/pg-types/lib/binaryParsers.js +257 -0
  453. package/.output/server/node_modules/pg-types/lib/builtins.js +73 -0
  454. package/.output/server/node_modules/pg-types/lib/textParsers.js +215 -0
  455. package/.output/server/node_modules/pg-types/package.json +42 -0
  456. package/.output/server/node_modules/pgpass/lib/helper.js +233 -0
  457. package/.output/server/node_modules/pgpass/lib/index.js +23 -0
  458. package/.output/server/node_modules/pgpass/package.json +41 -0
  459. package/.output/server/node_modules/postgres-array/index.js +97 -0
  460. package/.output/server/node_modules/postgres-array/package.json +35 -0
  461. package/.output/server/node_modules/postgres-bytea/index.js +31 -0
  462. package/.output/server/node_modules/postgres-bytea/package.json +34 -0
  463. package/.output/server/node_modules/postgres-date/index.js +116 -0
  464. package/.output/server/node_modules/postgres-date/package.json +33 -0
  465. package/.output/server/node_modules/postgres-interval/index.js +125 -0
  466. package/.output/server/node_modules/postgres-interval/package.json +36 -0
  467. package/.output/server/node_modules/redis-errors/index.js +7 -0
  468. package/.output/server/node_modules/redis-errors/lib/modern.js +59 -0
  469. package/.output/server/node_modules/redis-errors/lib/old.js +119 -0
  470. package/.output/server/node_modules/redis-errors/package.json +41 -0
  471. package/.output/server/node_modules/redis-parser/index.js +3 -0
  472. package/.output/server/node_modules/redis-parser/lib/parser.js +552 -0
  473. package/.output/server/node_modules/redis-parser/package.json +53 -0
  474. package/.output/server/node_modules/reflect-metadata/Reflect.js +1415 -0
  475. package/.output/server/node_modules/reflect-metadata/package.json +68 -0
  476. package/.output/server/node_modules/safe-buffer/index.js +65 -0
  477. package/.output/server/node_modules/safe-buffer/package.json +51 -0
  478. package/.output/server/node_modules/sha.js/hash.js +81 -0
  479. package/.output/server/node_modules/sha.js/index.js +15 -0
  480. package/.output/server/node_modules/sha.js/package.json +30 -0
  481. package/.output/server/node_modules/sha.js/sha.js +94 -0
  482. package/.output/server/node_modules/sha.js/sha1.js +99 -0
  483. package/.output/server/node_modules/sha.js/sha224.js +53 -0
  484. package/.output/server/node_modules/sha.js/sha256.js +135 -0
  485. package/.output/server/node_modules/sha.js/sha384.js +57 -0
  486. package/.output/server/node_modules/sha.js/sha512.js +260 -0
  487. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  488. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  489. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  490. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  491. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  492. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  493. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  494. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  495. package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
  496. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  497. package/.output/server/node_modules/source-map-js/package.json +71 -0
  498. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  499. package/.output/server/node_modules/split2/index.js +141 -0
  500. package/.output/server/node_modules/split2/package.json +39 -0
  501. package/.output/server/node_modules/sql-highlight/lib/escapeHtml.js +59 -0
  502. package/.output/server/node_modules/sql-highlight/lib/index.js +85 -0
  503. package/.output/server/node_modules/sql-highlight/lib/keywords.js +145 -0
  504. package/.output/server/node_modules/sql-highlight/package.json +49 -0
  505. package/.output/server/node_modules/sqlite3/build/Release/node_sqlite3.node +0 -0
  506. package/.output/server/node_modules/sqlite3/build/Release/node_sqlite3.node.bak +0 -0
  507. package/.output/server/node_modules/sqlite3/lib/sqlite3-binding.js +1 -0
  508. package/.output/server/node_modules/sqlite3/lib/sqlite3.js +207 -0
  509. package/.output/server/node_modules/sqlite3/lib/trace.js +38 -0
  510. package/.output/server/node_modules/sqlite3/package.json +89 -0
  511. package/.output/server/node_modules/standard-as-callback/built/index.js +41 -0
  512. package/.output/server/node_modules/standard-as-callback/built/utils.js +23 -0
  513. package/.output/server/node_modules/standard-as-callback/package.json +40 -0
  514. package/.output/server/node_modules/supports-color/index.js +152 -0
  515. package/.output/server/node_modules/supports-color/package.json +58 -0
  516. package/.output/server/node_modules/tslib/package.json +47 -0
  517. package/.output/server/node_modules/tslib/tslib.js +484 -0
  518. package/.output/server/node_modules/typeorm/cache/DbQueryResultCache.js +264 -0
  519. package/.output/server/node_modules/typeorm/cache/QueryResultCacheFactory.js +42 -0
  520. package/.output/server/node_modules/typeorm/cache/RedisQueryResultCache.js +197 -0
  521. package/.output/server/node_modules/typeorm/common/DeepPartial.js +4 -0
  522. package/.output/server/node_modules/typeorm/common/EntityTarget.js +4 -0
  523. package/.output/server/node_modules/typeorm/common/MixedList.js +4 -0
  524. package/.output/server/node_modules/typeorm/common/ObjectLiteral.js +4 -0
  525. package/.output/server/node_modules/typeorm/common/ObjectType.js +4 -0
  526. package/.output/server/node_modules/typeorm/common/RelationType.js +4 -0
  527. package/.output/server/node_modules/typeorm/connection/Connection.js +16 -0
  528. package/.output/server/node_modules/typeorm/connection/ConnectionManager.js +66 -0
  529. package/.output/server/node_modules/typeorm/connection/ConnectionMetadataBuilder.js +74 -0
  530. package/.output/server/node_modules/typeorm/connection/ConnectionOptionsReader.js +198 -0
  531. package/.output/server/node_modules/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js +111 -0
  532. package/.output/server/node_modules/typeorm/container.js +60 -0
  533. package/.output/server/node_modules/typeorm/data-source/DataSource.js +517 -0
  534. package/.output/server/node_modules/typeorm/decorator/Check.js +27 -0
  535. package/.output/server/node_modules/typeorm/decorator/EntityRepository.js +21 -0
  536. package/.output/server/node_modules/typeorm/decorator/Exclusion.js +27 -0
  537. package/.output/server/node_modules/typeorm/decorator/ForeignKey.js +44 -0
  538. package/.output/server/node_modules/typeorm/decorator/Generated.js +24 -0
  539. package/.output/server/node_modules/typeorm/decorator/Index.js +56 -0
  540. package/.output/server/node_modules/typeorm/decorator/Unique.js +50 -0
  541. package/.output/server/node_modules/typeorm/decorator/columns/Column.js +78 -0
  542. package/.output/server/node_modules/typeorm/decorator/columns/CreateDateColumn.js +21 -0
  543. package/.output/server/node_modules/typeorm/decorator/columns/DeleteDateColumn.js +20 -0
  544. package/.output/server/node_modules/typeorm/decorator/columns/ObjectIdColumn.js +27 -0
  545. package/.output/server/node_modules/typeorm/decorator/columns/PrimaryColumn.js +63 -0
  546. package/.output/server/node_modules/typeorm/decorator/columns/PrimaryGeneratedColumn.js +59 -0
  547. package/.output/server/node_modules/typeorm/decorator/columns/UpdateDateColumn.js +20 -0
  548. package/.output/server/node_modules/typeorm/decorator/columns/VersionColumn.js +21 -0
  549. package/.output/server/node_modules/typeorm/decorator/columns/ViewColumn.js +19 -0
  550. package/.output/server/node_modules/typeorm/decorator/columns/VirtualColumn.js +49 -0
  551. package/.output/server/node_modules/typeorm/decorator/entity/ChildEntity.js +25 -0
  552. package/.output/server/node_modules/typeorm/decorator/entity/Entity.js +31 -0
  553. package/.output/server/node_modules/typeorm/decorator/entity/TableInheritance.js +22 -0
  554. package/.output/server/node_modules/typeorm/decorator/entity-view/ViewEntity.js +32 -0
  555. package/.output/server/node_modules/typeorm/decorator/listeners/AfterInsert.js +19 -0
  556. package/.output/server/node_modules/typeorm/decorator/listeners/AfterLoad.js +19 -0
  557. package/.output/server/node_modules/typeorm/decorator/listeners/AfterRecover.js +19 -0
  558. package/.output/server/node_modules/typeorm/decorator/listeners/AfterRemove.js +19 -0
  559. package/.output/server/node_modules/typeorm/decorator/listeners/AfterSoftRemove.js +19 -0
  560. package/.output/server/node_modules/typeorm/decorator/listeners/AfterUpdate.js +19 -0
  561. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeInsert.js +19 -0
  562. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeRecover.js +19 -0
  563. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeRemove.js +19 -0
  564. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeSoftRemove.js +19 -0
  565. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeUpdate.js +19 -0
  566. package/.output/server/node_modules/typeorm/decorator/listeners/EventSubscriber.js +17 -0
  567. package/.output/server/node_modules/typeorm/decorator/options/ColumnOptions.js +4 -0
  568. package/.output/server/node_modules/typeorm/decorator/options/EntityOptions.js +4 -0
  569. package/.output/server/node_modules/typeorm/decorator/options/IndexOptions.js +4 -0
  570. package/.output/server/node_modules/typeorm/decorator/options/JoinColumnOptions.js +4 -0
  571. package/.output/server/node_modules/typeorm/decorator/options/JoinTableOptions.js +4 -0
  572. package/.output/server/node_modules/typeorm/decorator/options/RelationOptions.js +4 -0
  573. package/.output/server/node_modules/typeorm/decorator/options/ValueTransformer.js +4 -0
  574. package/.output/server/node_modules/typeorm/decorator/relations/JoinColumn.js +27 -0
  575. package/.output/server/node_modules/typeorm/decorator/relations/JoinTable.js +34 -0
  576. package/.output/server/node_modules/typeorm/decorator/relations/ManyToMany.js +46 -0
  577. package/.output/server/node_modules/typeorm/decorator/relations/ManyToOne.js +46 -0
  578. package/.output/server/node_modules/typeorm/decorator/relations/OneToMany.js +37 -0
  579. package/.output/server/node_modules/typeorm/decorator/relations/OneToOne.js +45 -0
  580. package/.output/server/node_modules/typeorm/decorator/relations/RelationCount.js +23 -0
  581. package/.output/server/node_modules/typeorm/decorator/relations/RelationId.js +22 -0
  582. package/.output/server/node_modules/typeorm/decorator/tree/Tree.js +21 -0
  583. package/.output/server/node_modules/typeorm/decorator/tree/TreeChildren.js +34 -0
  584. package/.output/server/node_modules/typeorm/decorator/tree/TreeLevelColumn.js +19 -0
  585. package/.output/server/node_modules/typeorm/decorator/tree/TreeParent.js +33 -0
  586. package/.output/server/node_modules/typeorm/driver/DriverFactory.js +98 -0
  587. package/.output/server/node_modules/typeorm/driver/DriverUtils.js +228 -0
  588. package/.output/server/node_modules/typeorm/driver/Query.js +16 -0
  589. package/.output/server/node_modules/typeorm/driver/SqlInMemory.js +15 -0
  590. package/.output/server/node_modules/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js +847 -0
  591. package/.output/server/node_modules/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1709 -0
  592. package/.output/server/node_modules/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js +103 -0
  593. package/.output/server/node_modules/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js +146 -0
  594. package/.output/server/node_modules/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js +153 -0
  595. package/.output/server/node_modules/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js +126 -0
  596. package/.output/server/node_modules/typeorm/driver/capacitor/CapacitorDriver.js +78 -0
  597. package/.output/server/node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js +98 -0
  598. package/.output/server/node_modules/typeorm/driver/cockroachdb/CockroachDriver.js +885 -0
  599. package/.output/server/node_modules/typeorm/driver/cockroachdb/CockroachQueryRunner.js +2453 -0
  600. package/.output/server/node_modules/typeorm/driver/cordova/CordovaDriver.js +76 -0
  601. package/.output/server/node_modules/typeorm/driver/cordova/CordovaQueryRunner.js +170 -0
  602. package/.output/server/node_modules/typeorm/driver/expo/ExpoDriver.js +29 -0
  603. package/.output/server/node_modules/typeorm/driver/expo/ExpoDriverFactory.js +22 -0
  604. package/.output/server/node_modules/typeorm/driver/expo/ExpoQueryRunner.js +65 -0
  605. package/.output/server/node_modules/typeorm/driver/expo/legacy/ExpoLegacyDriver.js +75 -0
  606. package/.output/server/node_modules/typeorm/driver/expo/legacy/ExpoLegacyQueryRunner.js +169 -0
  607. package/.output/server/node_modules/typeorm/driver/mongodb/MongoDriver.js +404 -0
  608. package/.output/server/node_modules/typeorm/driver/mongodb/MongoQueryRunner.js +701 -0
  609. package/.output/server/node_modules/typeorm/driver/mongodb/bson.typings.js +5 -0
  610. package/.output/server/node_modules/typeorm/driver/mongodb/typings.js +23 -0
  611. package/.output/server/node_modules/typeorm/driver/mysql/MysqlDriver.js +1105 -0
  612. package/.output/server/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js +2139 -0
  613. package/.output/server/node_modules/typeorm/driver/nativescript/NativescriptDriver.js +94 -0
  614. package/.output/server/node_modules/typeorm/driver/nativescript/NativescriptQueryRunner.js +92 -0
  615. package/.output/server/node_modules/typeorm/driver/oracle/OracleDriver.js +869 -0
  616. package/.output/server/node_modules/typeorm/driver/oracle/OracleQueryRunner.js +1884 -0
  617. package/.output/server/node_modules/typeorm/driver/postgres/PostgresDriver.js +1259 -0
  618. package/.output/server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js +2729 -0
  619. package/.output/server/node_modules/typeorm/driver/react-native/ReactNativeDriver.js +728 -0
  620. package/.output/server/node_modules/typeorm/driver/react-native/ReactNativeQueryRunner.js +107 -0
  621. package/.output/server/node_modules/typeorm/driver/sap/SapDriver.js +681 -0
  622. package/.output/server/node_modules/typeorm/driver/sap/SapQueryRunner.js +2054 -0
  623. package/.output/server/node_modules/typeorm/driver/spanner/SpannerDriver.js +613 -0
  624. package/.output/server/node_modules/typeorm/driver/spanner/SpannerQueryRunner.js +1464 -0
  625. package/.output/server/node_modules/typeorm/driver/sqlite/SqliteDriver.js +174 -0
  626. package/.output/server/node_modules/typeorm/driver/sqlite/SqliteQueryRunner.js +124 -0
  627. package/.output/server/node_modules/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js +695 -0
  628. package/.output/server/node_modules/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1511 -0
  629. package/.output/server/node_modules/typeorm/driver/sqljs/SqljsDriver.js +250 -0
  630. package/.output/server/node_modules/typeorm/driver/sqljs/SqljsQueryRunner.js +123 -0
  631. package/.output/server/node_modules/typeorm/driver/sqlserver/MssqlParameter.js +23 -0
  632. package/.output/server/node_modules/typeorm/driver/sqlserver/SqlServerDriver.js +922 -0
  633. package/.output/server/node_modules/typeorm/driver/sqlserver/SqlServerQueryRunner.js +2484 -0
  634. package/.output/server/node_modules/typeorm/driver/types/DatabaseType.js +4 -0
  635. package/.output/server/node_modules/typeorm/driver/types/GeoJsonTypes.js +4 -0
  636. package/.output/server/node_modules/typeorm/driver/types/MetadataTableType.js +11 -0
  637. package/.output/server/node_modules/typeorm/driver/types/ReplicationMode.js +4 -0
  638. package/.output/server/node_modules/typeorm/entity-manager/EntityManager.js +853 -0
  639. package/.output/server/node_modules/typeorm/entity-manager/EntityManagerFactory.js +24 -0
  640. package/.output/server/node_modules/typeorm/entity-manager/MongoEntityManager.js +668 -0
  641. package/.output/server/node_modules/typeorm/entity-manager/SqljsEntityManager.js +44 -0
  642. package/.output/server/node_modules/typeorm/entity-schema/EntitySchema.js +15 -0
  643. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js +8 -0
  644. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaEmbeddedError.js +18 -0
  645. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaOptions.js +11 -0
  646. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaTransformer.js +333 -0
  647. package/.output/server/node_modules/typeorm/error/AlreadyHasActiveConnectionError.js +16 -0
  648. package/.output/server/node_modules/typeorm/error/CannotAttachTreeChildrenEntityError.js +16 -0
  649. package/.output/server/node_modules/typeorm/error/CannotConnectAlreadyConnectedError.js +15 -0
  650. package/.output/server/node_modules/typeorm/error/CannotCreateEntityIdMapError.js +21 -0
  651. package/.output/server/node_modules/typeorm/error/CannotDetermineEntityError.js +16 -0
  652. package/.output/server/node_modules/typeorm/error/CannotExecuteNotConnectedError.js +15 -0
  653. package/.output/server/node_modules/typeorm/error/CannotGetEntityManagerNotConnectedError.js +15 -0
  654. package/.output/server/node_modules/typeorm/error/CannotReflectMethodParameterTypeError.js +18 -0
  655. package/.output/server/node_modules/typeorm/error/CircularRelationsError.js +16 -0
  656. package/.output/server/node_modules/typeorm/error/ColumnTypeUndefinedError.js +19 -0
  657. package/.output/server/node_modules/typeorm/error/ConnectionIsNotSetError.js +15 -0
  658. package/.output/server/node_modules/typeorm/error/ConnectionNotFoundError.js +15 -0
  659. package/.output/server/node_modules/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js +18 -0
  660. package/.output/server/node_modules/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js +18 -0
  661. package/.output/server/node_modules/typeorm/error/CustomRepositoryNotFoundError.js +18 -0
  662. package/.output/server/node_modules/typeorm/error/DataTypeNotSupportedError.js +14 -0
  663. package/.output/server/node_modules/typeorm/error/DriverOptionNotSetError.js +16 -0
  664. package/.output/server/node_modules/typeorm/error/DriverPackageNotInstalledError.js +16 -0
  665. package/.output/server/node_modules/typeorm/error/EntityMetadataNotFoundError.js +29 -0
  666. package/.output/server/node_modules/typeorm/error/EntityNotFoundError.js +42 -0
  667. package/.output/server/node_modules/typeorm/error/EntityPropertyNotFoundError.js +17 -0
  668. package/.output/server/node_modules/typeorm/error/FindRelationsNotFoundError.js +23 -0
  669. package/.output/server/node_modules/typeorm/error/ForbiddenTransactionModeOverrideError.js +16 -0
  670. package/.output/server/node_modules/typeorm/error/InitializedRelationError.js +20 -0
  671. package/.output/server/node_modules/typeorm/error/InsertValuesMissingError.js +16 -0
  672. package/.output/server/node_modules/typeorm/error/LimitOnUpdateNotSupportedError.js +15 -0
  673. package/.output/server/node_modules/typeorm/error/LockNotSupportedOnGivenDriverError.js +15 -0
  674. package/.output/server/node_modules/typeorm/error/MetadataAlreadyExistsError.js +18 -0
  675. package/.output/server/node_modules/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js +16 -0
  676. package/.output/server/node_modules/typeorm/error/MissingDeleteDateColumnError.js +12 -0
  677. package/.output/server/node_modules/typeorm/error/MissingDriverError.js +16 -0
  678. package/.output/server/node_modules/typeorm/error/MissingJoinColumnError.js +23 -0
  679. package/.output/server/node_modules/typeorm/error/MissingJoinTableError.js +23 -0
  680. package/.output/server/node_modules/typeorm/error/MissingPrimaryColumnError.js +13 -0
  681. package/.output/server/node_modules/typeorm/error/MustBeEntityError.js +15 -0
  682. package/.output/server/node_modules/typeorm/error/NestedSetMultipleRootError.js +12 -0
  683. package/.output/server/node_modules/typeorm/error/NoConnectionForRepositoryError.js +16 -0
  684. package/.output/server/node_modules/typeorm/error/NoConnectionOptionError.js +16 -0
  685. package/.output/server/node_modules/typeorm/error/NoNeedToReleaseEntityManagerError.js +17 -0
  686. package/.output/server/node_modules/typeorm/error/NoVersionOrUpdateDateColumnError.js +15 -0
  687. package/.output/server/node_modules/typeorm/error/OffsetWithoutLimitNotSupportedError.js +17 -0
  688. package/.output/server/node_modules/typeorm/error/OptimisticLockCanNotBeUsedError.js +15 -0
  689. package/.output/server/node_modules/typeorm/error/OptimisticLockVersionMismatchError.js +15 -0
  690. package/.output/server/node_modules/typeorm/error/PersistedEntityNotFoundError.js +15 -0
  691. package/.output/server/node_modules/typeorm/error/PessimisticLockTransactionRequiredError.js +15 -0
  692. package/.output/server/node_modules/typeorm/error/PrimaryColumnCannotBeNullableError.js +13 -0
  693. package/.output/server/node_modules/typeorm/error/QueryFailedError.js +30 -0
  694. package/.output/server/node_modules/typeorm/error/QueryRunnerAlreadyReleasedError.js +12 -0
  695. package/.output/server/node_modules/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js +16 -0
  696. package/.output/server/node_modules/typeorm/error/RepositoryNotTreeError.js +32 -0
  697. package/.output/server/node_modules/typeorm/error/ReturningStatementNotSupportedError.js +16 -0
  698. package/.output/server/node_modules/typeorm/error/SubjectRemovedAndUpdatedError.js +16 -0
  699. package/.output/server/node_modules/typeorm/error/SubjectWithoutIdentifierError.js +17 -0
  700. package/.output/server/node_modules/typeorm/error/TransactionAlreadyStartedError.js +15 -0
  701. package/.output/server/node_modules/typeorm/error/TransactionNotStartedError.js +15 -0
  702. package/.output/server/node_modules/typeorm/error/TreeRepositoryNotSupportedError.js +12 -0
  703. package/.output/server/node_modules/typeorm/error/TypeORMError.js +23 -0
  704. package/.output/server/node_modules/typeorm/error/UpdateValuesMissingError.js +12 -0
  705. package/.output/server/node_modules/typeorm/error/UsingJoinColumnIsNotAllowedError.js +13 -0
  706. package/.output/server/node_modules/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js +14 -0
  707. package/.output/server/node_modules/typeorm/error/UsingJoinTableIsNotAllowedError.js +14 -0
  708. package/.output/server/node_modules/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js +14 -0
  709. package/.output/server/node_modules/typeorm/error/index.js +66 -0
  710. package/.output/server/node_modules/typeorm/find-options/EqualOperator.js +13 -0
  711. package/.output/server/node_modules/typeorm/find-options/FindManyOptions.js +4 -0
  712. package/.output/server/node_modules/typeorm/find-options/FindOneOptions.js +4 -0
  713. package/.output/server/node_modules/typeorm/find-options/FindOperator.js +96 -0
  714. package/.output/server/node_modules/typeorm/find-options/FindOperatorType.js +4 -0
  715. package/.output/server/node_modules/typeorm/find-options/FindOptionsOrder.js +4 -0
  716. package/.output/server/node_modules/typeorm/find-options/FindOptionsRelations.js +4 -0
  717. package/.output/server/node_modules/typeorm/find-options/FindOptionsSelect.js +4 -0
  718. package/.output/server/node_modules/typeorm/find-options/FindOptionsUtils.js +350 -0
  719. package/.output/server/node_modules/typeorm/find-options/FindOptionsWhere.js +4 -0
  720. package/.output/server/node_modules/typeorm/find-options/FindTreeOptions.js +4 -0
  721. package/.output/server/node_modules/typeorm/find-options/JoinOptions.js +4 -0
  722. package/.output/server/node_modules/typeorm/find-options/OrderByCondition.js +4 -0
  723. package/.output/server/node_modules/typeorm/find-options/operator/And.js +9 -0
  724. package/.output/server/node_modules/typeorm/find-options/operator/Any.js +13 -0
  725. package/.output/server/node_modules/typeorm/find-options/operator/ArrayContainedBy.js +13 -0
  726. package/.output/server/node_modules/typeorm/find-options/operator/ArrayContains.js +13 -0
  727. package/.output/server/node_modules/typeorm/find-options/operator/ArrayOverlap.js +13 -0
  728. package/.output/server/node_modules/typeorm/find-options/operator/Between.js +13 -0
  729. package/.output/server/node_modules/typeorm/find-options/operator/Equal.js +17 -0
  730. package/.output/server/node_modules/typeorm/find-options/operator/ILike.js +13 -0
  731. package/.output/server/node_modules/typeorm/find-options/operator/In.js +13 -0
  732. package/.output/server/node_modules/typeorm/find-options/operator/IsNull.js +13 -0
  733. package/.output/server/node_modules/typeorm/find-options/operator/JsonContains.js +13 -0
  734. package/.output/server/node_modules/typeorm/find-options/operator/LessThan.js +13 -0
  735. package/.output/server/node_modules/typeorm/find-options/operator/LessThanOrEqual.js +13 -0
  736. package/.output/server/node_modules/typeorm/find-options/operator/Like.js +13 -0
  737. package/.output/server/node_modules/typeorm/find-options/operator/MoreThan.js +13 -0
  738. package/.output/server/node_modules/typeorm/find-options/operator/MoreThanOrEqual.js +13 -0
  739. package/.output/server/node_modules/typeorm/find-options/operator/Not.js +14 -0
  740. package/.output/server/node_modules/typeorm/find-options/operator/Or.js +9 -0
  741. package/.output/server/node_modules/typeorm/find-options/operator/Raw.js +12 -0
  742. package/.output/server/node_modules/typeorm/globals.js +182 -0
  743. package/.output/server/node_modules/typeorm/index.js +196 -0
  744. package/.output/server/node_modules/typeorm/index.mjs +422 -0
  745. package/.output/server/node_modules/typeorm/logger/AbstractLogger.js +238 -0
  746. package/.output/server/node_modules/typeorm/logger/AdvancedConsoleLogger.js +56 -0
  747. package/.output/server/node_modules/typeorm/logger/DebugLogger.js +78 -0
  748. package/.output/server/node_modules/typeorm/logger/FileLogger.js +88 -0
  749. package/.output/server/node_modules/typeorm/logger/FormattedConsoleLogger.js +59 -0
  750. package/.output/server/node_modules/typeorm/logger/Logger.js +4 -0
  751. package/.output/server/node_modules/typeorm/logger/LoggerFactory.js +39 -0
  752. package/.output/server/node_modules/typeorm/logger/LoggerOptions.js +4 -0
  753. package/.output/server/node_modules/typeorm/logger/SimpleConsoleLogger.js +57 -0
  754. package/.output/server/node_modules/typeorm/metadata/CheckMetadata.js +35 -0
  755. package/.output/server/node_modules/typeorm/metadata/ColumnMetadata.js +618 -0
  756. package/.output/server/node_modules/typeorm/metadata/EmbeddedMetadata.js +224 -0
  757. package/.output/server/node_modules/typeorm/metadata/EntityListenerMetadata.js +77 -0
  758. package/.output/server/node_modules/typeorm/metadata/EntityMetadata.js +692 -0
  759. package/.output/server/node_modules/typeorm/metadata/ExclusionMetadata.js +35 -0
  760. package/.output/server/node_modules/typeorm/metadata/ForeignKeyMetadata.js +57 -0
  761. package/.output/server/node_modules/typeorm/metadata/IndexMetadata.js +144 -0
  762. package/.output/server/node_modules/typeorm/metadata/RelationCountMetadata.js +39 -0
  763. package/.output/server/node_modules/typeorm/metadata/RelationIdMetadata.js +62 -0
  764. package/.output/server/node_modules/typeorm/metadata/RelationMetadata.js +440 -0
  765. package/.output/server/node_modules/typeorm/metadata/UniqueMetadata.js +101 -0
  766. package/.output/server/node_modules/typeorm/metadata/types/EventListenerTypes.js +22 -0
  767. package/.output/server/node_modules/typeorm/metadata-args/MetadataArgsStorage.js +236 -0
  768. package/.output/server/node_modules/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js +145 -0
  769. package/.output/server/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js +838 -0
  770. package/.output/server/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js +258 -0
  771. package/.output/server/node_modules/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js +287 -0
  772. package/.output/server/node_modules/typeorm/metadata-builder/MetadataUtils.js +44 -0
  773. package/.output/server/node_modules/typeorm/metadata-builder/RelationJoinColumnBuilder.js +185 -0
  774. package/.output/server/node_modules/typeorm/migration/Migration.js +21 -0
  775. package/.output/server/node_modules/typeorm/migration/MigrationExecutor.js +534 -0
  776. package/.output/server/node_modules/typeorm/naming-strategy/DefaultNamingStrategy.js +145 -0
  777. package/.output/server/node_modules/typeorm/naming-strategy/LegacyOracleNamingStrategy.js +50 -0
  778. package/.output/server/node_modules/typeorm/package.json +268 -0
  779. package/.output/server/node_modules/typeorm/persistence/EntityPersistExecutor.js +170 -0
  780. package/.output/server/node_modules/typeorm/persistence/Subject.js +239 -0
  781. package/.output/server/node_modules/typeorm/persistence/SubjectChangedColumnsComputer.js +216 -0
  782. package/.output/server/node_modules/typeorm/persistence/SubjectDatabaseEntityLoader.js +135 -0
  783. package/.output/server/node_modules/typeorm/persistence/SubjectExecutor.js +760 -0
  784. package/.output/server/node_modules/typeorm/persistence/SubjectTopologicalSorter.js +174 -0
  785. package/.output/server/node_modules/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js +107 -0
  786. package/.output/server/node_modules/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js +218 -0
  787. package/.output/server/node_modules/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js +181 -0
  788. package/.output/server/node_modules/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js +155 -0
  789. package/.output/server/node_modules/typeorm/persistence/tree/ClosureSubjectExecutor.js +241 -0
  790. package/.output/server/node_modules/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js +125 -0
  791. package/.output/server/node_modules/typeorm/persistence/tree/NestedSetSubjectExecutor.js +271 -0
  792. package/.output/server/node_modules/typeorm/platform/PlatformTools.js +243 -0
  793. package/.output/server/node_modules/typeorm/query-builder/Alias.js +29 -0
  794. package/.output/server/node_modules/typeorm/query-builder/Brackets.js +19 -0
  795. package/.output/server/node_modules/typeorm/query-builder/DeleteQueryBuilder.js +200 -0
  796. package/.output/server/node_modules/typeorm/query-builder/InsertQueryBuilder.js +745 -0
  797. package/.output/server/node_modules/typeorm/query-builder/JoinAttribute.js +175 -0
  798. package/.output/server/node_modules/typeorm/query-builder/NotBrackets.js +17 -0
  799. package/.output/server/node_modules/typeorm/query-builder/QueryBuilder.js +1139 -0
  800. package/.output/server/node_modules/typeorm/query-builder/QueryBuilderUtils.js +32 -0
  801. package/.output/server/node_modules/typeorm/query-builder/QueryExpressionMap.js +328 -0
  802. package/.output/server/node_modules/typeorm/query-builder/RelationIdLoader.js +503 -0
  803. package/.output/server/node_modules/typeorm/query-builder/RelationLoader.js +283 -0
  804. package/.output/server/node_modules/typeorm/query-builder/RelationQueryBuilder.js +155 -0
  805. package/.output/server/node_modules/typeorm/query-builder/RelationRemover.js +143 -0
  806. package/.output/server/node_modules/typeorm/query-builder/RelationUpdater.js +152 -0
  807. package/.output/server/node_modules/typeorm/query-builder/ReturningResultsEntityUpdator.js +176 -0
  808. package/.output/server/node_modules/typeorm/query-builder/SelectQueryBuilder.js +2656 -0
  809. package/.output/server/node_modules/typeorm/query-builder/SoftDeleteQueryBuilder.js +368 -0
  810. package/.output/server/node_modules/typeorm/query-builder/UpdateQueryBuilder.js +498 -0
  811. package/.output/server/node_modules/typeorm/query-builder/index.js +20 -0
  812. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountAttribute.js +80 -0
  813. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountLoader.js +168 -0
  814. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js +55 -0
  815. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdAttribute.js +88 -0
  816. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js +275 -0
  817. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js +55 -0
  818. package/.output/server/node_modules/typeorm/query-builder/result/DeleteResult.js +17 -0
  819. package/.output/server/node_modules/typeorm/query-builder/result/InsertResult.js +28 -0
  820. package/.output/server/node_modules/typeorm/query-builder/result/UpdateResult.js +29 -0
  821. package/.output/server/node_modules/typeorm/query-builder/transformer/DocumentToEntityTransformer.js +196 -0
  822. package/.output/server/node_modules/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js +112 -0
  823. package/.output/server/node_modules/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js +92 -0
  824. package/.output/server/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js +447 -0
  825. package/.output/server/node_modules/typeorm/query-runner/BaseQueryRunner.js +454 -0
  826. package/.output/server/node_modules/typeorm/query-runner/QueryLock.js +28 -0
  827. package/.output/server/node_modules/typeorm/query-runner/QueryResult.js +17 -0
  828. package/.output/server/node_modules/typeorm/repository/AbstractRepository.js +92 -0
  829. package/.output/server/node_modules/typeorm/repository/BaseEntity.js +328 -0
  830. package/.output/server/node_modules/typeorm/repository/MongoRepository.js +305 -0
  831. package/.output/server/node_modules/typeorm/repository/RemoveOptions.js +4 -0
  832. package/.output/server/node_modules/typeorm/repository/Repository.js +379 -0
  833. package/.output/server/node_modules/typeorm/repository/SaveOptions.js +4 -0
  834. package/.output/server/node_modules/typeorm/repository/TreeRepository.js +255 -0
  835. package/.output/server/node_modules/typeorm/schema-builder/MongoSchemaBuilder.js +66 -0
  836. package/.output/server/node_modules/typeorm/schema-builder/RdbmsSchemaBuilder.js +929 -0
  837. package/.output/server/node_modules/typeorm/schema-builder/options/TableCheckOptions.js +4 -0
  838. package/.output/server/node_modules/typeorm/schema-builder/options/TableColumnOptions.js +4 -0
  839. package/.output/server/node_modules/typeorm/schema-builder/options/TableExclusionOptions.js +4 -0
  840. package/.output/server/node_modules/typeorm/schema-builder/options/TableForeignKeyOptions.js +4 -0
  841. package/.output/server/node_modules/typeorm/schema-builder/options/TableIndexOptions.js +4 -0
  842. package/.output/server/node_modules/typeorm/schema-builder/options/TableOptions.js +4 -0
  843. package/.output/server/node_modules/typeorm/schema-builder/options/TableUniqueOptions.js +4 -0
  844. package/.output/server/node_modules/typeorm/schema-builder/options/ViewOptions.js +4 -0
  845. package/.output/server/node_modules/typeorm/schema-builder/table/Table.js +296 -0
  846. package/.output/server/node_modules/typeorm/schema-builder/table/TableCheck.js +49 -0
  847. package/.output/server/node_modules/typeorm/schema-builder/table/TableColumn.js +117 -0
  848. package/.output/server/node_modules/typeorm/schema-builder/table/TableExclusion.js +43 -0
  849. package/.output/server/node_modules/typeorm/schema-builder/table/TableForeignKey.js +72 -0
  850. package/.output/server/node_modules/typeorm/schema-builder/table/TableIndex.js +68 -0
  851. package/.output/server/node_modules/typeorm/schema-builder/table/TableUnique.js +50 -0
  852. package/.output/server/node_modules/typeorm/schema-builder/util/TableUtils.js +41 -0
  853. package/.output/server/node_modules/typeorm/schema-builder/util/ViewUtils.js +27 -0
  854. package/.output/server/node_modules/typeorm/schema-builder/view/View.js +71 -0
  855. package/.output/server/node_modules/typeorm/subscriber/Broadcaster.js +660 -0
  856. package/.output/server/node_modules/typeorm/subscriber/BroadcasterResult.js +30 -0
  857. package/.output/server/node_modules/typeorm/subscriber/event/QueryEvent.js +4 -0
  858. package/.output/server/node_modules/typeorm/util/ApplyValueTransformers.js +25 -0
  859. package/.output/server/node_modules/typeorm/util/DateUtils.js +229 -0
  860. package/.output/server/node_modules/typeorm/util/DepGraph.js +230 -0
  861. package/.output/server/node_modules/typeorm/util/DirectoryExportedClassesLoader.js +65 -0
  862. package/.output/server/node_modules/typeorm/util/ImportUtils.js +66 -0
  863. package/.output/server/node_modules/typeorm/util/InstanceChecker.js +104 -0
  864. package/.output/server/node_modules/typeorm/util/ObjectUtils.js +49 -0
  865. package/.output/server/node_modules/typeorm/util/OrmUtils.js +443 -0
  866. package/.output/server/node_modules/typeorm/util/PathUtils.js +33 -0
  867. package/.output/server/node_modules/typeorm/util/RandomGenerator.js +154 -0
  868. package/.output/server/node_modules/typeorm/util/SqlTagUtils.js +43 -0
  869. package/.output/server/node_modules/typeorm/util/StringUtils.js +113 -0
  870. package/.output/server/node_modules/typeorm/util/TreeRepositoryUtils.js +67 -0
  871. package/.output/server/node_modules/typeorm/util/VersionUtils.js +27 -0
  872. package/.output/server/node_modules/typeorm/util/escapeRegExp.js +10 -0
  873. package/.output/server/node_modules/ufo/dist/index.mjs +630 -0
  874. package/.output/server/node_modules/ufo/package.json +47 -0
  875. package/.output/server/node_modules/unhead/dist/plugins.mjs +94 -0
  876. package/.output/server/node_modules/unhead/dist/server.mjs +220 -0
  877. package/.output/server/node_modules/unhead/dist/shared/unhead.C13swrCa.mjs +48 -0
  878. package/.output/server/node_modules/unhead/dist/shared/unhead.CApf5sj3.mjs +148 -0
  879. package/.output/server/node_modules/unhead/dist/shared/unhead.Cp0iF6eN.mjs +177 -0
  880. package/.output/server/node_modules/unhead/dist/shared/unhead.DGkFBTYv.mjs +172 -0
  881. package/.output/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
  882. package/.output/server/node_modules/unhead/dist/shared/unhead.DZbvapt-.mjs +70 -0
  883. package/.output/server/node_modules/unhead/dist/shared/unhead.DeCxexjU.mjs +166 -0
  884. package/.output/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
  885. package/.output/server/node_modules/unhead/dist/utils.mjs +5 -0
  886. package/.output/server/node_modules/unhead/package.json +101 -0
  887. package/.output/server/node_modules/uuid/dist/cjs/index.js +31 -0
  888. package/.output/server/node_modules/uuid/dist/cjs/max.js +3 -0
  889. package/.output/server/node_modules/uuid/dist/cjs/md5.js +13 -0
  890. package/.output/server/node_modules/uuid/dist/cjs/native.js +4 -0
  891. package/.output/server/node_modules/uuid/dist/cjs/nil.js +3 -0
  892. package/.output/server/node_modules/uuid/dist/cjs/package.json +1 -0
  893. package/.output/server/node_modules/uuid/dist/cjs/parse.js +11 -0
  894. package/.output/server/node_modules/uuid/dist/cjs/regex.js +3 -0
  895. package/.output/server/node_modules/uuid/dist/cjs/rng.js +13 -0
  896. package/.output/server/node_modules/uuid/dist/cjs/sha1.js +13 -0
  897. package/.output/server/node_modules/uuid/dist/cjs/stringify.js +39 -0
  898. package/.output/server/node_modules/uuid/dist/cjs/v1.js +87 -0
  899. package/.output/server/node_modules/uuid/dist/cjs/v1ToV6.js +13 -0
  900. package/.output/server/node_modules/uuid/dist/cjs/v3.js +14 -0
  901. package/.output/server/node_modules/uuid/dist/cjs/v35.js +41 -0
  902. package/.output/server/node_modules/uuid/dist/cjs/v4.js +29 -0
  903. package/.output/server/node_modules/uuid/dist/cjs/v5.js +14 -0
  904. package/.output/server/node_modules/uuid/dist/cjs/v6.js +19 -0
  905. package/.output/server/node_modules/uuid/dist/cjs/v6ToV1.js +13 -0
  906. package/.output/server/node_modules/uuid/dist/cjs/v7.js +69 -0
  907. package/.output/server/node_modules/uuid/dist/cjs/validate.js +7 -0
  908. package/.output/server/node_modules/uuid/dist/cjs/version.js +10 -0
  909. package/.output/server/node_modules/uuid/package.json +132 -0
  910. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  911. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  912. package/.output/server/node_modules/vue/index.js +7 -0
  913. package/.output/server/node_modules/vue/index.mjs +1 -0
  914. package/.output/server/node_modules/vue/package.json +112 -0
  915. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  916. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +196 -0
  917. package/.output/server/node_modules/vue-bundle-renderer/package.json +50 -0
  918. package/.output/server/node_modules/xtend/mutable.js +17 -0
  919. package/.output/server/node_modules/xtend/package.json +55 -0
  920. package/.output/server/node_modules/zod/index.js +4 -0
  921. package/.output/server/node_modules/zod/package.json +135 -0
  922. package/.output/server/node_modules/zod/v3/ZodError.js +133 -0
  923. package/.output/server/node_modules/zod/v3/errors.js +9 -0
  924. package/.output/server/node_modules/zod/v3/external.js +6 -0
  925. package/.output/server/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  926. package/.output/server/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  927. package/.output/server/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  928. package/.output/server/node_modules/zod/v3/helpers/util.js +133 -0
  929. package/.output/server/node_modules/zod/v3/index.js +4 -0
  930. package/.output/server/node_modules/zod/v3/locales/en.js +109 -0
  931. package/.output/server/node_modules/zod/v3/package.json +6 -0
  932. package/.output/server/node_modules/zod/v3/types.js +3695 -0
  933. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -0
  934. package/.output/server/node_modules/zod/v4/classic/coerce.js +17 -0
  935. package/.output/server/node_modules/zod/v4/classic/compat.js +31 -0
  936. package/.output/server/node_modules/zod/v4/classic/errors.js +48 -0
  937. package/.output/server/node_modules/zod/v4/classic/external.js +20 -0
  938. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +584 -0
  939. package/.output/server/node_modules/zod/v4/classic/index.js +4 -0
  940. package/.output/server/node_modules/zod/v4/classic/iso.js +30 -0
  941. package/.output/server/node_modules/zod/v4/classic/package.json +6 -0
  942. package/.output/server/node_modules/zod/v4/classic/parse.js +15 -0
  943. package/.output/server/node_modules/zod/v4/classic/schemas.js +1157 -0
  944. package/.output/server/node_modules/zod/v4/core/api.js +1082 -0
  945. package/.output/server/node_modules/zod/v4/core/checks.js +575 -0
  946. package/.output/server/node_modules/zod/v4/core/core.js +76 -0
  947. package/.output/server/node_modules/zod/v4/core/doc.js +35 -0
  948. package/.output/server/node_modules/zod/v4/core/errors.js +182 -0
  949. package/.output/server/node_modules/zod/v4/core/index.js +16 -0
  950. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +95 -0
  951. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +605 -0
  952. package/.output/server/node_modules/zod/v4/core/json-schema.js +1 -0
  953. package/.output/server/node_modules/zod/v4/core/package.json +6 -0
  954. package/.output/server/node_modules/zod/v4/core/parse.js +93 -0
  955. package/.output/server/node_modules/zod/v4/core/regexes.js +133 -0
  956. package/.output/server/node_modules/zod/v4/core/registries.js +51 -0
  957. package/.output/server/node_modules/zod/v4/core/schemas.js +2095 -0
  958. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +437 -0
  959. package/.output/server/node_modules/zod/v4/core/util.js +651 -0
  960. package/.output/server/node_modules/zod/v4/core/versions.js +5 -0
  961. package/.output/server/node_modules/zod/v4/index.js +3 -0
  962. package/.output/server/node_modules/zod/v4/locales/ar.js +106 -0
  963. package/.output/server/node_modules/zod/v4/locales/az.js +105 -0
  964. package/.output/server/node_modules/zod/v4/locales/be.js +156 -0
  965. package/.output/server/node_modules/zod/v4/locales/bg.js +120 -0
  966. package/.output/server/node_modules/zod/v4/locales/ca.js +107 -0
  967. package/.output/server/node_modules/zod/v4/locales/cs.js +111 -0
  968. package/.output/server/node_modules/zod/v4/locales/da.js +115 -0
  969. package/.output/server/node_modules/zod/v4/locales/de.js +108 -0
  970. package/.output/server/node_modules/zod/v4/locales/en.js +109 -0
  971. package/.output/server/node_modules/zod/v4/locales/eo.js +109 -0
  972. package/.output/server/node_modules/zod/v4/locales/es.js +132 -0
  973. package/.output/server/node_modules/zod/v4/locales/fa.js +114 -0
  974. package/.output/server/node_modules/zod/v4/locales/fi.js +112 -0
  975. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +107 -0
  976. package/.output/server/node_modules/zod/v4/locales/fr.js +108 -0
  977. package/.output/server/node_modules/zod/v4/locales/he.js +214 -0
  978. package/.output/server/node_modules/zod/v4/locales/hu.js +108 -0
  979. package/.output/server/node_modules/zod/v4/locales/hy.js +147 -0
  980. package/.output/server/node_modules/zod/v4/locales/id.js +106 -0
  981. package/.output/server/node_modules/zod/v4/locales/index.js +49 -0
  982. package/.output/server/node_modules/zod/v4/locales/is.js +109 -0
  983. package/.output/server/node_modules/zod/v4/locales/it.js +108 -0
  984. package/.output/server/node_modules/zod/v4/locales/ja.js +107 -0
  985. package/.output/server/node_modules/zod/v4/locales/ka.js +112 -0
  986. package/.output/server/node_modules/zod/v4/locales/kh.js +5 -0
  987. package/.output/server/node_modules/zod/v4/locales/km.js +110 -0
  988. package/.output/server/node_modules/zod/v4/locales/ko.js +111 -0
  989. package/.output/server/node_modules/zod/v4/locales/lt.js +203 -0
  990. package/.output/server/node_modules/zod/v4/locales/mk.js +109 -0
  991. package/.output/server/node_modules/zod/v4/locales/ms.js +107 -0
  992. package/.output/server/node_modules/zod/v4/locales/nl.js +110 -0
  993. package/.output/server/node_modules/zod/v4/locales/no.js +108 -0
  994. package/.output/server/node_modules/zod/v4/locales/ota.js +109 -0
  995. package/.output/server/node_modules/zod/v4/locales/package.json +6 -0
  996. package/.output/server/node_modules/zod/v4/locales/pl.js +109 -0
  997. package/.output/server/node_modules/zod/v4/locales/ps.js +114 -0
  998. package/.output/server/node_modules/zod/v4/locales/pt.js +108 -0
  999. package/.output/server/node_modules/zod/v4/locales/ru.js +156 -0
  1000. package/.output/server/node_modules/zod/v4/locales/sl.js +109 -0
  1001. package/.output/server/node_modules/zod/v4/locales/sv.js +110 -0
  1002. package/.output/server/node_modules/zod/v4/locales/ta.js +110 -0
  1003. package/.output/server/node_modules/zod/v4/locales/th.js +110 -0
  1004. package/.output/server/node_modules/zod/v4/locales/tr.js +105 -0
  1005. package/.output/server/node_modules/zod/v4/locales/ua.js +5 -0
  1006. package/.output/server/node_modules/zod/v4/locales/uk.js +108 -0
  1007. package/.output/server/node_modules/zod/v4/locales/ur.js +110 -0
  1008. package/.output/server/node_modules/zod/v4/locales/uz.js +109 -0
  1009. package/.output/server/node_modules/zod/v4/locales/vi.js +108 -0
  1010. package/.output/server/node_modules/zod/v4/locales/yo.js +107 -0
  1011. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +109 -0
  1012. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +107 -0
  1013. package/.output/server/node_modules/zod/v4/package.json +6 -0
  1014. package/.output/server/package.json +95 -0
  1015. package/README.md +46 -0
  1016. package/bin/cli.mjs +113 -0
  1017. package/bin/entry.cjs +84 -0
  1018. package/package.json +48 -0
@@ -0,0 +1,2484 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqlServerQueryRunner = void 0;
4
+ const error_1 = require("../../error");
5
+ const QueryFailedError_1 = require("../../error/QueryFailedError");
6
+ const QueryRunnerAlreadyReleasedError_1 = require("../../error/QueryRunnerAlreadyReleasedError");
7
+ const TransactionNotStartedError_1 = require("../../error/TransactionNotStartedError");
8
+ const BaseQueryRunner_1 = require("../../query-runner/BaseQueryRunner");
9
+ const QueryLock_1 = require("../../query-runner/QueryLock");
10
+ const QueryResult_1 = require("../../query-runner/QueryResult");
11
+ const Table_1 = require("../../schema-builder/table/Table");
12
+ const TableCheck_1 = require("../../schema-builder/table/TableCheck");
13
+ const TableColumn_1 = require("../../schema-builder/table/TableColumn");
14
+ const TableForeignKey_1 = require("../../schema-builder/table/TableForeignKey");
15
+ const TableIndex_1 = require("../../schema-builder/table/TableIndex");
16
+ const TableUnique_1 = require("../../schema-builder/table/TableUnique");
17
+ const View_1 = require("../../schema-builder/view/View");
18
+ const Broadcaster_1 = require("../../subscriber/Broadcaster");
19
+ const BroadcasterResult_1 = require("../../subscriber/BroadcasterResult");
20
+ const InstanceChecker_1 = require("../../util/InstanceChecker");
21
+ const OrmUtils_1 = require("../../util/OrmUtils");
22
+ const Query_1 = require("../Query");
23
+ const MetadataTableType_1 = require("../types/MetadataTableType");
24
+ /**
25
+ * Runs queries on a single SQL Server database connection.
26
+ */
27
+ class SqlServerQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
28
+ // -------------------------------------------------------------------------
29
+ // Constructor
30
+ // -------------------------------------------------------------------------
31
+ constructor(driver, mode) {
32
+ super();
33
+ // -------------------------------------------------------------------------
34
+ // Private Properties
35
+ // -------------------------------------------------------------------------
36
+ this.lock = new QueryLock_1.QueryLock();
37
+ this.driver = driver;
38
+ this.connection = driver.connection;
39
+ this.broadcaster = new Broadcaster_1.Broadcaster(this);
40
+ this.mode = mode;
41
+ }
42
+ // -------------------------------------------------------------------------
43
+ // Public Methods
44
+ // -------------------------------------------------------------------------
45
+ /**
46
+ * Creates/uses database connection from the connection pool to perform further operations.
47
+ * Returns obtained database connection.
48
+ */
49
+ connect() {
50
+ return Promise.resolve();
51
+ }
52
+ /**
53
+ * Releases used database connection.
54
+ * You cannot use query runner methods once its released.
55
+ */
56
+ release() {
57
+ this.isReleased = true;
58
+ return Promise.resolve();
59
+ }
60
+ /**
61
+ * Starts transaction.
62
+ */
63
+ async startTransaction(isolationLevel) {
64
+ if (this.isReleased)
65
+ throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
66
+ this.isTransactionActive = true;
67
+ try {
68
+ await this.broadcaster.broadcast("BeforeTransactionStart");
69
+ }
70
+ catch (err) {
71
+ this.isTransactionActive = false;
72
+ throw err;
73
+ }
74
+ await new Promise(async (ok, fail) => {
75
+ const transactionCallback = (err) => {
76
+ if (err) {
77
+ this.isTransactionActive = false;
78
+ return fail(err);
79
+ }
80
+ ok();
81
+ };
82
+ if (this.transactionDepth === 0) {
83
+ const pool = await (this.mode === "slave"
84
+ ? this.driver.obtainSlaveConnection()
85
+ : this.driver.obtainMasterConnection());
86
+ this.databaseConnection = pool.transaction();
87
+ this.connection.logger.logQuery("BEGIN TRANSACTION");
88
+ if (isolationLevel) {
89
+ this.databaseConnection.begin(this.convertIsolationLevel(isolationLevel), transactionCallback);
90
+ this.connection.logger.logQuery("SET TRANSACTION ISOLATION LEVEL " + isolationLevel);
91
+ }
92
+ else {
93
+ this.databaseConnection.begin(transactionCallback);
94
+ }
95
+ }
96
+ else {
97
+ await this.query(`SAVE TRANSACTION typeorm_${this.transactionDepth}`);
98
+ ok();
99
+ }
100
+ this.transactionDepth += 1;
101
+ });
102
+ await this.broadcaster.broadcast("AfterTransactionStart");
103
+ }
104
+ /**
105
+ * Commits transaction.
106
+ * Error will be thrown if transaction was not started.
107
+ */
108
+ async commitTransaction() {
109
+ if (this.isReleased)
110
+ throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
111
+ if (!this.isTransactionActive)
112
+ throw new TransactionNotStartedError_1.TransactionNotStartedError();
113
+ await this.broadcaster.broadcast("BeforeTransactionCommit");
114
+ if (this.transactionDepth === 1) {
115
+ return new Promise((ok, fail) => {
116
+ this.databaseConnection.commit(async (err) => {
117
+ if (err)
118
+ return fail(err);
119
+ this.isTransactionActive = false;
120
+ this.databaseConnection = null;
121
+ await this.broadcaster.broadcast("AfterTransactionCommit");
122
+ ok();
123
+ this.connection.logger.logQuery("COMMIT");
124
+ this.transactionDepth -= 1;
125
+ });
126
+ });
127
+ }
128
+ this.transactionDepth -= 1;
129
+ }
130
+ /**
131
+ * Rollbacks transaction.
132
+ * Error will be thrown if transaction was not started.
133
+ */
134
+ async rollbackTransaction() {
135
+ if (this.isReleased)
136
+ throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
137
+ if (!this.isTransactionActive)
138
+ throw new TransactionNotStartedError_1.TransactionNotStartedError();
139
+ await this.broadcaster.broadcast("BeforeTransactionRollback");
140
+ if (this.transactionDepth > 1) {
141
+ await this.query(`ROLLBACK TRANSACTION typeorm_${this.transactionDepth - 1}`);
142
+ this.transactionDepth -= 1;
143
+ }
144
+ else {
145
+ return new Promise((ok, fail) => {
146
+ this.databaseConnection.rollback(async (err) => {
147
+ if (err)
148
+ return fail(err);
149
+ this.isTransactionActive = false;
150
+ this.databaseConnection = null;
151
+ await this.broadcaster.broadcast("AfterTransactionRollback");
152
+ ok();
153
+ this.connection.logger.logQuery("ROLLBACK");
154
+ this.transactionDepth -= 1;
155
+ });
156
+ });
157
+ }
158
+ }
159
+ /**
160
+ * Executes a given SQL query.
161
+ */
162
+ async query(query, parameters, useStructuredResult = false) {
163
+ if (this.isReleased)
164
+ throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
165
+ const release = await this.lock.acquire();
166
+ this.driver.connection.logger.logQuery(query, parameters, this);
167
+ await this.broadcaster.broadcast("BeforeQuery", query, parameters);
168
+ const broadcasterResult = new BroadcasterResult_1.BroadcasterResult();
169
+ try {
170
+ const pool = await (this.mode === "slave"
171
+ ? this.driver.obtainSlaveConnection()
172
+ : this.driver.obtainMasterConnection());
173
+ const request = new this.driver.mssql.Request(this.isTransactionActive ? this.databaseConnection : pool);
174
+ if (parameters && parameters.length) {
175
+ parameters.forEach((parameter, index) => {
176
+ const parameterName = index.toString();
177
+ if (InstanceChecker_1.InstanceChecker.isMssqlParameter(parameter)) {
178
+ const mssqlParameter = this.mssqlParameterToNativeParameter(parameter);
179
+ if (mssqlParameter) {
180
+ request.input(parameterName, mssqlParameter, parameter.value);
181
+ }
182
+ else {
183
+ request.input(parameterName, parameter.value);
184
+ }
185
+ }
186
+ else {
187
+ request.input(parameterName, parameter);
188
+ }
189
+ });
190
+ }
191
+ const queryStartTime = Date.now();
192
+ const raw = await new Promise((ok, fail) => {
193
+ request.query(query, (err, raw) => {
194
+ // log slow queries if maxQueryExecution time is set
195
+ const maxQueryExecutionTime = this.driver.options.maxQueryExecutionTime;
196
+ const queryEndTime = Date.now();
197
+ const queryExecutionTime = queryEndTime - queryStartTime;
198
+ this.broadcaster.broadcastAfterQueryEvent(broadcasterResult, query, parameters, true, queryExecutionTime, raw, undefined);
199
+ if (maxQueryExecutionTime &&
200
+ queryExecutionTime > maxQueryExecutionTime) {
201
+ this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);
202
+ }
203
+ if (err) {
204
+ fail(new QueryFailedError_1.QueryFailedError(query, parameters, err));
205
+ }
206
+ ok(raw);
207
+ });
208
+ });
209
+ const result = new QueryResult_1.QueryResult();
210
+ if (raw?.hasOwnProperty("recordset")) {
211
+ result.records = raw.recordset;
212
+ }
213
+ if (raw?.hasOwnProperty("rowsAffected")) {
214
+ result.affected = raw.rowsAffected[0];
215
+ }
216
+ const queryType = query.slice(0, query.indexOf(" "));
217
+ switch (queryType) {
218
+ case "DELETE":
219
+ // for DELETE query additionally return number of affected rows
220
+ result.raw = [raw.recordset, raw.rowsAffected[0]];
221
+ break;
222
+ default:
223
+ result.raw = raw.recordset;
224
+ }
225
+ if (useStructuredResult) {
226
+ return result;
227
+ }
228
+ else {
229
+ return result.raw;
230
+ }
231
+ }
232
+ catch (err) {
233
+ this.driver.connection.logger.logQueryError(err, query, parameters, this);
234
+ this.broadcaster.broadcastAfterQueryEvent(broadcasterResult, query, parameters, false, undefined, undefined, err);
235
+ throw err;
236
+ }
237
+ finally {
238
+ await broadcasterResult.wait();
239
+ release();
240
+ }
241
+ }
242
+ /**
243
+ * Returns raw data stream.
244
+ */
245
+ async stream(query, parameters, onEnd, onError) {
246
+ if (this.isReleased)
247
+ throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
248
+ const release = await this.lock.acquire();
249
+ this.driver.connection.logger.logQuery(query, parameters, this);
250
+ const pool = await (this.mode === "slave"
251
+ ? this.driver.obtainSlaveConnection()
252
+ : this.driver.obtainMasterConnection());
253
+ const request = new this.driver.mssql.Request(this.isTransactionActive ? this.databaseConnection : pool);
254
+ if (parameters && parameters.length) {
255
+ parameters.forEach((parameter, index) => {
256
+ const parameterName = index.toString();
257
+ if (InstanceChecker_1.InstanceChecker.isMssqlParameter(parameter)) {
258
+ request.input(parameterName, this.mssqlParameterToNativeParameter(parameter), parameter.value);
259
+ }
260
+ else {
261
+ request.input(parameterName, parameter);
262
+ }
263
+ });
264
+ }
265
+ request.query(query);
266
+ const streamRequest = request.toReadableStream();
267
+ streamRequest.on("error", (err) => {
268
+ release();
269
+ this.driver.connection.logger.logQueryError(err, query, parameters, this);
270
+ });
271
+ streamRequest.on("end", () => {
272
+ release();
273
+ });
274
+ if (onEnd) {
275
+ streamRequest.on("end", onEnd);
276
+ }
277
+ if (onError) {
278
+ streamRequest.on("error", onError);
279
+ }
280
+ return streamRequest;
281
+ }
282
+ /**
283
+ * Returns all available database names including system databases.
284
+ */
285
+ async getDatabases() {
286
+ const results = await this.query(`EXEC sp_databases`);
287
+ return results.map((result) => result["DATABASE_NAME"]);
288
+ }
289
+ /**
290
+ * Returns all available schema names including system schemas.
291
+ * If database parameter specified, returns schemas of that database.
292
+ */
293
+ async getSchemas(database) {
294
+ const query = database
295
+ ? `SELECT * FROM "${database}"."sys"."schema"`
296
+ : `SELECT * FROM "sys"."schemas"`;
297
+ const results = await this.query(query);
298
+ return results.map((result) => result["name"]);
299
+ }
300
+ /**
301
+ * Checks if database with the given name exist.
302
+ */
303
+ async hasDatabase(database) {
304
+ const result = await this.query(`SELECT DB_ID('${database}') as "db_id"`);
305
+ const dbId = result[0]["db_id"];
306
+ return !!dbId;
307
+ }
308
+ /**
309
+ * Loads currently using database
310
+ */
311
+ async getCurrentDatabase() {
312
+ const currentDBQuery = await this.query(`SELECT DB_NAME() AS "db_name"`);
313
+ return currentDBQuery[0]["db_name"];
314
+ }
315
+ /**
316
+ * Checks if schema with the given name exist.
317
+ */
318
+ async hasSchema(schema) {
319
+ const result = await this.query(`SELECT SCHEMA_ID('${schema}') as "schema_id"`);
320
+ const schemaId = result[0]["schema_id"];
321
+ return !!schemaId;
322
+ }
323
+ /**
324
+ * Loads currently using database schema
325
+ */
326
+ async getCurrentSchema() {
327
+ const currentSchemaQuery = await this.query(`SELECT SCHEMA_NAME() AS "schema_name"`);
328
+ return currentSchemaQuery[0]["schema_name"];
329
+ }
330
+ /**
331
+ * Checks if table with the given name exist in the database.
332
+ */
333
+ async hasTable(tableOrName) {
334
+ const parsedTableName = this.driver.parseTableName(tableOrName);
335
+ if (!parsedTableName.database) {
336
+ parsedTableName.database = await this.getCurrentDatabase();
337
+ }
338
+ if (!parsedTableName.schema) {
339
+ parsedTableName.schema = await this.getCurrentSchema();
340
+ }
341
+ const sql = `SELECT * FROM "${parsedTableName.database}"."INFORMATION_SCHEMA"."TABLES" WHERE "TABLE_NAME" = '${parsedTableName.tableName}' AND "TABLE_SCHEMA" = '${parsedTableName.schema}'`;
342
+ const result = await this.query(sql);
343
+ return result.length ? true : false;
344
+ }
345
+ /**
346
+ * Checks if column exist in the table.
347
+ */
348
+ async hasColumn(tableOrName, columnName) {
349
+ const parsedTableName = this.driver.parseTableName(tableOrName);
350
+ if (!parsedTableName.database) {
351
+ parsedTableName.database = await this.getCurrentDatabase();
352
+ }
353
+ if (!parsedTableName.schema) {
354
+ parsedTableName.schema = await this.getCurrentSchema();
355
+ }
356
+ const sql = `SELECT * FROM "${parsedTableName.database}"."INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = '${parsedTableName.tableName}' AND "TABLE_SCHEMA" = '${parsedTableName.schema}' AND "COLUMN_NAME" = '${columnName}'`;
357
+ const result = await this.query(sql);
358
+ return result.length ? true : false;
359
+ }
360
+ /**
361
+ * Creates a new database.
362
+ */
363
+ async createDatabase(database, ifNotExist) {
364
+ const up = ifNotExist
365
+ ? `IF DB_ID('${database}') IS NULL CREATE DATABASE "${database}"`
366
+ : `CREATE DATABASE "${database}"`;
367
+ const down = `DROP DATABASE "${database}"`;
368
+ await this.executeQueries(new Query_1.Query(up), new Query_1.Query(down));
369
+ }
370
+ /**
371
+ * Drops database.
372
+ */
373
+ async dropDatabase(database, ifExist) {
374
+ const up = ifExist
375
+ ? `IF DB_ID('${database}') IS NOT NULL DROP DATABASE "${database}"`
376
+ : `DROP DATABASE "${database}"`;
377
+ const down = `CREATE DATABASE "${database}"`;
378
+ await this.executeQueries(new Query_1.Query(up), new Query_1.Query(down));
379
+ }
380
+ /**
381
+ * Creates table schema.
382
+ * If database name also specified (e.g. 'dbName.schemaName') schema will be created in specified database.
383
+ */
384
+ async createSchema(schemaPath, ifNotExist) {
385
+ const upQueries = [];
386
+ const downQueries = [];
387
+ if (schemaPath.indexOf(".") === -1) {
388
+ const upQuery = ifNotExist
389
+ ? `IF SCHEMA_ID('${schemaPath}') IS NULL BEGIN EXEC ('CREATE SCHEMA "${schemaPath}"') END`
390
+ : `CREATE SCHEMA "${schemaPath}"`;
391
+ upQueries.push(new Query_1.Query(upQuery));
392
+ downQueries.push(new Query_1.Query(`DROP SCHEMA "${schemaPath}"`));
393
+ }
394
+ else {
395
+ const dbName = schemaPath.split(".")[0];
396
+ const schema = schemaPath.split(".")[1];
397
+ const currentDB = await this.getCurrentDatabase();
398
+ upQueries.push(new Query_1.Query(`USE "${dbName}"`));
399
+ downQueries.push(new Query_1.Query(`USE "${currentDB}"`));
400
+ const upQuery = ifNotExist
401
+ ? `IF SCHEMA_ID('${schema}') IS NULL BEGIN EXEC ('CREATE SCHEMA "${schema}"') END`
402
+ : `CREATE SCHEMA "${schema}"`;
403
+ upQueries.push(new Query_1.Query(upQuery));
404
+ downQueries.push(new Query_1.Query(`DROP SCHEMA "${schema}"`));
405
+ upQueries.push(new Query_1.Query(`USE "${currentDB}"`));
406
+ downQueries.push(new Query_1.Query(`USE "${dbName}"`));
407
+ }
408
+ await this.executeQueries(upQueries, downQueries);
409
+ }
410
+ /**
411
+ * Drops table schema.
412
+ * If database name also specified (e.g. 'dbName.schemaName') schema will be dropped in specified database.
413
+ */
414
+ async dropSchema(schemaPath, ifExist) {
415
+ const upQueries = [];
416
+ const downQueries = [];
417
+ if (schemaPath.indexOf(".") === -1) {
418
+ const upQuery = ifExist
419
+ ? `IF SCHEMA_ID('${schemaPath}') IS NULL BEGIN EXEC ('DROP SCHEMA "${schemaPath}"') END`
420
+ : `DROP SCHEMA "${schemaPath}"`;
421
+ upQueries.push(new Query_1.Query(upQuery));
422
+ downQueries.push(new Query_1.Query(`CREATE SCHEMA "${schemaPath}"`));
423
+ }
424
+ else {
425
+ const dbName = schemaPath.split(".")[0];
426
+ const schema = schemaPath.split(".")[1];
427
+ const currentDB = await this.getCurrentDatabase();
428
+ upQueries.push(new Query_1.Query(`USE "${dbName}"`));
429
+ downQueries.push(new Query_1.Query(`USE "${currentDB}"`));
430
+ const upQuery = ifExist
431
+ ? `IF SCHEMA_ID('${schema}') IS NULL BEGIN EXEC ('DROP SCHEMA "${schema}"') END`
432
+ : `DROP SCHEMA "${schema}"`;
433
+ upQueries.push(new Query_1.Query(upQuery));
434
+ downQueries.push(new Query_1.Query(`CREATE SCHEMA "${schema}"`));
435
+ upQueries.push(new Query_1.Query(`USE "${currentDB}"`));
436
+ downQueries.push(new Query_1.Query(`USE "${dbName}"`));
437
+ }
438
+ await this.executeQueries(upQueries, downQueries);
439
+ }
440
+ /**
441
+ * Creates a new table.
442
+ */
443
+ async createTable(table, ifNotExist = false, createForeignKeys = true, createIndices = true) {
444
+ if (ifNotExist) {
445
+ const isTableExist = await this.hasTable(table);
446
+ if (isTableExist)
447
+ return Promise.resolve();
448
+ }
449
+ const upQueries = [];
450
+ const downQueries = [];
451
+ upQueries.push(this.createTableSql(table, createForeignKeys));
452
+ downQueries.push(this.dropTableSql(table));
453
+ // if createForeignKeys is true, we must drop created foreign keys in down query.
454
+ // createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
455
+ if (createForeignKeys)
456
+ table.foreignKeys.forEach((foreignKey) => downQueries.push(this.dropForeignKeySql(table, foreignKey)));
457
+ if (createIndices) {
458
+ table.indices.forEach((index) => {
459
+ // new index may be passed without name. In this case we generate index name manually.
460
+ if (!index.name)
461
+ index.name = this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
462
+ upQueries.push(this.createIndexSql(table, index));
463
+ downQueries.push(this.dropIndexSql(table, index));
464
+ });
465
+ }
466
+ // if table have column with generated type, we must add the expression to the metadata table
467
+ const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
468
+ for (const column of generatedColumns) {
469
+ const parsedTableName = this.driver.parseTableName(table);
470
+ if (!parsedTableName.schema) {
471
+ parsedTableName.schema = await this.getCurrentSchema();
472
+ }
473
+ const insertQuery = this.insertTypeormMetadataSql({
474
+ database: parsedTableName.database,
475
+ schema: parsedTableName.schema,
476
+ table: parsedTableName.tableName,
477
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
478
+ name: column.name,
479
+ value: column.asExpression,
480
+ });
481
+ const deleteQuery = this.deleteTypeormMetadataSql({
482
+ database: parsedTableName.database,
483
+ schema: parsedTableName.schema,
484
+ table: parsedTableName.tableName,
485
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
486
+ name: column.name,
487
+ });
488
+ upQueries.push(insertQuery);
489
+ downQueries.push(deleteQuery);
490
+ }
491
+ await this.executeQueries(upQueries, downQueries);
492
+ }
493
+ /**
494
+ * Drops the table.
495
+ */
496
+ async dropTable(tableOrName, ifExist, dropForeignKeys = true, dropIndices = true) {
497
+ if (ifExist) {
498
+ const isTableExist = await this.hasTable(tableOrName);
499
+ if (!isTableExist)
500
+ return Promise.resolve();
501
+ }
502
+ // if dropTable called with dropForeignKeys = true, we must create foreign keys in down query.
503
+ const createForeignKeys = dropForeignKeys;
504
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
505
+ ? tableOrName
506
+ : await this.getCachedTable(tableOrName);
507
+ const upQueries = [];
508
+ const downQueries = [];
509
+ // It needs because if table does not exist and dropForeignKeys or dropIndices is true, we don't need
510
+ // to perform drop queries for foreign keys and indices.
511
+ if (dropIndices) {
512
+ table.indices.forEach((index) => {
513
+ upQueries.push(this.dropIndexSql(table, index));
514
+ downQueries.push(this.createIndexSql(table, index));
515
+ });
516
+ }
517
+ // if dropForeignKeys is true, we just drop the table, otherwise we also drop table foreign keys.
518
+ // createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
519
+ if (dropForeignKeys)
520
+ table.foreignKeys.forEach((foreignKey) => upQueries.push(this.dropForeignKeySql(table, foreignKey)));
521
+ upQueries.push(this.dropTableSql(table));
522
+ downQueries.push(this.createTableSql(table, createForeignKeys));
523
+ // if table had columns with generated type, we must remove the expression from the metadata table
524
+ const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
525
+ for (const column of generatedColumns) {
526
+ const parsedTableName = this.driver.parseTableName(table);
527
+ if (!parsedTableName.schema) {
528
+ parsedTableName.schema = await this.getCurrentSchema();
529
+ }
530
+ const deleteQuery = this.deleteTypeormMetadataSql({
531
+ database: parsedTableName.database,
532
+ schema: parsedTableName.schema,
533
+ table: parsedTableName.tableName,
534
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
535
+ name: column.name,
536
+ });
537
+ const insertQuery = this.insertTypeormMetadataSql({
538
+ database: parsedTableName.database,
539
+ schema: parsedTableName.schema,
540
+ table: parsedTableName.tableName,
541
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
542
+ name: column.name,
543
+ value: column.asExpression,
544
+ });
545
+ upQueries.push(deleteQuery);
546
+ downQueries.push(insertQuery);
547
+ }
548
+ await this.executeQueries(upQueries, downQueries);
549
+ }
550
+ /**
551
+ * Creates a new view.
552
+ */
553
+ async createView(view, syncWithMetadata = false) {
554
+ const upQueries = [];
555
+ const downQueries = [];
556
+ upQueries.push(this.createViewSql(view));
557
+ if (syncWithMetadata)
558
+ upQueries.push(await this.insertViewDefinitionSql(view));
559
+ downQueries.push(this.dropViewSql(view));
560
+ if (syncWithMetadata)
561
+ downQueries.push(await this.deleteViewDefinitionSql(view));
562
+ await this.executeQueries(upQueries, downQueries);
563
+ }
564
+ /**
565
+ * Drops the view.
566
+ */
567
+ async dropView(target) {
568
+ const viewName = InstanceChecker_1.InstanceChecker.isView(target) ? target.name : target;
569
+ const view = await this.getCachedView(viewName);
570
+ const upQueries = [];
571
+ const downQueries = [];
572
+ upQueries.push(await this.deleteViewDefinitionSql(view));
573
+ upQueries.push(this.dropViewSql(view));
574
+ downQueries.push(await this.insertViewDefinitionSql(view));
575
+ downQueries.push(this.createViewSql(view));
576
+ await this.executeQueries(upQueries, downQueries);
577
+ }
578
+ /**
579
+ * Renames a table.
580
+ */
581
+ async renameTable(oldTableOrName, newTableName) {
582
+ const upQueries = [];
583
+ const downQueries = [];
584
+ const oldTable = InstanceChecker_1.InstanceChecker.isTable(oldTableOrName)
585
+ ? oldTableOrName
586
+ : await this.getCachedTable(oldTableOrName);
587
+ const newTable = oldTable.clone();
588
+ // we need database name and schema name to rename FK constraints
589
+ let dbName = undefined;
590
+ let schemaName = undefined;
591
+ let oldTableName = oldTable.name;
592
+ const splittedName = oldTable.name.split(".");
593
+ if (splittedName.length === 3) {
594
+ dbName = splittedName[0];
595
+ oldTableName = splittedName[2];
596
+ if (splittedName[1] !== "")
597
+ schemaName = splittedName[1];
598
+ }
599
+ else if (splittedName.length === 2) {
600
+ schemaName = splittedName[0];
601
+ oldTableName = splittedName[1];
602
+ }
603
+ newTable.name = this.driver.buildTableName(newTableName, schemaName, dbName);
604
+ // if we have tables with database which differs from database specified in config, we must change currently used database.
605
+ // This need because we can not rename objects from another database.
606
+ const currentDB = await this.getCurrentDatabase();
607
+ if (dbName && dbName !== currentDB) {
608
+ upQueries.push(new Query_1.Query(`USE "${dbName}"`));
609
+ downQueries.push(new Query_1.Query(`USE "${currentDB}"`));
610
+ }
611
+ // rename table
612
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(oldTable)}", "${newTableName}"`));
613
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}", "${oldTableName}"`));
614
+ // rename primary key constraint
615
+ if (newTable.primaryColumns.length > 0 &&
616
+ !newTable.primaryColumns[0].primaryKeyConstraintName) {
617
+ const columnNames = newTable.primaryColumns.map((column) => column.name);
618
+ const oldPkName = this.connection.namingStrategy.primaryKeyName(oldTable, columnNames);
619
+ const newPkName = this.connection.namingStrategy.primaryKeyName(newTable, columnNames);
620
+ // rename primary constraint
621
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${oldPkName}", "${newPkName}"`));
622
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${newPkName}", "${oldPkName}"`));
623
+ }
624
+ // rename unique constraints
625
+ newTable.uniques.forEach((unique) => {
626
+ const oldUniqueName = this.connection.namingStrategy.uniqueConstraintName(oldTable, unique.columnNames);
627
+ // Skip renaming if Unique has user defined constraint name
628
+ if (unique.name !== oldUniqueName)
629
+ return;
630
+ // build new constraint name
631
+ const newUniqueName = this.connection.namingStrategy.uniqueConstraintName(newTable, unique.columnNames);
632
+ // build queries
633
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${unique.name}", "${newUniqueName}"`));
634
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${newUniqueName}", "${unique.name}"`));
635
+ // replace constraint name
636
+ unique.name = newUniqueName;
637
+ });
638
+ // rename index constraints
639
+ newTable.indices.forEach((index) => {
640
+ const oldIndexName = this.connection.namingStrategy.indexName(oldTable, index.columnNames, index.where);
641
+ // Skip renaming if Index has user defined constraint name
642
+ if (index.name !== oldIndexName)
643
+ return;
644
+ // build new constraint name
645
+ const newIndexName = this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
646
+ // build queries
647
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${index.name}", "${newIndexName}", "INDEX"`));
648
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(newTable)}.${newIndexName}", "${index.name}", "INDEX"`));
649
+ // replace constraint name
650
+ index.name = newIndexName;
651
+ });
652
+ // rename foreign key constraints
653
+ newTable.foreignKeys.forEach((foreignKey) => {
654
+ const oldForeignKeyName = this.connection.namingStrategy.foreignKeyName(oldTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
655
+ // Skip renaming if foreign key has user defined constraint name
656
+ if (foreignKey.name !== oldForeignKeyName)
657
+ return;
658
+ // build new constraint name
659
+ const newForeignKeyName = this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
660
+ // build queries
661
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.buildForeignKeyName(foreignKey.name, schemaName, dbName)}", "${newForeignKeyName}"`));
662
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.buildForeignKeyName(newForeignKeyName, schemaName, dbName)}", "${foreignKey.name}"`));
663
+ // replace constraint name
664
+ foreignKey.name = newForeignKeyName;
665
+ });
666
+ // change currently used database back to default db.
667
+ if (dbName && dbName !== currentDB) {
668
+ upQueries.push(new Query_1.Query(`USE "${currentDB}"`));
669
+ downQueries.push(new Query_1.Query(`USE "${dbName}"`));
670
+ }
671
+ await this.executeQueries(upQueries, downQueries);
672
+ // rename old table and replace it in cached tabled;
673
+ oldTable.name = newTable.name;
674
+ this.replaceCachedTable(oldTable, newTable);
675
+ }
676
+ /**
677
+ * Creates a new column from the column in the table.
678
+ */
679
+ async addColumn(tableOrName, column) {
680
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
681
+ ? tableOrName
682
+ : await this.getCachedTable(tableOrName);
683
+ const clonedTable = table.clone();
684
+ const upQueries = [];
685
+ const downQueries = [];
686
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD ${this.buildCreateColumnSql(table, column, false, true)}`));
687
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP COLUMN "${column.name}"`));
688
+ // create or update primary key constraint
689
+ if (column.isPrimary) {
690
+ const primaryColumns = clonedTable.primaryColumns;
691
+ // if table already have primary key, me must drop it and recreate again
692
+ if (primaryColumns.length > 0) {
693
+ const pkName = primaryColumns[0].primaryKeyConstraintName
694
+ ? primaryColumns[0].primaryKeyConstraintName
695
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
696
+ const columnNames = primaryColumns
697
+ .map((column) => `"${column.name}"`)
698
+ .join(", ");
699
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
700
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
701
+ }
702
+ primaryColumns.push(column);
703
+ const pkName = primaryColumns[0].primaryKeyConstraintName
704
+ ? primaryColumns[0].primaryKeyConstraintName
705
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
706
+ const columnNames = primaryColumns
707
+ .map((column) => `"${column.name}"`)
708
+ .join(", ");
709
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
710
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
711
+ }
712
+ // create column index
713
+ const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
714
+ index.columnNames[0] === column.name);
715
+ if (columnIndex) {
716
+ upQueries.push(this.createIndexSql(table, columnIndex));
717
+ downQueries.push(this.dropIndexSql(table, columnIndex));
718
+ }
719
+ // create unique constraint
720
+ if (column.isUnique) {
721
+ const uniqueConstraint = new TableUnique_1.TableUnique({
722
+ name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
723
+ columnNames: [column.name],
724
+ });
725
+ clonedTable.uniques.push(uniqueConstraint);
726
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${column.name}")`));
727
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
728
+ }
729
+ // remove default constraint
730
+ if (column.default !== null && column.default !== undefined) {
731
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, column.name);
732
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${defaultName}"`));
733
+ }
734
+ if (column.generatedType && column.asExpression) {
735
+ const parsedTableName = this.driver.parseTableName(table);
736
+ if (!parsedTableName.schema) {
737
+ parsedTableName.schema = await this.getCurrentSchema();
738
+ }
739
+ const insertQuery = this.insertTypeormMetadataSql({
740
+ database: parsedTableName.database,
741
+ schema: parsedTableName.schema,
742
+ table: parsedTableName.tableName,
743
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
744
+ name: column.name,
745
+ value: column.asExpression,
746
+ });
747
+ const deleteQuery = this.deleteTypeormMetadataSql({
748
+ database: parsedTableName.database,
749
+ schema: parsedTableName.schema,
750
+ table: parsedTableName.tableName,
751
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
752
+ name: column.name,
753
+ });
754
+ upQueries.push(insertQuery);
755
+ downQueries.push(deleteQuery);
756
+ }
757
+ await this.executeQueries(upQueries, downQueries);
758
+ clonedTable.addColumn(column);
759
+ this.replaceCachedTable(table, clonedTable);
760
+ }
761
+ /**
762
+ * Creates a new columns from the column in the table.
763
+ */
764
+ async addColumns(tableOrName, columns) {
765
+ for (const column of columns) {
766
+ await this.addColumn(tableOrName, column);
767
+ }
768
+ }
769
+ /**
770
+ * Renames column in the given table.
771
+ */
772
+ async renameColumn(tableOrName, oldTableColumnOrName, newTableColumnOrName) {
773
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
774
+ ? tableOrName
775
+ : await this.getCachedTable(tableOrName);
776
+ const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
777
+ ? oldTableColumnOrName
778
+ : table.columns.find((c) => c.name === oldTableColumnOrName);
779
+ if (!oldColumn)
780
+ throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
781
+ let newColumn = undefined;
782
+ if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
783
+ newColumn = newTableColumnOrName;
784
+ }
785
+ else {
786
+ newColumn = oldColumn.clone();
787
+ newColumn.name = newTableColumnOrName;
788
+ }
789
+ await this.changeColumn(table, oldColumn, newColumn);
790
+ }
791
+ /**
792
+ * Changes a column in the table.
793
+ */
794
+ async changeColumn(tableOrName, oldTableColumnOrName, newColumn) {
795
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
796
+ ? tableOrName
797
+ : await this.getCachedTable(tableOrName);
798
+ let clonedTable = table.clone();
799
+ const upQueries = [];
800
+ const downQueries = [];
801
+ const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
802
+ ? oldTableColumnOrName
803
+ : table.columns.find((column) => column.name === oldTableColumnOrName);
804
+ if (!oldColumn)
805
+ throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
806
+ if ((newColumn.isGenerated !== oldColumn.isGenerated &&
807
+ newColumn.generationStrategy !== "uuid") ||
808
+ newColumn.type !== oldColumn.type ||
809
+ newColumn.length !== oldColumn.length ||
810
+ newColumn.asExpression !== oldColumn.asExpression ||
811
+ newColumn.generatedType !== oldColumn.generatedType) {
812
+ // SQL Server does not support changing of IDENTITY column, so we must drop column and recreate it again.
813
+ // Also, we recreate column if column type changed
814
+ await this.dropColumn(table, oldColumn);
815
+ await this.addColumn(table, newColumn);
816
+ // update cloned table
817
+ clonedTable = table.clone();
818
+ }
819
+ else {
820
+ if (newColumn.name !== oldColumn.name) {
821
+ // we need database name and schema name to rename FK constraints
822
+ let dbName = undefined;
823
+ let schemaName = undefined;
824
+ const splittedName = table.name.split(".");
825
+ if (splittedName.length === 3) {
826
+ dbName = splittedName[0];
827
+ if (splittedName[1] !== "")
828
+ schemaName = splittedName[1];
829
+ }
830
+ else if (splittedName.length === 2) {
831
+ schemaName = splittedName[0];
832
+ }
833
+ // if we have tables with database which differs from database specified in config, we must change currently used database.
834
+ // This need because we can not rename objects from another database.
835
+ const currentDB = await this.getCurrentDatabase();
836
+ if (dbName && dbName !== currentDB) {
837
+ upQueries.push(new Query_1.Query(`USE "${dbName}"`));
838
+ downQueries.push(new Query_1.Query(`USE "${currentDB}"`));
839
+ }
840
+ // rename the column
841
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(table)}.${oldColumn.name}", "${newColumn.name}"`));
842
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(table)}.${newColumn.name}", "${oldColumn.name}"`));
843
+ // rename column primary key constraint
844
+ if (oldColumn.isPrimary === true &&
845
+ !oldColumn.primaryKeyConstraintName) {
846
+ const primaryColumns = clonedTable.primaryColumns;
847
+ // build old primary constraint name
848
+ const columnNames = primaryColumns.map((column) => column.name);
849
+ const oldPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
850
+ // replace old column name with new column name
851
+ columnNames.splice(columnNames.indexOf(oldColumn.name), 1);
852
+ columnNames.push(newColumn.name);
853
+ // build new primary constraint name
854
+ const newPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
855
+ // rename primary constraint
856
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${oldPkName}", "${newPkName}"`));
857
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${newPkName}", "${oldPkName}"`));
858
+ }
859
+ // rename index constraints
860
+ clonedTable.findColumnIndices(oldColumn).forEach((index) => {
861
+ const oldIndexName = this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
862
+ // Skip renaming if Index has user defined constraint name
863
+ if (index.name !== oldIndexName)
864
+ return;
865
+ // build new constraint name
866
+ index.columnNames.splice(index.columnNames.indexOf(oldColumn.name), 1);
867
+ index.columnNames.push(newColumn.name);
868
+ const newIndexName = this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
869
+ // build queries
870
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${index.name}", "${newIndexName}", "INDEX"`));
871
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${newIndexName}", "${index.name}", "INDEX"`));
872
+ // replace constraint name
873
+ index.name = newIndexName;
874
+ });
875
+ // rename foreign key constraints
876
+ clonedTable
877
+ .findColumnForeignKeys(oldColumn)
878
+ .forEach((foreignKey) => {
879
+ const foreignKeyName = this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
880
+ // Skip renaming if foreign key has user defined constraint name
881
+ if (foreignKey.name !== foreignKeyName)
882
+ return;
883
+ // build new constraint name
884
+ foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(oldColumn.name), 1);
885
+ foreignKey.columnNames.push(newColumn.name);
886
+ const newForeignKeyName = this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
887
+ // build queries
888
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.buildForeignKeyName(foreignKey.name, schemaName, dbName)}", "${newForeignKeyName}"`));
889
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.buildForeignKeyName(newForeignKeyName, schemaName, dbName)}", "${foreignKey.name}"`));
890
+ // replace constraint name
891
+ foreignKey.name = newForeignKeyName;
892
+ });
893
+ // rename check constraints
894
+ clonedTable.findColumnChecks(oldColumn).forEach((check) => {
895
+ // build new constraint name
896
+ check.columnNames.splice(check.columnNames.indexOf(oldColumn.name), 1);
897
+ check.columnNames.push(newColumn.name);
898
+ const newCheckName = this.connection.namingStrategy.checkConstraintName(clonedTable, check.expression);
899
+ // build queries
900
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${check.name}", "${newCheckName}"`));
901
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${newCheckName}", "${check.name}"`));
902
+ // replace constraint name
903
+ check.name = newCheckName;
904
+ });
905
+ // rename unique constraints
906
+ clonedTable.findColumnUniques(oldColumn).forEach((unique) => {
907
+ const oldUniqueName = this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
908
+ // Skip renaming if Unique has user defined constraint name
909
+ if (unique.name !== oldUniqueName)
910
+ return;
911
+ // build new constraint name
912
+ unique.columnNames.splice(unique.columnNames.indexOf(oldColumn.name), 1);
913
+ unique.columnNames.push(newColumn.name);
914
+ const newUniqueName = this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
915
+ // build queries
916
+ upQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${unique.name}", "${newUniqueName}"`));
917
+ downQueries.push(new Query_1.Query(`EXEC sp_rename "${this.getTablePath(clonedTable)}.${newUniqueName}", "${unique.name}"`));
918
+ // replace constraint name
919
+ unique.name = newUniqueName;
920
+ });
921
+ // rename default constraints
922
+ if (oldColumn.default !== null &&
923
+ oldColumn.default !== undefined) {
924
+ const oldDefaultName = this.connection.namingStrategy.defaultConstraintName(table, oldColumn.name);
925
+ const newDefaultName = this.connection.namingStrategy.defaultConstraintName(table, newColumn.name);
926
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${oldDefaultName}"`));
927
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${oldDefaultName}" DEFAULT ${oldColumn.default} FOR "${newColumn.name}"`));
928
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${newDefaultName}" DEFAULT ${oldColumn.default} FOR "${newColumn.name}"`));
929
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${newDefaultName}"`));
930
+ }
931
+ // change currently used database back to default db.
932
+ if (dbName && dbName !== currentDB) {
933
+ upQueries.push(new Query_1.Query(`USE "${currentDB}"`));
934
+ downQueries.push(new Query_1.Query(`USE "${dbName}"`));
935
+ }
936
+ // rename old column in the Table object
937
+ const oldTableColumn = clonedTable.columns.find((column) => column.name === oldColumn.name);
938
+ clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
939
+ oldColumn.name = newColumn.name;
940
+ }
941
+ if (this.isColumnChanged(oldColumn, newColumn, false, false, false)) {
942
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER COLUMN ${this.buildCreateColumnSql(table, newColumn, true, false, true)}`));
943
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER COLUMN ${this.buildCreateColumnSql(table, oldColumn, true, false, true)}`));
944
+ }
945
+ if (this.isEnumChanged(oldColumn, newColumn)) {
946
+ const oldExpression = this.getEnumExpression(oldColumn);
947
+ const oldCheck = new TableCheck_1.TableCheck({
948
+ name: this.connection.namingStrategy.checkConstraintName(table, oldExpression, true),
949
+ expression: oldExpression,
950
+ });
951
+ const newExpression = this.getEnumExpression(newColumn);
952
+ const newCheck = new TableCheck_1.TableCheck({
953
+ name: this.connection.namingStrategy.checkConstraintName(table, newExpression, true),
954
+ expression: newExpression,
955
+ });
956
+ upQueries.push(this.dropCheckConstraintSql(table, oldCheck));
957
+ upQueries.push(this.createCheckConstraintSql(table, newCheck));
958
+ downQueries.push(this.dropCheckConstraintSql(table, newCheck));
959
+ downQueries.push(this.createCheckConstraintSql(table, oldCheck));
960
+ }
961
+ if (newColumn.isPrimary !== oldColumn.isPrimary) {
962
+ const primaryColumns = clonedTable.primaryColumns;
963
+ // if primary column state changed, we must always drop existed constraint.
964
+ if (primaryColumns.length > 0) {
965
+ const pkName = primaryColumns[0].primaryKeyConstraintName
966
+ ? primaryColumns[0].primaryKeyConstraintName
967
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
968
+ const columnNames = primaryColumns
969
+ .map((column) => `"${column.name}"`)
970
+ .join(", ");
971
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
972
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
973
+ }
974
+ if (newColumn.isPrimary === true) {
975
+ primaryColumns.push(newColumn);
976
+ // update column in table
977
+ const column = clonedTable.columns.find((column) => column.name === newColumn.name);
978
+ column.isPrimary = true;
979
+ const pkName = primaryColumns[0].primaryKeyConstraintName
980
+ ? primaryColumns[0].primaryKeyConstraintName
981
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
982
+ const columnNames = primaryColumns
983
+ .map((column) => `"${column.name}"`)
984
+ .join(", ");
985
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
986
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
987
+ }
988
+ else {
989
+ const primaryColumn = primaryColumns.find((c) => c.name === newColumn.name);
990
+ primaryColumns.splice(primaryColumns.indexOf(primaryColumn), 1);
991
+ // update column in table
992
+ const column = clonedTable.columns.find((column) => column.name === newColumn.name);
993
+ column.isPrimary = false;
994
+ // if we have another primary keys, we must recreate constraint.
995
+ if (primaryColumns.length > 0) {
996
+ const pkName = primaryColumns[0]
997
+ .primaryKeyConstraintName
998
+ ? primaryColumns[0].primaryKeyConstraintName
999
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
1000
+ const columnNames = primaryColumns
1001
+ .map((column) => `"${column.name}"`)
1002
+ .join(", ");
1003
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
1004
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
1005
+ }
1006
+ }
1007
+ }
1008
+ if (newColumn.isUnique !== oldColumn.isUnique) {
1009
+ if (newColumn.isUnique === true) {
1010
+ const uniqueConstraint = new TableUnique_1.TableUnique({
1011
+ name: this.connection.namingStrategy.uniqueConstraintName(table, [newColumn.name]),
1012
+ columnNames: [newColumn.name],
1013
+ });
1014
+ clonedTable.uniques.push(uniqueConstraint);
1015
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${newColumn.name}")`));
1016
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
1017
+ }
1018
+ else {
1019
+ const uniqueConstraint = clonedTable.uniques.find((unique) => {
1020
+ return (unique.columnNames.length === 1 &&
1021
+ !!unique.columnNames.find((columnName) => columnName === newColumn.name));
1022
+ });
1023
+ clonedTable.uniques.splice(clonedTable.uniques.indexOf(uniqueConstraint), 1);
1024
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
1025
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${newColumn.name}")`));
1026
+ }
1027
+ }
1028
+ if (newColumn.default !== oldColumn.default) {
1029
+ // (note) if there is a previous default, we need to drop its constraint first
1030
+ if (oldColumn.default !== null &&
1031
+ oldColumn.default !== undefined) {
1032
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, oldColumn.name);
1033
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${defaultName}"`));
1034
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${defaultName}" DEFAULT ${oldColumn.default} FOR "${oldColumn.name}"`));
1035
+ }
1036
+ if (newColumn.default !== null &&
1037
+ newColumn.default !== undefined) {
1038
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, newColumn.name);
1039
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${defaultName}" DEFAULT ${newColumn.default} FOR "${newColumn.name}"`));
1040
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${defaultName}"`));
1041
+ }
1042
+ }
1043
+ await this.executeQueries(upQueries, downQueries);
1044
+ this.replaceCachedTable(table, clonedTable);
1045
+ }
1046
+ }
1047
+ /**
1048
+ * Changes a column in the table.
1049
+ */
1050
+ async changeColumns(tableOrName, changedColumns) {
1051
+ for (const { oldColumn, newColumn } of changedColumns) {
1052
+ await this.changeColumn(tableOrName, oldColumn, newColumn);
1053
+ }
1054
+ }
1055
+ /**
1056
+ * Drops column in the table.
1057
+ */
1058
+ async dropColumn(tableOrName, columnOrName) {
1059
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1060
+ ? tableOrName
1061
+ : await this.getCachedTable(tableOrName);
1062
+ const column = InstanceChecker_1.InstanceChecker.isTableColumn(columnOrName)
1063
+ ? columnOrName
1064
+ : table.findColumnByName(columnOrName);
1065
+ if (!column)
1066
+ throw new error_1.TypeORMError(`Column "${columnOrName}" was not found in table "${table.name}"`);
1067
+ const clonedTable = table.clone();
1068
+ const upQueries = [];
1069
+ const downQueries = [];
1070
+ // drop primary key constraint
1071
+ if (column.isPrimary) {
1072
+ const pkName = column.primaryKeyConstraintName
1073
+ ? column.primaryKeyConstraintName
1074
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
1075
+ const columnNames = clonedTable.primaryColumns
1076
+ .map((primaryColumn) => `"${primaryColumn.name}"`)
1077
+ .join(", ");
1078
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
1079
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
1080
+ // update column in table
1081
+ const tableColumn = clonedTable.findColumnByName(column.name);
1082
+ tableColumn.isPrimary = false;
1083
+ // if primary key have multiple columns, we must recreate it without dropped column
1084
+ if (clonedTable.primaryColumns.length > 0) {
1085
+ const pkName = clonedTable.primaryColumns[0]
1086
+ .primaryKeyConstraintName
1087
+ ? clonedTable.primaryColumns[0].primaryKeyConstraintName
1088
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
1089
+ const columnNames = clonedTable.primaryColumns
1090
+ .map((primaryColumn) => `"${primaryColumn.name}"`)
1091
+ .join(", ");
1092
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
1093
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
1094
+ }
1095
+ }
1096
+ // drop column index
1097
+ const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
1098
+ index.columnNames[0] === column.name);
1099
+ if (columnIndex) {
1100
+ clonedTable.indices.splice(clonedTable.indices.indexOf(columnIndex), 1);
1101
+ upQueries.push(this.dropIndexSql(table, columnIndex));
1102
+ downQueries.push(this.createIndexSql(table, columnIndex));
1103
+ }
1104
+ // drop column check
1105
+ const columnCheck = clonedTable.checks.find((check) => !!check.columnNames &&
1106
+ check.columnNames.length === 1 &&
1107
+ check.columnNames[0] === column.name);
1108
+ if (columnCheck) {
1109
+ clonedTable.checks.splice(clonedTable.checks.indexOf(columnCheck), 1);
1110
+ upQueries.push(this.dropCheckConstraintSql(table, columnCheck));
1111
+ downQueries.push(this.createCheckConstraintSql(table, columnCheck));
1112
+ }
1113
+ // drop column unique
1114
+ const columnUnique = clonedTable.uniques.find((unique) => unique.columnNames.length === 1 &&
1115
+ unique.columnNames[0] === column.name);
1116
+ if (columnUnique) {
1117
+ clonedTable.uniques.splice(clonedTable.uniques.indexOf(columnUnique), 1);
1118
+ upQueries.push(this.dropUniqueConstraintSql(table, columnUnique));
1119
+ downQueries.push(this.createUniqueConstraintSql(table, columnUnique));
1120
+ }
1121
+ // drop default constraint
1122
+ if (column.default !== null && column.default !== undefined) {
1123
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, column.name);
1124
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${defaultName}"`));
1125
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${defaultName}" DEFAULT ${column.default} FOR "${column.name}"`));
1126
+ }
1127
+ if (column.generatedType && column.asExpression) {
1128
+ const parsedTableName = this.driver.parseTableName(table);
1129
+ if (!parsedTableName.schema) {
1130
+ parsedTableName.schema = await this.getCurrentSchema();
1131
+ }
1132
+ const deleteQuery = this.deleteTypeormMetadataSql({
1133
+ database: parsedTableName.database,
1134
+ schema: parsedTableName.schema,
1135
+ table: parsedTableName.tableName,
1136
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
1137
+ name: column.name,
1138
+ });
1139
+ const insertQuery = this.insertTypeormMetadataSql({
1140
+ database: parsedTableName.database,
1141
+ schema: parsedTableName.schema,
1142
+ table: parsedTableName.tableName,
1143
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
1144
+ name: column.name,
1145
+ value: column.asExpression,
1146
+ });
1147
+ upQueries.push(deleteQuery);
1148
+ downQueries.push(insertQuery);
1149
+ }
1150
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP COLUMN "${column.name}"`));
1151
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD ${this.buildCreateColumnSql(table, column, false, false)}`));
1152
+ await this.executeQueries(upQueries, downQueries);
1153
+ clonedTable.removeColumn(column);
1154
+ this.replaceCachedTable(table, clonedTable);
1155
+ }
1156
+ /**
1157
+ * Drops the columns in the table.
1158
+ */
1159
+ async dropColumns(tableOrName, columns) {
1160
+ for (const column of columns) {
1161
+ await this.dropColumn(tableOrName, column);
1162
+ }
1163
+ }
1164
+ /**
1165
+ * Creates a new primary key.
1166
+ */
1167
+ async createPrimaryKey(tableOrName, columnNames, constraintName) {
1168
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1169
+ ? tableOrName
1170
+ : await this.getCachedTable(tableOrName);
1171
+ const clonedTable = table.clone();
1172
+ const up = this.createPrimaryKeySql(table, columnNames, constraintName);
1173
+ // mark columns as primary, because dropPrimaryKeySql build constraint name from table primary column names.
1174
+ clonedTable.columns.forEach((column) => {
1175
+ if (columnNames.find((columnName) => columnName === column.name))
1176
+ column.isPrimary = true;
1177
+ });
1178
+ const down = this.dropPrimaryKeySql(clonedTable);
1179
+ await this.executeQueries(up, down);
1180
+ this.replaceCachedTable(table, clonedTable);
1181
+ }
1182
+ /**
1183
+ * Updates composite primary keys.
1184
+ */
1185
+ async updatePrimaryKeys(tableOrName, columns) {
1186
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1187
+ ? tableOrName
1188
+ : await this.getCachedTable(tableOrName);
1189
+ const clonedTable = table.clone();
1190
+ const columnNames = columns.map((column) => column.name);
1191
+ const upQueries = [];
1192
+ const downQueries = [];
1193
+ // if table already have primary columns, we must drop them.
1194
+ const primaryColumns = clonedTable.primaryColumns;
1195
+ if (primaryColumns.length > 0) {
1196
+ const pkName = primaryColumns[0].primaryKeyConstraintName
1197
+ ? primaryColumns[0].primaryKeyConstraintName
1198
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
1199
+ const columnNamesString = primaryColumns
1200
+ .map((column) => `"${column.name}"`)
1201
+ .join(", ");
1202
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
1203
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
1204
+ }
1205
+ // update columns in table.
1206
+ clonedTable.columns
1207
+ .filter((column) => columnNames.indexOf(column.name) !== -1)
1208
+ .forEach((column) => (column.isPrimary = true));
1209
+ const pkName = primaryColumns[0].primaryKeyConstraintName
1210
+ ? primaryColumns[0].primaryKeyConstraintName
1211
+ : this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
1212
+ const columnNamesString = columnNames
1213
+ .map((columnName) => `"${columnName}"`)
1214
+ .join(", ");
1215
+ upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
1216
+ downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
1217
+ await this.executeQueries(upQueries, downQueries);
1218
+ this.replaceCachedTable(table, clonedTable);
1219
+ }
1220
+ /**
1221
+ * Drops a primary key.
1222
+ */
1223
+ async dropPrimaryKey(tableOrName, constraintName) {
1224
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1225
+ ? tableOrName
1226
+ : await this.getCachedTable(tableOrName);
1227
+ const up = this.dropPrimaryKeySql(table);
1228
+ const down = this.createPrimaryKeySql(table, table.primaryColumns.map((column) => column.name), constraintName);
1229
+ await this.executeQueries(up, down);
1230
+ table.primaryColumns.forEach((column) => {
1231
+ column.isPrimary = false;
1232
+ });
1233
+ }
1234
+ /**
1235
+ * Creates a new unique constraint.
1236
+ */
1237
+ async createUniqueConstraint(tableOrName, uniqueConstraint) {
1238
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1239
+ ? tableOrName
1240
+ : await this.getCachedTable(tableOrName);
1241
+ // new unique constraint may be passed without name. In this case we generate unique name manually.
1242
+ if (!uniqueConstraint.name)
1243
+ uniqueConstraint.name =
1244
+ this.connection.namingStrategy.uniqueConstraintName(table, uniqueConstraint.columnNames);
1245
+ const up = this.createUniqueConstraintSql(table, uniqueConstraint);
1246
+ const down = this.dropUniqueConstraintSql(table, uniqueConstraint);
1247
+ await this.executeQueries(up, down);
1248
+ table.addUniqueConstraint(uniqueConstraint);
1249
+ }
1250
+ /**
1251
+ * Creates a new unique constraints.
1252
+ */
1253
+ async createUniqueConstraints(tableOrName, uniqueConstraints) {
1254
+ const promises = uniqueConstraints.map((uniqueConstraint) => this.createUniqueConstraint(tableOrName, uniqueConstraint));
1255
+ await Promise.all(promises);
1256
+ }
1257
+ /**
1258
+ * Drops unique constraint.
1259
+ */
1260
+ async dropUniqueConstraint(tableOrName, uniqueOrName) {
1261
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1262
+ ? tableOrName
1263
+ : await this.getCachedTable(tableOrName);
1264
+ const uniqueConstraint = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
1265
+ ? uniqueOrName
1266
+ : table.uniques.find((u) => u.name === uniqueOrName);
1267
+ if (!uniqueConstraint)
1268
+ throw new error_1.TypeORMError(`Supplied unique constraint was not found in table ${table.name}`);
1269
+ const up = this.dropUniqueConstraintSql(table, uniqueConstraint);
1270
+ const down = this.createUniqueConstraintSql(table, uniqueConstraint);
1271
+ await this.executeQueries(up, down);
1272
+ table.removeUniqueConstraint(uniqueConstraint);
1273
+ }
1274
+ /**
1275
+ * Drops an unique constraints.
1276
+ */
1277
+ async dropUniqueConstraints(tableOrName, uniqueConstraints) {
1278
+ const promises = uniqueConstraints.map((uniqueConstraint) => this.dropUniqueConstraint(tableOrName, uniqueConstraint));
1279
+ await Promise.all(promises);
1280
+ }
1281
+ /**
1282
+ * Creates a new check constraint.
1283
+ */
1284
+ async createCheckConstraint(tableOrName, checkConstraint) {
1285
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1286
+ ? tableOrName
1287
+ : await this.getCachedTable(tableOrName);
1288
+ // new unique constraint may be passed without name. In this case we generate unique name manually.
1289
+ if (!checkConstraint.name)
1290
+ checkConstraint.name =
1291
+ this.connection.namingStrategy.checkConstraintName(table, checkConstraint.expression);
1292
+ const up = this.createCheckConstraintSql(table, checkConstraint);
1293
+ const down = this.dropCheckConstraintSql(table, checkConstraint);
1294
+ await this.executeQueries(up, down);
1295
+ table.addCheckConstraint(checkConstraint);
1296
+ }
1297
+ /**
1298
+ * Creates a new check constraints.
1299
+ */
1300
+ async createCheckConstraints(tableOrName, checkConstraints) {
1301
+ const promises = checkConstraints.map((checkConstraint) => this.createCheckConstraint(tableOrName, checkConstraint));
1302
+ await Promise.all(promises);
1303
+ }
1304
+ /**
1305
+ * Drops check constraint.
1306
+ */
1307
+ async dropCheckConstraint(tableOrName, checkOrName) {
1308
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1309
+ ? tableOrName
1310
+ : await this.getCachedTable(tableOrName);
1311
+ const checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
1312
+ ? checkOrName
1313
+ : table.checks.find((c) => c.name === checkOrName);
1314
+ if (!checkConstraint)
1315
+ throw new error_1.TypeORMError(`Supplied check constraint was not found in table ${table.name}`);
1316
+ const up = this.dropCheckConstraintSql(table, checkConstraint);
1317
+ const down = this.createCheckConstraintSql(table, checkConstraint);
1318
+ await this.executeQueries(up, down);
1319
+ table.removeCheckConstraint(checkConstraint);
1320
+ }
1321
+ /**
1322
+ * Drops check constraints.
1323
+ */
1324
+ async dropCheckConstraints(tableOrName, checkConstraints) {
1325
+ const promises = checkConstraints.map((checkConstraint) => this.dropCheckConstraint(tableOrName, checkConstraint));
1326
+ await Promise.all(promises);
1327
+ }
1328
+ /**
1329
+ * Creates a new exclusion constraint.
1330
+ */
1331
+ async createExclusionConstraint(tableOrName, exclusionConstraint) {
1332
+ throw new error_1.TypeORMError(`SqlServer does not support exclusion constraints.`);
1333
+ }
1334
+ /**
1335
+ * Creates a new exclusion constraints.
1336
+ */
1337
+ async createExclusionConstraints(tableOrName, exclusionConstraints) {
1338
+ throw new error_1.TypeORMError(`SqlServer does not support exclusion constraints.`);
1339
+ }
1340
+ /**
1341
+ * Drops exclusion constraint.
1342
+ */
1343
+ async dropExclusionConstraint(tableOrName, exclusionOrName) {
1344
+ throw new error_1.TypeORMError(`SqlServer does not support exclusion constraints.`);
1345
+ }
1346
+ /**
1347
+ * Drops exclusion constraints.
1348
+ */
1349
+ async dropExclusionConstraints(tableOrName, exclusionConstraints) {
1350
+ throw new error_1.TypeORMError(`SqlServer does not support exclusion constraints.`);
1351
+ }
1352
+ /**
1353
+ * Creates a new foreign key.
1354
+ */
1355
+ async createForeignKey(tableOrName, foreignKey) {
1356
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1357
+ ? tableOrName
1358
+ : await this.getCachedTable(tableOrName);
1359
+ const metadata = this.connection.hasMetadata(table.name)
1360
+ ? this.connection.getMetadata(table.name)
1361
+ : undefined;
1362
+ if (metadata &&
1363
+ metadata.treeParentRelation &&
1364
+ metadata.treeParentRelation.isTreeParent &&
1365
+ metadata.foreignKeys.find((foreignKey) => foreignKey.onDelete !== "NO ACTION"))
1366
+ throw new error_1.TypeORMError("SqlServer does not support options in TreeParent.");
1367
+ // new FK may be passed without name. In this case we generate FK name manually.
1368
+ if (!foreignKey.name)
1369
+ foreignKey.name = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
1370
+ const up = this.createForeignKeySql(table, foreignKey);
1371
+ const down = this.dropForeignKeySql(table, foreignKey);
1372
+ await this.executeQueries(up, down);
1373
+ table.addForeignKey(foreignKey);
1374
+ }
1375
+ /**
1376
+ * Creates a new foreign keys.
1377
+ */
1378
+ async createForeignKeys(tableOrName, foreignKeys) {
1379
+ const promises = foreignKeys.map((foreignKey) => this.createForeignKey(tableOrName, foreignKey));
1380
+ await Promise.all(promises);
1381
+ }
1382
+ /**
1383
+ * Drops a foreign key from the table.
1384
+ */
1385
+ async dropForeignKey(tableOrName, foreignKeyOrName) {
1386
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1387
+ ? tableOrName
1388
+ : await this.getCachedTable(tableOrName);
1389
+ const foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
1390
+ ? foreignKeyOrName
1391
+ : table.foreignKeys.find((fk) => fk.name === foreignKeyOrName);
1392
+ if (!foreignKey)
1393
+ throw new error_1.TypeORMError(`Supplied foreign key was not found in table ${table.name}`);
1394
+ const up = this.dropForeignKeySql(table, foreignKey);
1395
+ const down = this.createForeignKeySql(table, foreignKey);
1396
+ await this.executeQueries(up, down);
1397
+ table.removeForeignKey(foreignKey);
1398
+ }
1399
+ /**
1400
+ * Drops a foreign keys from the table.
1401
+ */
1402
+ async dropForeignKeys(tableOrName, foreignKeys) {
1403
+ const promises = foreignKeys.map((foreignKey) => this.dropForeignKey(tableOrName, foreignKey));
1404
+ await Promise.all(promises);
1405
+ }
1406
+ /**
1407
+ * Creates a new index.
1408
+ */
1409
+ async createIndex(tableOrName, index) {
1410
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1411
+ ? tableOrName
1412
+ : await this.getCachedTable(tableOrName);
1413
+ // new index may be passed without name. In this case we generate index name manually.
1414
+ if (!index.name)
1415
+ index.name = this.generateIndexName(table, index);
1416
+ const up = this.createIndexSql(table, index);
1417
+ const down = this.dropIndexSql(table, index);
1418
+ await this.executeQueries(up, down);
1419
+ table.addIndex(index);
1420
+ }
1421
+ /**
1422
+ * Creates a new indices
1423
+ */
1424
+ async createIndices(tableOrName, indices) {
1425
+ const promises = indices.map((index) => this.createIndex(tableOrName, index));
1426
+ await Promise.all(promises);
1427
+ }
1428
+ /**
1429
+ * Drops an index.
1430
+ */
1431
+ async dropIndex(tableOrName, indexOrName) {
1432
+ const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
1433
+ ? tableOrName
1434
+ : await this.getCachedTable(tableOrName);
1435
+ const index = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
1436
+ ? indexOrName
1437
+ : table.indices.find((i) => i.name === indexOrName);
1438
+ if (!index)
1439
+ throw new error_1.TypeORMError(`Supplied index was not found in table ${table.name}`);
1440
+ // old index may be passed without name. In this case we generate index name manually.
1441
+ if (!index.name)
1442
+ index.name = this.generateIndexName(table, index);
1443
+ const up = this.dropIndexSql(table, index);
1444
+ const down = this.createIndexSql(table, index);
1445
+ await this.executeQueries(up, down);
1446
+ table.removeIndex(index);
1447
+ }
1448
+ /**
1449
+ * Drops an indices from the table.
1450
+ */
1451
+ async dropIndices(tableOrName, indices) {
1452
+ const promises = indices.map((index) => this.dropIndex(tableOrName, index));
1453
+ await Promise.all(promises);
1454
+ }
1455
+ /**
1456
+ * Clears all table contents.
1457
+ * Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.
1458
+ */
1459
+ async clearTable(tablePath) {
1460
+ await this.query(`TRUNCATE TABLE ${this.escapePath(tablePath)}`);
1461
+ }
1462
+ /**
1463
+ * Removes all tables from the currently connected database.
1464
+ */
1465
+ async clearDatabase(database) {
1466
+ if (database) {
1467
+ const isDatabaseExist = await this.hasDatabase(database);
1468
+ if (!isDatabaseExist)
1469
+ return Promise.resolve();
1470
+ }
1471
+ const isAnotherTransactionActive = this.isTransactionActive;
1472
+ if (!isAnotherTransactionActive)
1473
+ await this.startTransaction();
1474
+ try {
1475
+ const allViewsSql = database
1476
+ ? `SELECT * FROM "${database}"."INFORMATION_SCHEMA"."VIEWS"`
1477
+ : `SELECT * FROM "INFORMATION_SCHEMA"."VIEWS"`;
1478
+ const allViewsResults = await this.query(allViewsSql);
1479
+ await Promise.all(allViewsResults.map((viewResult) => {
1480
+ // 'DROP VIEW' does not allow specifying the database name as a prefix to the object name.
1481
+ const dropTableSql = `DROP VIEW "${viewResult["TABLE_SCHEMA"]}"."${viewResult["TABLE_NAME"]}"`;
1482
+ return this.query(dropTableSql);
1483
+ }));
1484
+ const allTablesSql = database
1485
+ ? `SELECT * FROM "${database}"."INFORMATION_SCHEMA"."TABLES" WHERE "TABLE_TYPE" = 'BASE TABLE'`
1486
+ : `SELECT * FROM "INFORMATION_SCHEMA"."TABLES" WHERE "TABLE_TYPE" = 'BASE TABLE'`;
1487
+ const allTablesResults = await this.query(allTablesSql);
1488
+ if (allTablesResults.length > 0) {
1489
+ const tablesByCatalog = allTablesResults.reduce((c, { TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME }) => {
1490
+ c[TABLE_CATALOG] = c[TABLE_CATALOG] || [];
1491
+ c[TABLE_CATALOG].push({ TABLE_SCHEMA, TABLE_NAME });
1492
+ return c;
1493
+ }, {});
1494
+ const foreignKeysSql = Object.entries(tablesByCatalog)
1495
+ .map(([TABLE_CATALOG, tables]) => {
1496
+ const conditions = tables
1497
+ .map(({ TABLE_SCHEMA, TABLE_NAME }) => {
1498
+ return `("fk"."referenced_object_id" = OBJECT_ID('"${TABLE_CATALOG}"."${TABLE_SCHEMA}"."${TABLE_NAME}"'))`;
1499
+ })
1500
+ .join(" OR ");
1501
+ return `
1502
+ SELECT DISTINCT '${TABLE_CATALOG}' AS "TABLE_CATALOG",
1503
+ OBJECT_SCHEMA_NAME("fk"."parent_object_id",
1504
+ DB_ID('${TABLE_CATALOG}')) AS "TABLE_SCHEMA",
1505
+ OBJECT_NAME("fk"."parent_object_id", DB_ID('${TABLE_CATALOG}')) AS "TABLE_NAME",
1506
+ "fk"."name" AS "CONSTRAINT_NAME"
1507
+ FROM "${TABLE_CATALOG}"."sys"."foreign_keys" AS "fk"
1508
+ WHERE (${conditions})
1509
+ `;
1510
+ })
1511
+ .join(" UNION ALL ");
1512
+ const foreignKeys = await this.query(foreignKeysSql);
1513
+ await Promise.all(foreignKeys.map(async ({ TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME, }) => {
1514
+ // Disable the constraint first.
1515
+ await this.query(`ALTER TABLE "${TABLE_CATALOG}"."${TABLE_SCHEMA}"."${TABLE_NAME}" ` +
1516
+ `NOCHECK CONSTRAINT "${CONSTRAINT_NAME}"`);
1517
+ await this.query(`ALTER TABLE "${TABLE_CATALOG}"."${TABLE_SCHEMA}"."${TABLE_NAME}" ` +
1518
+ `DROP CONSTRAINT "${CONSTRAINT_NAME}" -- FROM CLEAR`);
1519
+ }));
1520
+ await Promise.all(allTablesResults.map((tablesResult) => {
1521
+ if (tablesResult["TABLE_NAME"].startsWith("#")) {
1522
+ // don't try to drop temporary tables
1523
+ return;
1524
+ }
1525
+ const dropTableSql = `DROP TABLE "${tablesResult["TABLE_CATALOG"]}"."${tablesResult["TABLE_SCHEMA"]}"."${tablesResult["TABLE_NAME"]}"`;
1526
+ return this.query(dropTableSql);
1527
+ }));
1528
+ }
1529
+ if (!isAnotherTransactionActive)
1530
+ await this.commitTransaction();
1531
+ }
1532
+ catch (error) {
1533
+ try {
1534
+ // we throw original error even if rollback thrown an error
1535
+ if (!isAnotherTransactionActive)
1536
+ await this.rollbackTransaction();
1537
+ }
1538
+ catch (rollbackError) { }
1539
+ throw error;
1540
+ }
1541
+ }
1542
+ // -------------------------------------------------------------------------
1543
+ // Protected Methods
1544
+ // -------------------------------------------------------------------------
1545
+ async loadViews(viewPaths) {
1546
+ const hasTable = await this.hasTable(this.getTypeormMetadataTableName());
1547
+ if (!hasTable) {
1548
+ return [];
1549
+ }
1550
+ if (!viewPaths) {
1551
+ viewPaths = [];
1552
+ }
1553
+ const currentSchema = await this.getCurrentSchema();
1554
+ const currentDatabase = await this.getCurrentDatabase();
1555
+ const dbNames = viewPaths
1556
+ .map((viewPath) => this.driver.parseTableName(viewPath).database)
1557
+ .filter((database) => database);
1558
+ if (this.driver.database &&
1559
+ !dbNames.find((dbName) => dbName === this.driver.database))
1560
+ dbNames.push(this.driver.database);
1561
+ const viewsCondition = viewPaths
1562
+ .map((viewPath) => {
1563
+ let { schema, tableName: name } = this.driver.parseTableName(viewPath);
1564
+ if (!schema) {
1565
+ schema = currentSchema;
1566
+ }
1567
+ return `("T"."SCHEMA" = '${schema}' AND "T"."NAME" = '${name}')`;
1568
+ })
1569
+ .join(" OR ");
1570
+ const query = dbNames
1571
+ .map((dbName) => {
1572
+ return (`SELECT "T".*, "V"."CHECK_OPTION" FROM ${this.escapePath(this.getTypeormMetadataTableName())} "t" ` +
1573
+ `INNER JOIN "${dbName}"."INFORMATION_SCHEMA"."VIEWS" "V" ON "V"."TABLE_SCHEMA" = "T"."SCHEMA" AND "v"."TABLE_NAME" = "T"."NAME" WHERE "T"."TYPE" = '${MetadataTableType_1.MetadataTableType.VIEW}' ${viewsCondition ? `AND (${viewsCondition})` : ""}`);
1574
+ })
1575
+ .join(" UNION ALL ");
1576
+ const dbViews = await this.query(query);
1577
+ return dbViews.map((dbView) => {
1578
+ const view = new View_1.View();
1579
+ const db = dbView["TABLE_CATALOG"] === currentDatabase
1580
+ ? undefined
1581
+ : dbView["TABLE_CATALOG"];
1582
+ const schema = dbView["schema"] === currentSchema &&
1583
+ !this.driver.options.schema
1584
+ ? undefined
1585
+ : dbView["schema"];
1586
+ view.database = dbView["TABLE_CATALOG"];
1587
+ view.schema = dbView["schema"];
1588
+ view.name = this.driver.buildTableName(dbView["name"], schema, db);
1589
+ view.expression = dbView["value"];
1590
+ return view;
1591
+ });
1592
+ }
1593
+ /**
1594
+ * Loads all tables (with given names) from the database and creates a Table from them.
1595
+ */
1596
+ async loadTables(tableNames) {
1597
+ // if no tables given then no need to proceed
1598
+ if (tableNames && tableNames.length === 0) {
1599
+ return [];
1600
+ }
1601
+ const currentSchema = await this.getCurrentSchema();
1602
+ const currentDatabase = await this.getCurrentDatabase();
1603
+ const dbTables = [];
1604
+ if (!tableNames) {
1605
+ const databasesSql = `SELECT DISTINCT "name" ` +
1606
+ `FROM "master"."dbo"."sysdatabases" ` +
1607
+ `WHERE "name" NOT IN ('master', 'model', 'msdb')`;
1608
+ const dbDatabases = await this.query(databasesSql);
1609
+ const tablesSql = dbDatabases
1610
+ .map(({ name }) => {
1611
+ return `
1612
+ SELECT DISTINCT
1613
+ "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"
1614
+ FROM "${name}"."INFORMATION_SCHEMA"."TABLES"
1615
+ WHERE
1616
+ "TABLE_TYPE" = 'BASE TABLE'
1617
+ AND
1618
+ "TABLE_CATALOG" = '${name}'
1619
+ AND
1620
+ ISNULL(Objectproperty(Object_id("TABLE_CATALOG" + '.' + "TABLE_SCHEMA" + '.' + "TABLE_NAME"), 'IsMSShipped'), 0) = 0
1621
+ `;
1622
+ })
1623
+ .join(" UNION ALL ");
1624
+ dbTables.push(...(await this.query(tablesSql)));
1625
+ }
1626
+ else {
1627
+ const tableNamesByCatalog = tableNames
1628
+ .map((tableName) => this.driver.parseTableName(tableName))
1629
+ .reduce((c, { database, ...other }) => {
1630
+ database = database || currentDatabase;
1631
+ c[database] = c[database] || [];
1632
+ c[database].push({
1633
+ schema: other.schema || currentSchema,
1634
+ tableName: other.tableName,
1635
+ });
1636
+ return c;
1637
+ }, {});
1638
+ const tablesSql = Object.entries(tableNamesByCatalog)
1639
+ .map(([database, tables]) => {
1640
+ const tablesCondition = tables
1641
+ .map(({ schema, tableName }) => {
1642
+ return `("TABLE_SCHEMA" = '${schema}' AND "TABLE_NAME" = '${tableName}')`;
1643
+ })
1644
+ .join(" OR ");
1645
+ return `
1646
+ SELECT DISTINCT
1647
+ "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"
1648
+ FROM "${database}"."INFORMATION_SCHEMA"."TABLES"
1649
+ WHERE
1650
+ "TABLE_TYPE" = 'BASE TABLE' AND
1651
+ "TABLE_CATALOG" = '${database}' AND
1652
+ ${tablesCondition}
1653
+ `;
1654
+ })
1655
+ .join(" UNION ALL ");
1656
+ dbTables.push(...(await this.query(tablesSql)));
1657
+ }
1658
+ // if tables were not found in the db, no need to proceed
1659
+ if (dbTables.length === 0) {
1660
+ return [];
1661
+ }
1662
+ const dbTablesByCatalog = dbTables.reduce((c, { TABLE_CATALOG, ...other }) => {
1663
+ c[TABLE_CATALOG] = c[TABLE_CATALOG] || [];
1664
+ c[TABLE_CATALOG].push(other);
1665
+ return c;
1666
+ }, {});
1667
+ const columnsSql = Object.entries(dbTablesByCatalog)
1668
+ .map(([TABLE_CATALOG, tables]) => {
1669
+ const condition = tables
1670
+ .map(({ TABLE_SCHEMA, TABLE_NAME }) => `("TABLE_SCHEMA" = '${TABLE_SCHEMA}' AND "TABLE_NAME" = '${TABLE_NAME}')`)
1671
+ .join("OR");
1672
+ return (`SELECT "COLUMNS".*, "cc"."is_persisted", "cc"."definition" ` +
1673
+ `FROM "${TABLE_CATALOG}"."INFORMATION_SCHEMA"."COLUMNS" ` +
1674
+ `LEFT JOIN "sys"."computed_columns" "cc" ON COL_NAME("cc"."object_id", "cc"."column_id") = "column_name" ` +
1675
+ `WHERE (${condition})`);
1676
+ })
1677
+ .join(" UNION ALL ");
1678
+ const constraintsSql = Object.entries(dbTablesByCatalog)
1679
+ .map(([TABLE_CATALOG, tables]) => {
1680
+ const conditions = tables
1681
+ .map(({ TABLE_NAME, TABLE_SCHEMA }) => `("columnUsages"."TABLE_SCHEMA" = '${TABLE_SCHEMA}' AND "columnUsages"."TABLE_NAME" = '${TABLE_NAME}')`)
1682
+ .join(" OR ");
1683
+ return (`SELECT "columnUsages".*, "tableConstraints"."CONSTRAINT_TYPE", "chk"."definition" ` +
1684
+ `FROM "${TABLE_CATALOG}"."INFORMATION_SCHEMA"."CONSTRAINT_COLUMN_USAGE" "columnUsages" ` +
1685
+ `INNER JOIN "${TABLE_CATALOG}"."INFORMATION_SCHEMA"."TABLE_CONSTRAINTS" "tableConstraints" ` +
1686
+ `ON ` +
1687
+ `"tableConstraints"."CONSTRAINT_NAME" = "columnUsages"."CONSTRAINT_NAME" AND ` +
1688
+ `"tableConstraints"."TABLE_SCHEMA" = "columnUsages"."TABLE_SCHEMA" AND ` +
1689
+ `"tableConstraints"."TABLE_NAME" = "columnUsages"."TABLE_NAME" ` +
1690
+ `LEFT JOIN "${TABLE_CATALOG}"."sys"."check_constraints" "chk" ` +
1691
+ `ON ` +
1692
+ `"chk"."object_id" = OBJECT_ID("columnUsages"."TABLE_CATALOG" + '.' + "columnUsages"."TABLE_SCHEMA" + '.' + "columnUsages"."CONSTRAINT_NAME") ` +
1693
+ `WHERE ` +
1694
+ `(${conditions}) AND ` +
1695
+ `"tableConstraints"."CONSTRAINT_TYPE" IN ('PRIMARY KEY', 'UNIQUE', 'CHECK')`);
1696
+ })
1697
+ .join(" UNION ALL ");
1698
+ const foreignKeysSql = Object.entries(dbTablesByCatalog)
1699
+ .map(([TABLE_CATALOG, tables]) => {
1700
+ const conditions = tables
1701
+ .map(({ TABLE_NAME, TABLE_SCHEMA }) => `("s1"."name" = '${TABLE_SCHEMA}' AND "t1"."name" = '${TABLE_NAME}')`)
1702
+ .join(" OR ");
1703
+ return (`SELECT "fk"."name" AS "FK_NAME", '${TABLE_CATALOG}' AS "TABLE_CATALOG", "s1"."name" AS "TABLE_SCHEMA", "t1"."name" AS "TABLE_NAME", ` +
1704
+ `"col1"."name" AS "COLUMN_NAME", "s2"."name" AS "REF_SCHEMA", "t2"."name" AS "REF_TABLE", "col2"."name" AS "REF_COLUMN", ` +
1705
+ `"fk"."delete_referential_action_desc" AS "ON_DELETE", "fk"."update_referential_action_desc" AS "ON_UPDATE" ` +
1706
+ `FROM "${TABLE_CATALOG}"."sys"."foreign_keys" "fk" ` +
1707
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."foreign_key_columns" "fkc" ON "fkc"."constraint_object_id" = "fk"."object_id" ` +
1708
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."tables" "t1" ON "t1"."object_id" = "fk"."parent_object_id" ` +
1709
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."schemas" "s1" ON "s1"."schema_id" = "t1"."schema_id" ` +
1710
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."tables" "t2" ON "t2"."object_id" = "fk"."referenced_object_id" ` +
1711
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."schemas" "s2" ON "s2"."schema_id" = "t2"."schema_id" ` +
1712
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."columns" "col1" ON "col1"."column_id" = "fkc"."parent_column_id" AND "col1"."object_id" = "fk"."parent_object_id" ` +
1713
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."columns" "col2" ON "col2"."column_id" = "fkc"."referenced_column_id" AND "col2"."object_id" = "fk"."referenced_object_id" ` +
1714
+ `WHERE (${conditions})`);
1715
+ })
1716
+ .join(" UNION ALL ");
1717
+ const identityColumnsSql = Object.entries(dbTablesByCatalog)
1718
+ .map(([TABLE_CATALOG, tables]) => {
1719
+ const conditions = tables
1720
+ .map(({ TABLE_NAME, TABLE_SCHEMA }) => `("TABLE_SCHEMA" = '${TABLE_SCHEMA}' AND "TABLE_NAME" = '${TABLE_NAME}')`)
1721
+ .join(" OR ");
1722
+ return (`SELECT "TABLE_CATALOG", "TABLE_SCHEMA", "COLUMN_NAME", "TABLE_NAME" ` +
1723
+ `FROM "${TABLE_CATALOG}"."INFORMATION_SCHEMA"."COLUMNS" ` +
1724
+ `WHERE ` +
1725
+ `EXISTS(SELECT 1 FROM "${TABLE_CATALOG}"."sys"."columns" "S" WHERE OBJECT_ID("TABLE_CATALOG" + '.' + "TABLE_SCHEMA" + '.' + "TABLE_NAME") = "S"."OBJECT_ID" AND "COLUMN_NAME" = "S"."NAME" AND "S"."is_identity" = 1) AND ` +
1726
+ `(${conditions})`);
1727
+ })
1728
+ .join(" UNION ALL ");
1729
+ const dbCollationsSql = `SELECT "NAME", "COLLATION_NAME" FROM "sys"."databases"`;
1730
+ const indicesSql = Object.entries(dbTablesByCatalog)
1731
+ .map(([TABLE_CATALOG, tables]) => {
1732
+ const conditions = tables
1733
+ .map(({ TABLE_NAME, TABLE_SCHEMA }) => `("s"."name" = '${TABLE_SCHEMA}' AND "t"."name" = '${TABLE_NAME}')`)
1734
+ .join(" OR ");
1735
+ return (`SELECT '${TABLE_CATALOG}' AS "TABLE_CATALOG", "s"."name" AS "TABLE_SCHEMA", "t"."name" AS "TABLE_NAME", ` +
1736
+ `"ind"."name" AS "INDEX_NAME", "col"."name" AS "COLUMN_NAME", "ind"."is_unique" AS "IS_UNIQUE", "ind"."filter_definition" as "CONDITION" ` +
1737
+ `FROM "${TABLE_CATALOG}"."sys"."indexes" "ind" ` +
1738
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."index_columns" "ic" ON "ic"."object_id" = "ind"."object_id" AND "ic"."index_id" = "ind"."index_id" ` +
1739
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."columns" "col" ON "col"."object_id" = "ic"."object_id" AND "col"."column_id" = "ic"."column_id" ` +
1740
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."tables" "t" ON "t"."object_id" = "ind"."object_id" ` +
1741
+ `INNER JOIN "${TABLE_CATALOG}"."sys"."schemas" "s" ON "s"."schema_id" = "t"."schema_id" ` +
1742
+ `WHERE ` +
1743
+ `"ind"."is_primary_key" = 0 AND "ind"."is_unique_constraint" = 0 AND "t"."is_ms_shipped" = 0 AND ` +
1744
+ `(${conditions})`);
1745
+ })
1746
+ .join(" UNION ALL ");
1747
+ const [dbColumns, dbConstraints, dbForeignKeys, dbIdentityColumns, dbCollations, dbIndices,] = await Promise.all([
1748
+ this.query(columnsSql),
1749
+ this.query(constraintsSql),
1750
+ this.query(foreignKeysSql),
1751
+ this.query(identityColumnsSql),
1752
+ this.query(dbCollationsSql),
1753
+ this.query(indicesSql),
1754
+ ]);
1755
+ // create table schemas for loaded tables
1756
+ return await Promise.all(dbTables.map(async (dbTable) => {
1757
+ const table = new Table_1.Table();
1758
+ const getSchemaFromKey = (dbObject, key) => {
1759
+ return dbObject[key] === currentSchema &&
1760
+ (!this.driver.options.schema ||
1761
+ this.driver.options.schema === currentSchema)
1762
+ ? undefined
1763
+ : dbObject[key];
1764
+ };
1765
+ // We do not need to join schema and database names, when db or schema is by default.
1766
+ const db = dbTable["TABLE_CATALOG"] === currentDatabase
1767
+ ? undefined
1768
+ : dbTable["TABLE_CATALOG"];
1769
+ const schema = getSchemaFromKey(dbTable, "TABLE_SCHEMA");
1770
+ table.database = dbTable["TABLE_CATALOG"];
1771
+ table.schema = dbTable["TABLE_SCHEMA"];
1772
+ table.name = this.driver.buildTableName(dbTable["TABLE_NAME"], schema, db);
1773
+ const defaultCollation = dbCollations.find((dbCollation) => dbCollation["NAME"] === dbTable["TABLE_CATALOG"]);
1774
+ // create columns from the loaded columns
1775
+ table.columns = await Promise.all(dbColumns
1776
+ .filter((dbColumn) => dbColumn["TABLE_NAME"] ===
1777
+ dbTable["TABLE_NAME"] &&
1778
+ dbColumn["TABLE_SCHEMA"] ===
1779
+ dbTable["TABLE_SCHEMA"] &&
1780
+ dbColumn["TABLE_CATALOG"] ===
1781
+ dbTable["TABLE_CATALOG"])
1782
+ .map(async (dbColumn) => {
1783
+ const columnConstraints = dbConstraints.filter((dbConstraint) => dbConstraint["TABLE_NAME"] ===
1784
+ dbColumn["TABLE_NAME"] &&
1785
+ dbConstraint["TABLE_SCHEMA"] ===
1786
+ dbColumn["TABLE_SCHEMA"] &&
1787
+ dbConstraint["TABLE_CATALOG"] ===
1788
+ dbColumn["TABLE_CATALOG"] &&
1789
+ dbConstraint["COLUMN_NAME"] ===
1790
+ dbColumn["COLUMN_NAME"]);
1791
+ const uniqueConstraints = columnConstraints.filter((constraint) => constraint["CONSTRAINT_TYPE"] === "UNIQUE");
1792
+ const isConstraintComposite = uniqueConstraints.every((uniqueConstraint) => {
1793
+ return dbConstraints.some((dbConstraint) => dbConstraint["CONSTRAINT_TYPE"] ===
1794
+ "UNIQUE" &&
1795
+ dbConstraint["CONSTRAINT_NAME"] ===
1796
+ uniqueConstraint["CONSTRAINT_NAME"] &&
1797
+ dbConstraint["TABLE_SCHEMA"] ===
1798
+ dbColumn["TABLE_SCHEMA"] &&
1799
+ dbConstraint["TABLE_CATALOG"] ===
1800
+ dbColumn["TABLE_CATALOG"] &&
1801
+ dbConstraint["COLUMN_NAME"] !==
1802
+ dbColumn["COLUMN_NAME"]);
1803
+ });
1804
+ const isGenerated = !!dbIdentityColumns.find((column) => column["TABLE_NAME"] ===
1805
+ dbColumn["TABLE_NAME"] &&
1806
+ column["TABLE_SCHEMA"] ===
1807
+ dbColumn["TABLE_SCHEMA"] &&
1808
+ column["TABLE_CATALOG"] ===
1809
+ dbColumn["TABLE_CATALOG"] &&
1810
+ column["COLUMN_NAME"] ===
1811
+ dbColumn["COLUMN_NAME"]);
1812
+ const tableColumn = new TableColumn_1.TableColumn();
1813
+ tableColumn.name = dbColumn["COLUMN_NAME"];
1814
+ tableColumn.type =
1815
+ dbColumn["DATA_TYPE"].toLowerCase();
1816
+ // check only columns that have length property
1817
+ if (this.driver.withLengthColumnTypes.indexOf(tableColumn.type) !== -1 &&
1818
+ dbColumn["CHARACTER_MAXIMUM_LENGTH"]) {
1819
+ const length = dbColumn["CHARACTER_MAXIMUM_LENGTH"].toString();
1820
+ if (length === "-1") {
1821
+ tableColumn.length = "MAX";
1822
+ }
1823
+ else {
1824
+ tableColumn.length =
1825
+ !this.isDefaultColumnLength(table, tableColumn, length)
1826
+ ? length
1827
+ : "";
1828
+ }
1829
+ }
1830
+ if (tableColumn.type === "decimal" ||
1831
+ tableColumn.type === "numeric") {
1832
+ if (dbColumn["NUMERIC_PRECISION"] !== null &&
1833
+ !this.isDefaultColumnPrecision(table, tableColumn, dbColumn["NUMERIC_PRECISION"]))
1834
+ tableColumn.precision =
1835
+ dbColumn["NUMERIC_PRECISION"];
1836
+ if (dbColumn["NUMERIC_SCALE"] !== null &&
1837
+ !this.isDefaultColumnScale(table, tableColumn, dbColumn["NUMERIC_SCALE"]))
1838
+ tableColumn.scale =
1839
+ dbColumn["NUMERIC_SCALE"];
1840
+ }
1841
+ if (tableColumn.type === "nvarchar") {
1842
+ // Check if this is an enum
1843
+ const columnCheckConstraints = columnConstraints.filter((constraint) => constraint["CONSTRAINT_TYPE"] ===
1844
+ "CHECK");
1845
+ if (columnCheckConstraints.length) {
1846
+ // const isEnumRegexp = new RegExp("^\\(\\[" + tableColumn.name + "\\]='[^']+'(?: OR \\[" + tableColumn.name + "\\]='[^']+')*\\)$");
1847
+ for (const checkConstraint of columnCheckConstraints) {
1848
+ if (this.isEnumCheckConstraint(checkConstraint["CONSTRAINT_NAME"])) {
1849
+ // This is an enum constraint, make column into an enum
1850
+ tableColumn.enum = [];
1851
+ const enumValueRegexp = new RegExp("\\[" +
1852
+ tableColumn.name +
1853
+ "\\]='([^']+)'", "g");
1854
+ let result;
1855
+ while ((result = enumValueRegexp.exec(checkConstraint["definition"])) !== null) {
1856
+ tableColumn.enum.unshift(result[1]);
1857
+ }
1858
+ // Skip other column constraints
1859
+ break;
1860
+ }
1861
+ }
1862
+ }
1863
+ }
1864
+ const primaryConstraint = columnConstraints.find((constraint) => constraint["CONSTRAINT_TYPE"] ===
1865
+ "PRIMARY KEY");
1866
+ if (primaryConstraint) {
1867
+ tableColumn.isPrimary = true;
1868
+ // find another columns involved in primary key constraint
1869
+ const anotherPrimaryConstraints = dbConstraints.filter((constraint) => constraint["TABLE_NAME"] ===
1870
+ dbColumn["TABLE_NAME"] &&
1871
+ constraint["TABLE_SCHEMA"] ===
1872
+ dbColumn["TABLE_SCHEMA"] &&
1873
+ constraint["TABLE_CATALOG"] ===
1874
+ dbColumn["TABLE_CATALOG"] &&
1875
+ constraint["COLUMN_NAME"] !==
1876
+ dbColumn["COLUMN_NAME"] &&
1877
+ constraint["CONSTRAINT_TYPE"] ===
1878
+ "PRIMARY KEY");
1879
+ // collect all column names
1880
+ const columnNames = anotherPrimaryConstraints.map((constraint) => constraint["COLUMN_NAME"]);
1881
+ columnNames.push(dbColumn["COLUMN_NAME"]);
1882
+ // build default primary key constraint name
1883
+ const pkName = this.connection.namingStrategy.primaryKeyName(table, columnNames);
1884
+ // if primary key has user-defined constraint name, write it in table column
1885
+ if (primaryConstraint["CONSTRAINT_NAME"] !==
1886
+ pkName) {
1887
+ tableColumn.primaryKeyConstraintName =
1888
+ primaryConstraint["CONSTRAINT_NAME"];
1889
+ }
1890
+ }
1891
+ tableColumn.default =
1892
+ dbColumn["COLUMN_DEFAULT"] !== null &&
1893
+ dbColumn["COLUMN_DEFAULT"] !== undefined
1894
+ ? this.removeParenthesisFromDefault(dbColumn["COLUMN_DEFAULT"])
1895
+ : undefined;
1896
+ tableColumn.isNullable =
1897
+ dbColumn["IS_NULLABLE"] === "YES";
1898
+ tableColumn.isUnique =
1899
+ uniqueConstraints.length > 0 &&
1900
+ !isConstraintComposite;
1901
+ tableColumn.isGenerated = isGenerated;
1902
+ if (isGenerated)
1903
+ tableColumn.generationStrategy = "increment";
1904
+ if (tableColumn.default === "newsequentialid()") {
1905
+ tableColumn.isGenerated = true;
1906
+ tableColumn.generationStrategy = "uuid";
1907
+ tableColumn.default = undefined;
1908
+ }
1909
+ // todo: unable to get default charset
1910
+ // tableColumn.charset = dbColumn["CHARACTER_SET_NAME"];
1911
+ if (dbColumn["COLLATION_NAME"])
1912
+ tableColumn.collation =
1913
+ dbColumn["COLLATION_NAME"] ===
1914
+ defaultCollation["COLLATION_NAME"]
1915
+ ? undefined
1916
+ : dbColumn["COLLATION_NAME"];
1917
+ if (tableColumn.type === "datetime2" ||
1918
+ tableColumn.type === "time" ||
1919
+ tableColumn.type === "datetimeoffset") {
1920
+ tableColumn.precision =
1921
+ !this.isDefaultColumnPrecision(table, tableColumn, dbColumn["DATETIME_PRECISION"])
1922
+ ? dbColumn["DATETIME_PRECISION"]
1923
+ : undefined;
1924
+ }
1925
+ if (dbColumn["is_persisted"] !== null &&
1926
+ dbColumn["is_persisted"] !== undefined &&
1927
+ dbColumn["definition"]) {
1928
+ tableColumn.generatedType =
1929
+ dbColumn["is_persisted"] === true
1930
+ ? "STORED"
1931
+ : "VIRTUAL";
1932
+ // We cannot relay on information_schema.columns.generation_expression, because it is formatted different.
1933
+ const asExpressionQuery = this.selectTypeormMetadataSql({
1934
+ database: dbTable["TABLE_CATALOG"],
1935
+ schema: dbTable["TABLE_SCHEMA"],
1936
+ table: dbTable["TABLE_NAME"],
1937
+ type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
1938
+ name: tableColumn.name,
1939
+ });
1940
+ const results = await this.query(asExpressionQuery.query, asExpressionQuery.parameters);
1941
+ if (results[0] && results[0].value) {
1942
+ tableColumn.asExpression = results[0].value;
1943
+ }
1944
+ else {
1945
+ tableColumn.asExpression = "";
1946
+ }
1947
+ }
1948
+ return tableColumn;
1949
+ }));
1950
+ // find unique constraints of table, group them by constraint name and build TableUnique.
1951
+ const tableUniqueConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter((dbConstraint) => dbConstraint["TABLE_NAME"] ===
1952
+ dbTable["TABLE_NAME"] &&
1953
+ dbConstraint["TABLE_SCHEMA"] ===
1954
+ dbTable["TABLE_SCHEMA"] &&
1955
+ dbConstraint["TABLE_CATALOG"] ===
1956
+ dbTable["TABLE_CATALOG"] &&
1957
+ dbConstraint["CONSTRAINT_TYPE"] === "UNIQUE"), (dbConstraint) => dbConstraint["CONSTRAINT_NAME"]);
1958
+ table.uniques = tableUniqueConstraints.map((constraint) => {
1959
+ const uniques = dbConstraints.filter((dbC) => dbC["CONSTRAINT_NAME"] ===
1960
+ constraint["CONSTRAINT_NAME"]);
1961
+ return new TableUnique_1.TableUnique({
1962
+ name: constraint["CONSTRAINT_NAME"],
1963
+ columnNames: uniques.map((u) => u["COLUMN_NAME"]),
1964
+ });
1965
+ });
1966
+ // find check constraints of table, group them by constraint name and build TableCheck.
1967
+ const tableCheckConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter((dbConstraint) => dbConstraint["TABLE_NAME"] ===
1968
+ dbTable["TABLE_NAME"] &&
1969
+ dbConstraint["TABLE_SCHEMA"] ===
1970
+ dbTable["TABLE_SCHEMA"] &&
1971
+ dbConstraint["TABLE_CATALOG"] ===
1972
+ dbTable["TABLE_CATALOG"] &&
1973
+ dbConstraint["CONSTRAINT_TYPE"] === "CHECK"), (dbConstraint) => dbConstraint["CONSTRAINT_NAME"]);
1974
+ table.checks = tableCheckConstraints
1975
+ .filter((constraint) => !this.isEnumCheckConstraint(constraint["CONSTRAINT_NAME"]))
1976
+ .map((constraint) => {
1977
+ const checks = dbConstraints.filter((dbC) => dbC["CONSTRAINT_NAME"] ===
1978
+ constraint["CONSTRAINT_NAME"]);
1979
+ return new TableCheck_1.TableCheck({
1980
+ name: constraint["CONSTRAINT_NAME"],
1981
+ columnNames: checks.map((c) => c["COLUMN_NAME"]),
1982
+ expression: constraint["definition"],
1983
+ });
1984
+ });
1985
+ // find foreign key constraints of table, group them by constraint name and build TableForeignKey.
1986
+ const tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys.filter((dbForeignKey) => dbForeignKey["TABLE_NAME"] ===
1987
+ dbTable["TABLE_NAME"] &&
1988
+ dbForeignKey["TABLE_SCHEMA"] ===
1989
+ dbTable["TABLE_SCHEMA"] &&
1990
+ dbForeignKey["TABLE_CATALOG"] ===
1991
+ dbTable["TABLE_CATALOG"]), (dbForeignKey) => dbForeignKey["FK_NAME"]);
1992
+ table.foreignKeys = tableForeignKeyConstraints.map((dbForeignKey) => {
1993
+ const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["FK_NAME"] === dbForeignKey["FK_NAME"]);
1994
+ // if referenced table located in currently used db and schema, we don't need to concat db and schema names to table name.
1995
+ const db = dbForeignKey["TABLE_CATALOG"] === currentDatabase
1996
+ ? undefined
1997
+ : dbForeignKey["TABLE_CATALOG"];
1998
+ const schema = getSchemaFromKey(dbForeignKey, "REF_SCHEMA");
1999
+ const referencedTableName = this.driver.buildTableName(dbForeignKey["REF_TABLE"], schema, db);
2000
+ return new TableForeignKey_1.TableForeignKey({
2001
+ name: dbForeignKey["FK_NAME"],
2002
+ columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
2003
+ referencedDatabase: dbForeignKey["TABLE_CATALOG"],
2004
+ referencedSchema: dbForeignKey["REF_SCHEMA"],
2005
+ referencedTableName: referencedTableName,
2006
+ referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REF_COLUMN"]),
2007
+ onDelete: dbForeignKey["ON_DELETE"].replace("_", " "), // SqlServer returns NO_ACTION, instead of NO ACTION
2008
+ onUpdate: dbForeignKey["ON_UPDATE"].replace("_", " "), // SqlServer returns NO_ACTION, instead of NO ACTION
2009
+ });
2010
+ });
2011
+ // find index constraints of table, group them by constraint name and build TableIndex.
2012
+ const tableIndexConstraints = OrmUtils_1.OrmUtils.uniq(dbIndices.filter((dbIndex) => dbIndex["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
2013
+ dbIndex["TABLE_SCHEMA"] ===
2014
+ dbTable["TABLE_SCHEMA"] &&
2015
+ dbIndex["TABLE_CATALOG"] ===
2016
+ dbTable["TABLE_CATALOG"]), (dbIndex) => dbIndex["INDEX_NAME"]);
2017
+ table.indices = tableIndexConstraints.map((constraint) => {
2018
+ const indices = dbIndices.filter((index) => {
2019
+ return (index["TABLE_CATALOG"] ===
2020
+ constraint["TABLE_CATALOG"] &&
2021
+ index["TABLE_SCHEMA"] ===
2022
+ constraint["TABLE_SCHEMA"] &&
2023
+ index["TABLE_NAME"] === constraint["TABLE_NAME"] &&
2024
+ index["INDEX_NAME"] === constraint["INDEX_NAME"]);
2025
+ });
2026
+ return new TableIndex_1.TableIndex({
2027
+ table: table,
2028
+ name: constraint["INDEX_NAME"],
2029
+ columnNames: indices.map((i) => i["COLUMN_NAME"]),
2030
+ isUnique: constraint["IS_UNIQUE"],
2031
+ where: constraint["CONDITION"],
2032
+ });
2033
+ });
2034
+ return table;
2035
+ }));
2036
+ }
2037
+ /**
2038
+ * Builds and returns SQL for create table.
2039
+ */
2040
+ createTableSql(table, createForeignKeys) {
2041
+ const columnDefinitions = table.columns
2042
+ .map((column) => this.buildCreateColumnSql(table, column, false, true))
2043
+ .join(", ");
2044
+ let sql = `CREATE TABLE ${this.escapePath(table)} (${columnDefinitions}`;
2045
+ table.columns
2046
+ .filter((column) => column.isUnique)
2047
+ .forEach((column) => {
2048
+ const isUniqueExist = table.uniques.some((unique) => unique.columnNames.length === 1 &&
2049
+ unique.columnNames[0] === column.name);
2050
+ if (!isUniqueExist)
2051
+ table.uniques.push(new TableUnique_1.TableUnique({
2052
+ name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
2053
+ columnNames: [column.name],
2054
+ }));
2055
+ });
2056
+ if (table.uniques.length > 0) {
2057
+ const uniquesSql = table.uniques
2058
+ .map((unique) => {
2059
+ const uniqueName = unique.name
2060
+ ? unique.name
2061
+ : this.connection.namingStrategy.uniqueConstraintName(table, unique.columnNames);
2062
+ const columnNames = unique.columnNames
2063
+ .map((columnName) => `"${columnName}"`)
2064
+ .join(", ");
2065
+ return `CONSTRAINT "${uniqueName}" UNIQUE (${columnNames})`;
2066
+ })
2067
+ .join(", ");
2068
+ sql += `, ${uniquesSql}`;
2069
+ }
2070
+ if (table.checks.length > 0) {
2071
+ const checksSql = table.checks
2072
+ .map((check) => {
2073
+ const checkName = check.name
2074
+ ? check.name
2075
+ : this.connection.namingStrategy.checkConstraintName(table, check.expression);
2076
+ return `CONSTRAINT "${checkName}" CHECK (${check.expression})`;
2077
+ })
2078
+ .join(", ");
2079
+ sql += `, ${checksSql}`;
2080
+ }
2081
+ if (table.foreignKeys.length > 0 && createForeignKeys) {
2082
+ const foreignKeysSql = table.foreignKeys
2083
+ .map((fk) => {
2084
+ const columnNames = fk.columnNames
2085
+ .map((columnName) => `"${columnName}"`)
2086
+ .join(", ");
2087
+ if (!fk.name)
2088
+ fk.name = this.connection.namingStrategy.foreignKeyName(table, fk.columnNames, this.getTablePath(fk), fk.referencedColumnNames);
2089
+ const referencedColumnNames = fk.referencedColumnNames
2090
+ .map((columnName) => `"${columnName}"`)
2091
+ .join(", ");
2092
+ let constraint = `CONSTRAINT "${fk.name}" FOREIGN KEY (${columnNames}) REFERENCES ${this.escapePath(this.getTablePath(fk))} (${referencedColumnNames})`;
2093
+ if (fk.onDelete)
2094
+ constraint += ` ON DELETE ${fk.onDelete}`;
2095
+ if (fk.onUpdate)
2096
+ constraint += ` ON UPDATE ${fk.onUpdate}`;
2097
+ return constraint;
2098
+ })
2099
+ .join(", ");
2100
+ sql += `, ${foreignKeysSql}`;
2101
+ }
2102
+ const primaryColumns = table.columns.filter((column) => column.isPrimary);
2103
+ if (primaryColumns.length > 0) {
2104
+ const primaryKeyName = primaryColumns[0].primaryKeyConstraintName
2105
+ ? primaryColumns[0].primaryKeyConstraintName
2106
+ : this.connection.namingStrategy.primaryKeyName(table, primaryColumns.map((column) => column.name));
2107
+ const columnNames = primaryColumns
2108
+ .map((column) => `"${column.name}"`)
2109
+ .join(", ");
2110
+ sql += `, CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNames})`;
2111
+ }
2112
+ sql += `)`;
2113
+ return new Query_1.Query(sql);
2114
+ }
2115
+ /**
2116
+ * Builds drop table sql.
2117
+ */
2118
+ dropTableSql(tableOrName, ifExist) {
2119
+ const query = ifExist
2120
+ ? `DROP TABLE IF EXISTS ${this.escapePath(tableOrName)}`
2121
+ : `DROP TABLE ${this.escapePath(tableOrName)}`;
2122
+ return new Query_1.Query(query);
2123
+ }
2124
+ createViewSql(view) {
2125
+ const parsedName = this.driver.parseTableName(view);
2126
+ // Can't use `escapePath` here because `CREATE VIEW` does not accept database names.
2127
+ const viewIdentifier = parsedName.schema
2128
+ ? `"${parsedName.schema}"."${parsedName.tableName}"`
2129
+ : `"${parsedName.tableName}"`;
2130
+ if (typeof view.expression === "string") {
2131
+ return new Query_1.Query(`CREATE VIEW ${viewIdentifier} AS ${view.expression}`);
2132
+ }
2133
+ else {
2134
+ return new Query_1.Query(`CREATE VIEW ${viewIdentifier} AS ${view
2135
+ .expression(this.connection)
2136
+ .getQuery()}`);
2137
+ }
2138
+ }
2139
+ async insertViewDefinitionSql(view) {
2140
+ const parsedTableName = this.driver.parseTableName(view);
2141
+ if (!parsedTableName.schema) {
2142
+ parsedTableName.schema = await this.getCurrentSchema();
2143
+ }
2144
+ const expression = typeof view.expression === "string"
2145
+ ? view.expression.trim()
2146
+ : view.expression(this.connection).getQuery();
2147
+ return this.insertTypeormMetadataSql({
2148
+ type: MetadataTableType_1.MetadataTableType.VIEW,
2149
+ database: parsedTableName.database,
2150
+ schema: parsedTableName.schema,
2151
+ name: parsedTableName.tableName,
2152
+ value: expression,
2153
+ });
2154
+ }
2155
+ /**
2156
+ * Builds drop view sql.
2157
+ */
2158
+ dropViewSql(viewOrPath) {
2159
+ return new Query_1.Query(`DROP VIEW ${this.escapePath(viewOrPath)}`);
2160
+ }
2161
+ /**
2162
+ * Builds remove view sql.
2163
+ */
2164
+ async deleteViewDefinitionSql(viewOrPath) {
2165
+ const parsedTableName = this.driver.parseTableName(viewOrPath);
2166
+ if (!parsedTableName.schema) {
2167
+ parsedTableName.schema = await this.getCurrentSchema();
2168
+ }
2169
+ return this.deleteTypeormMetadataSql({
2170
+ type: MetadataTableType_1.MetadataTableType.VIEW,
2171
+ database: parsedTableName.database,
2172
+ schema: parsedTableName.schema,
2173
+ name: parsedTableName.tableName,
2174
+ });
2175
+ }
2176
+ /**
2177
+ * Builds create index sql.
2178
+ */
2179
+ createIndexSql(table, index) {
2180
+ const columns = index.columnNames
2181
+ .map((columnName) => `"${columnName}"`)
2182
+ .join(", ");
2183
+ return new Query_1.Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX "${index.name}" ON ${this.escapePath(table)} (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
2184
+ }
2185
+ /**
2186
+ * Builds drop index sql.
2187
+ */
2188
+ dropIndexSql(table, indexOrName) {
2189
+ const indexName = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
2190
+ ? indexOrName.name
2191
+ : indexOrName;
2192
+ return new Query_1.Query(`DROP INDEX "${indexName}" ON ${this.escapePath(table)}`);
2193
+ }
2194
+ /**
2195
+ * Builds create primary key sql.
2196
+ */
2197
+ createPrimaryKeySql(table, columnNames, constraintName) {
2198
+ const primaryKeyName = constraintName
2199
+ ? constraintName
2200
+ : this.connection.namingStrategy.primaryKeyName(table, columnNames);
2201
+ const columnNamesString = columnNames
2202
+ .map((columnName) => `"${columnName}"`)
2203
+ .join(", ");
2204
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNamesString})`);
2205
+ }
2206
+ /**
2207
+ * Builds drop primary key sql.
2208
+ */
2209
+ dropPrimaryKeySql(table) {
2210
+ const columnNames = table.primaryColumns.map((column) => column.name);
2211
+ const constraintName = table.primaryColumns[0].primaryKeyConstraintName;
2212
+ const primaryKeyName = constraintName
2213
+ ? constraintName
2214
+ : this.connection.namingStrategy.primaryKeyName(table, columnNames);
2215
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${primaryKeyName}"`);
2216
+ }
2217
+ /**
2218
+ * Builds create unique constraint sql.
2219
+ */
2220
+ createUniqueConstraintSql(table, uniqueConstraint) {
2221
+ const columnNames = uniqueConstraint.columnNames
2222
+ .map((column) => `"` + column + `"`)
2223
+ .join(", ");
2224
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE (${columnNames})`);
2225
+ }
2226
+ /**
2227
+ * Builds drop unique constraint sql.
2228
+ */
2229
+ dropUniqueConstraintSql(table, uniqueOrName) {
2230
+ const uniqueName = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
2231
+ ? uniqueOrName.name
2232
+ : uniqueOrName;
2233
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueName}"`);
2234
+ }
2235
+ /**
2236
+ * Builds create check constraint sql.
2237
+ */
2238
+ createCheckConstraintSql(table, checkConstraint) {
2239
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${checkConstraint.name}" CHECK (${checkConstraint.expression})`);
2240
+ }
2241
+ /**
2242
+ * Builds drop check constraint sql.
2243
+ */
2244
+ dropCheckConstraintSql(table, checkOrName) {
2245
+ const checkName = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
2246
+ ? checkOrName.name
2247
+ : checkOrName;
2248
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${checkName}"`);
2249
+ }
2250
+ /**
2251
+ * Builds create foreign key sql.
2252
+ */
2253
+ createForeignKeySql(table, foreignKey) {
2254
+ const columnNames = foreignKey.columnNames
2255
+ .map((column) => `"` + column + `"`)
2256
+ .join(", ");
2257
+ const referencedColumnNames = foreignKey.referencedColumnNames
2258
+ .map((column) => `"` + column + `"`)
2259
+ .join(",");
2260
+ let sql = `ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${foreignKey.name}" FOREIGN KEY (${columnNames}) ` +
2261
+ `REFERENCES ${this.escapePath(this.getTablePath(foreignKey))}(${referencedColumnNames})`;
2262
+ if (foreignKey.onDelete)
2263
+ sql += ` ON DELETE ${foreignKey.onDelete}`;
2264
+ if (foreignKey.onUpdate)
2265
+ sql += ` ON UPDATE ${foreignKey.onUpdate}`;
2266
+ return new Query_1.Query(sql);
2267
+ }
2268
+ /**
2269
+ * Builds drop foreign key sql.
2270
+ */
2271
+ dropForeignKeySql(table, foreignKeyOrName) {
2272
+ const foreignKeyName = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
2273
+ ? foreignKeyOrName.name
2274
+ : foreignKeyOrName;
2275
+ return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${foreignKeyName}"`);
2276
+ }
2277
+ /**
2278
+ * Escapes given table or View path.
2279
+ */
2280
+ escapePath(target) {
2281
+ const { database, schema, tableName } = this.driver.parseTableName(target);
2282
+ if (database && database !== this.driver.database) {
2283
+ if (schema && schema !== this.driver.searchSchema) {
2284
+ return `"${database}"."${schema}"."${tableName}"`;
2285
+ }
2286
+ return `"${database}".."${tableName}"`;
2287
+ }
2288
+ if (schema && schema !== this.driver.searchSchema) {
2289
+ return `"${schema}"."${tableName}"`;
2290
+ }
2291
+ return `"${tableName}"`;
2292
+ }
2293
+ /**
2294
+ * Concat database name and schema name to the foreign key name.
2295
+ * Needs because FK name is relevant to the schema and database.
2296
+ */
2297
+ buildForeignKeyName(fkName, schemaName, dbName) {
2298
+ let joinedFkName = fkName;
2299
+ if (schemaName && schemaName !== this.driver.searchSchema)
2300
+ joinedFkName = schemaName + "." + joinedFkName;
2301
+ if (dbName && dbName !== this.driver.database)
2302
+ joinedFkName = dbName + "." + joinedFkName;
2303
+ return joinedFkName;
2304
+ }
2305
+ /**
2306
+ * Removes parenthesis around default value.
2307
+ * Sql server returns default value with parenthesis around, e.g.
2308
+ * ('My text') - for string
2309
+ * ((1)) - for number
2310
+ * (newsequentialId()) - for function
2311
+ */
2312
+ removeParenthesisFromDefault(defaultValue) {
2313
+ if (defaultValue.substr(0, 1) !== "(")
2314
+ return defaultValue;
2315
+ const normalizedDefault = defaultValue.substr(1, defaultValue.lastIndexOf(")") - 1);
2316
+ return this.removeParenthesisFromDefault(normalizedDefault);
2317
+ }
2318
+ /**
2319
+ * Builds a query for create column.
2320
+ */
2321
+ buildCreateColumnSql(table, column, skipIdentity, createDefault, skipEnum) {
2322
+ let c = `"${column.name}" ${this.connection.driver.createFullType(column)}`;
2323
+ if (!skipEnum && column.enum) {
2324
+ const expression = this.getEnumExpression(column);
2325
+ const checkName = this.connection.namingStrategy.checkConstraintName(table, expression, true);
2326
+ c += ` CONSTRAINT ${checkName} CHECK(${expression})`;
2327
+ }
2328
+ if (column.collation)
2329
+ c += " COLLATE " + column.collation;
2330
+ if (column.asExpression) {
2331
+ c += ` AS (${column.asExpression})`;
2332
+ if (column.generatedType === "STORED") {
2333
+ c += ` PERSISTED`;
2334
+ // NOT NULL can be specified for computed columns only if PERSISTED is also specified
2335
+ if (column.isNullable !== true)
2336
+ c += " NOT NULL";
2337
+ }
2338
+ }
2339
+ else {
2340
+ if (column.isNullable !== true)
2341
+ c += " NOT NULL";
2342
+ }
2343
+ if (column.isGenerated === true &&
2344
+ column.generationStrategy === "increment" &&
2345
+ !skipIdentity)
2346
+ // don't use skipPrimary here since updates can update already exist primary without auto inc.
2347
+ c += " IDENTITY(1,1)";
2348
+ if (column.default !== undefined &&
2349
+ column.default !== null &&
2350
+ createDefault) {
2351
+ // we create named constraint to be able to delete this constraint when column been dropped
2352
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, column.name);
2353
+ c += ` CONSTRAINT "${defaultName}" DEFAULT ${column.default}`;
2354
+ }
2355
+ if (column.isGenerated &&
2356
+ column.generationStrategy === "uuid" &&
2357
+ !column.default) {
2358
+ // we create named constraint to be able to delete this constraint when column been dropped
2359
+ const defaultName = this.connection.namingStrategy.defaultConstraintName(table, column.name);
2360
+ c += ` CONSTRAINT "${defaultName}" DEFAULT NEWSEQUENTIALID()`;
2361
+ }
2362
+ return c;
2363
+ }
2364
+ getEnumExpression(column) {
2365
+ if (!column.enum) {
2366
+ throw new Error(`Enum is not defined in column ${column.name}`);
2367
+ }
2368
+ return (column.name +
2369
+ " IN (" +
2370
+ column.enum.map((val) => "'" + val + "'").join(",") +
2371
+ ")");
2372
+ }
2373
+ isEnumCheckConstraint(name) {
2374
+ return name.indexOf("CHK_") !== -1 && name.indexOf("_ENUM") !== -1;
2375
+ }
2376
+ /**
2377
+ * Converts MssqlParameter into real mssql parameter type.
2378
+ */
2379
+ mssqlParameterToNativeParameter(parameter) {
2380
+ switch (this.driver.normalizeType({ type: parameter.type })) {
2381
+ case "bit":
2382
+ return this.driver.mssql.Bit;
2383
+ case "bigint":
2384
+ return this.driver.mssql.BigInt;
2385
+ case "decimal":
2386
+ return this.driver.mssql.Decimal(...parameter.params);
2387
+ case "float":
2388
+ return this.driver.mssql.Float;
2389
+ case "int":
2390
+ return this.driver.mssql.Int;
2391
+ case "money":
2392
+ return this.driver.mssql.Money;
2393
+ case "numeric":
2394
+ return this.driver.mssql.Numeric(...parameter.params);
2395
+ case "smallint":
2396
+ return this.driver.mssql.SmallInt;
2397
+ case "smallmoney":
2398
+ return this.driver.mssql.SmallMoney;
2399
+ case "real":
2400
+ return this.driver.mssql.Real;
2401
+ case "tinyint":
2402
+ return this.driver.mssql.TinyInt;
2403
+ case "char":
2404
+ if (this.driver.options.options
2405
+ ?.disableAsciiToUnicodeParamConversion) {
2406
+ return this.driver.mssql.Char(...parameter.params);
2407
+ }
2408
+ return this.driver.mssql.NChar(...parameter.params);
2409
+ case "nchar":
2410
+ return this.driver.mssql.NChar(...parameter.params);
2411
+ case "text":
2412
+ if (this.driver.options.options
2413
+ ?.disableAsciiToUnicodeParamConversion) {
2414
+ return this.driver.mssql.Text;
2415
+ }
2416
+ return this.driver.mssql.Ntext;
2417
+ case "ntext":
2418
+ return this.driver.mssql.Ntext;
2419
+ case "varchar":
2420
+ if (this.driver.options.options
2421
+ ?.disableAsciiToUnicodeParamConversion) {
2422
+ return this.driver.mssql.VarChar(...parameter.params);
2423
+ }
2424
+ return this.driver.mssql.NVarChar(...parameter.params);
2425
+ case "nvarchar":
2426
+ return this.driver.mssql.NVarChar(...parameter.params);
2427
+ case "xml":
2428
+ return this.driver.mssql.Xml;
2429
+ case "time":
2430
+ return this.driver.mssql.Time(...parameter.params);
2431
+ case "date":
2432
+ return this.driver.mssql.Date;
2433
+ case "datetime":
2434
+ return this.driver.mssql.DateTime;
2435
+ case "datetime2":
2436
+ return this.driver.mssql.DateTime2(...parameter.params);
2437
+ case "datetimeoffset":
2438
+ return this.driver.mssql.DateTimeOffset(...parameter.params);
2439
+ case "smalldatetime":
2440
+ return this.driver.mssql.SmallDateTime;
2441
+ case "uniqueidentifier":
2442
+ return this.driver.mssql.UniqueIdentifier;
2443
+ case "variant":
2444
+ return this.driver.mssql.Variant;
2445
+ case "binary":
2446
+ return this.driver.mssql.Binary;
2447
+ case "varbinary":
2448
+ return this.driver.mssql.VarBinary(...parameter.params);
2449
+ case "image":
2450
+ return this.driver.mssql.Image;
2451
+ case "udt":
2452
+ return this.driver.mssql.UDT;
2453
+ case "rowversion":
2454
+ return this.driver.mssql.RowVersion;
2455
+ }
2456
+ }
2457
+ /**
2458
+ * Converts string literal of isolation level to enum.
2459
+ * The underlying mssql driver requires an enum for the isolation level.
2460
+ */
2461
+ convertIsolationLevel(isolation) {
2462
+ const ISOLATION_LEVEL = this.driver.mssql.ISOLATION_LEVEL;
2463
+ switch (isolation) {
2464
+ case "READ UNCOMMITTED":
2465
+ return ISOLATION_LEVEL.READ_UNCOMMITTED;
2466
+ case "REPEATABLE READ":
2467
+ return ISOLATION_LEVEL.REPEATABLE_READ;
2468
+ case "SERIALIZABLE":
2469
+ return ISOLATION_LEVEL.SERIALIZABLE;
2470
+ case "READ COMMITTED":
2471
+ default:
2472
+ return ISOLATION_LEVEL.READ_COMMITTED;
2473
+ }
2474
+ }
2475
+ /**
2476
+ * Change table comment.
2477
+ */
2478
+ changeTableComment(tableOrName, comment) {
2479
+ throw new error_1.TypeORMError(`sqlserver driver does not support change table comment.`);
2480
+ }
2481
+ }
2482
+ exports.SqlServerQueryRunner = SqlServerQueryRunner;
2483
+
2484
+ //# sourceMappingURL=SqlServerQueryRunner.js.map