@dineug/erd-editor 4.1.0 → 4.2.0

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 (186) hide show
  1. package/README.md +17 -4
  2. package/dist/components/dictionary/Dictionary.d.ts +12 -0
  3. package/dist/components/dictionary/Dictionary.styles.d.ts +33 -0
  4. package/dist/components/dictionary/checkCount.d.ts +28 -0
  5. package/dist/components/dictionary/checkSheet.d.ts +41 -0
  6. package/dist/components/dictionary/dictionary-context-menu/DictionaryContextMenu.d.ts +30 -0
  7. package/dist/components/dictionary/dictionaryCommit.d.ts +83 -0
  8. package/dist/components/dictionary/dictionaryFile.d.ts +23 -0
  9. package/dist/components/dictionary/dictionaryKeys.d.ts +48 -0
  10. package/dist/components/dictionary/dictionaryView.d.ts +65 -0
  11. package/dist/components/dictionary/domain-cell-editor/DomainCellEditor.d.ts +22 -0
  12. package/dist/components/dictionary/domain-cell-editor/DomainCellEditor.styles.d.ts +7 -0
  13. package/dist/components/dictionary/domain-cell-editor/openDomainCellEditor.d.ts +9 -0
  14. package/dist/components/dictionary/gridTheme.d.ts +18 -0
  15. package/dist/components/dictionary/sheets.d.ts +65 -0
  16. package/dist/components/erd/automatic-table-placement/flowPlacement.d.ts +4 -4
  17. package/dist/components/erd/canvas/EditOverlay.styles.d.ts +6 -0
  18. package/dist/components/erd/canvas/sceneHit.d.ts +5 -0
  19. package/dist/components/erd/canvas/sceneTokens.d.ts +6 -0
  20. package/dist/components/erd/canvas/table/Table.d.ts +6 -0
  21. package/dist/components/erd/canvas/table/blankLogicalName.d.ts +19 -0
  22. package/dist/components/erd/canvas/table/cellLayout.d.ts +4 -4
  23. package/dist/components/erd/canvas/table/column/Column.d.ts +32 -5
  24. package/dist/components/erd/canvas/table/dictionaryMarks.d.ts +29 -0
  25. package/dist/components/erd/canvas/table/useFocusTable.d.ts +1 -0
  26. package/dist/components/erd/diff-viewer/diff-tree/DiffTree.styles.d.ts +1 -0
  27. package/dist/components/erd/diff-viewer/diff-tree/diffTreeModel.d.ts +4 -1
  28. package/dist/components/erd/erd-context-menu/menus/nameViewMenus.d.ts +22 -0
  29. package/dist/components/erd/floating-toolbar/FloatingToolbar.d.ts +1 -1
  30. package/dist/components/erd/floating-toolbar/nameViewDropdown.d.ts +16 -0
  31. package/dist/components/erd/floating-toolbar/nameViewDropdown.styles.d.ts +5 -0
  32. package/dist/components/erd/readerNameView.d.ts +15 -0
  33. package/dist/components/explorer/explorerTree.d.ts +4 -1
  34. package/dist/components/explorer/fieldIcon.d.ts +4 -1
  35. package/dist/components/explorer/matchTarget.d.ts +6 -6
  36. package/dist/components/export-image/ExportImage.d.ts +10 -0
  37. package/dist/components/export-image/exportImageActions.d.ts +2 -2
  38. package/dist/components/flowCenters.d.ts +9 -0
  39. package/dist/components/map-columns/nameOf.d.ts +11 -3
  40. package/dist/components/primitives/icon/icons.d.ts +5 -0
  41. package/dist/components/quick-search/actions.d.ts +3 -1
  42. package/dist/components/quick-search/scopedActions.d.ts +2 -2
  43. package/dist/components/schema-sql/schema-sql-options/SchemaSQLOptions.d.ts +2 -2
  44. package/dist/components/schema-sql/schema-sql-options/SchemaSQLOptions.styles.d.ts +2 -0
  45. package/dist/components/schema-sql/schemaSQLView.d.ts +2 -0
  46. package/dist/components/settings/lockSettingRows.d.ts +2 -1
  47. package/dist/components/table-view/column/column-domain/ColumnDomain.d.ts +19 -0
  48. package/dist/components/table-view/column/column-domain/domainOptions.d.ts +13 -0
  49. package/dist/components/table-view/column/column-logical-name/ColumnLogicalName.d.ts +22 -0
  50. package/dist/components/table-view/column/column-logical-name/ColumnLogicalName.styles.d.ts +4 -0
  51. package/dist/components/table-view/column/columnViewText.d.ts +33 -0
  52. package/dist/components/table-view/column/useHintList.d.ts +24 -0
  53. package/dist/components/visualization/createVisualization.d.ts +2 -0
  54. package/dist/components/visualization/flowLayout.d.ts +2 -1
  55. package/dist/components/visualization/table/column/Column.d.ts +4 -0
  56. package/dist/components/visualization/visualization-toolbar/VisualizationToolbar.d.ts +2 -2
  57. package/dist/components/visualization/visualizationView.d.ts +15 -4
  58. package/dist/constants/layout.d.ts +11 -0
  59. package/dist/constants/schema.d.ts +15 -2
  60. package/dist/engine/actions.d.ts +5 -2
  61. package/dist/engine/history.actions.d.ts +8 -0
  62. package/dist/engine/history.d.ts +11 -3
  63. package/dist/engine/index.js +17 -17
  64. package/dist/engine/modules/dictionary/actions.d.ts +74 -0
  65. package/dist/engine/modules/dictionary/atom.actions.d.ts +74 -0
  66. package/dist/engine/modules/dictionary/checks.d.ts +76 -0
  67. package/dist/engine/modules/dictionary/derive.d.ts +54 -0
  68. package/dist/engine/modules/dictionary/derivedNames.d.ts +23 -0
  69. package/dist/engine/modules/dictionary/dictionaryIndex.d.ts +73 -0
  70. package/dist/engine/modules/dictionary/domainLinks.d.ts +9 -0
  71. package/dist/engine/modules/dictionary/domainTypes.d.ts +27 -0
  72. package/dist/engine/modules/dictionary/entryWrites.d.ts +63 -0
  73. package/dist/engine/modules/dictionary/generator.actions.d.ts +126 -0
  74. package/dist/engine/modules/dictionary/history.d.ts +14 -0
  75. package/dist/engine/modules/dictionary/membership.d.ts +28 -0
  76. package/dist/engine/modules/dictionary/orderKeys.d.ts +13 -0
  77. package/dist/engine/modules/dictionary/termIndex.d.ts +24 -0
  78. package/dist/engine/modules/editor/actions.d.ts +18 -3
  79. package/dist/engine/modules/editor/atom.actions.d.ts +24 -6
  80. package/dist/engine/modules/editor/generator.actions.d.ts +22 -8
  81. package/dist/engine/modules/editor/state.d.ts +24 -0
  82. package/dist/engine/modules/editor/utils/nameView.d.ts +103 -0
  83. package/dist/engine/modules/editor/view.actions.d.ts +24 -1
  84. package/dist/engine/modules/editor/view.d.ts +8 -0
  85. package/dist/engine/modules/relationship/fkColumns.d.ts +10 -4
  86. package/dist/engine/modules/settings/actions.d.ts +13 -3
  87. package/dist/engine/modules/settings/atom.actions.d.ts +49 -5
  88. package/dist/engine/modules/settings/generator.actions.d.ts +2 -2
  89. package/dist/engine/modules/table/actions.d.ts +7 -0
  90. package/dist/engine/modules/table/atom.actions.d.ts +46 -0
  91. package/dist/engine/modules/table/generator.actions.d.ts +7 -0
  92. package/dist/engine/modules/table/history.d.ts +2 -0
  93. package/dist/engine/modules/table-column/actions.d.ts +7 -0
  94. package/dist/engine/modules/table-column/atom.actions.d.ts +49 -0
  95. package/dist/engine/modules/table-column/generator.actions.d.ts +5 -0
  96. package/dist/engine/modules/table-column/history.d.ts +3 -0
  97. package/dist/engine/modules/table-column/utils/dataType.d.ts +3 -1
  98. package/dist/engine/rx-store.d.ts +6 -0
  99. package/dist/engine/tag.d.ts +8 -0
  100. package/dist/erd-editor.umd.js +1163 -817
  101. package/dist/i18n/messages/ar-SA.d.ts +125 -0
  102. package/dist/i18n/messages/de-DE.d.ts +93 -0
  103. package/dist/i18n/messages/en/common.d.ts +11 -0
  104. package/dist/i18n/messages/en/contextMenu.d.ts +1 -0
  105. package/dist/i18n/messages/en/dictionary.d.ts +79 -0
  106. package/dist/i18n/messages/en/findReplace.d.ts +2 -0
  107. package/dist/i18n/messages/en/index.d.ts +93 -0
  108. package/dist/i18n/messages/en/palette.d.ts +4 -0
  109. package/dist/i18n/messages/en/schemaSql.d.ts +1 -0
  110. package/dist/i18n/messages/en/settings.d.ts +1 -0
  111. package/dist/i18n/messages/en/visualization.d.ts +2 -0
  112. package/dist/i18n/messages/es-ES.d.ts +101 -0
  113. package/dist/i18n/messages/eu-ES.d.ts +93 -0
  114. package/dist/i18n/messages/fa-IR.d.ts +93 -0
  115. package/dist/i18n/messages/fr-FR.d.ts +101 -0
  116. package/dist/i18n/messages/he-IL.d.ts +101 -0
  117. package/dist/i18n/messages/id-ID.d.ts +85 -0
  118. package/dist/i18n/messages/it-IT.d.ts +101 -0
  119. package/dist/i18n/messages/ja-JP.d.ts +85 -0
  120. package/dist/i18n/messages/ko-KR.d.ts +85 -0
  121. package/dist/i18n/messages/nl-NL.d.ts +93 -0
  122. package/dist/i18n/messages/pl-PL.d.ts +109 -0
  123. package/dist/i18n/messages/pt-BR.d.ts +101 -0
  124. package/dist/i18n/messages/pt-PT.d.ts +101 -0
  125. package/dist/i18n/messages/ro-RO.d.ts +101 -0
  126. package/dist/i18n/messages/ru-RU.d.ts +109 -0
  127. package/dist/i18n/messages/sk-SK.d.ts +109 -0
  128. package/dist/i18n/messages/sl-SI.d.ts +109 -0
  129. package/dist/i18n/messages/sv-SE.d.ts +93 -0
  130. package/dist/i18n/messages/tr-TR.d.ts +93 -0
  131. package/dist/i18n/messages/uk-UA.d.ts +109 -0
  132. package/dist/i18n/messages/zh-CN.d.ts +85 -0
  133. package/dist/i18n/messages/zh-TW.d.ts +85 -0
  134. package/dist/index.d.ts +1 -0
  135. package/dist/index.js +25195 -18014
  136. package/dist/internal-types/index.d.ts +6 -0
  137. package/dist/konva/scene/columnDropTarget.d.ts +2 -2
  138. package/dist/loadValue-B5ojYrZ-.js +14682 -0
  139. package/dist/peer/index.d.ts +4 -0
  140. package/dist/peer/index.js +61 -60
  141. package/dist/services/export-png/ExportScene.d.ts +1 -1
  142. package/dist/services/export-png/documentScene.d.ts +7 -1
  143. package/dist/services/export-png/index.d.ts +11 -5
  144. package/dist/services/export-png/renderPng.d.ts +4 -1
  145. package/dist/services/export-png/renderSvg.d.ts +4 -1
  146. package/dist/shared-store-S7YWEz3E.js +1656 -0
  147. package/dist/themes/tokens.d.ts +12 -0
  148. package/dist/utils/calcTable.d.ts +20 -4
  149. package/dist/utils/collection/domain.entity.d.ts +3 -0
  150. package/dist/utils/collection/term.entity.d.ts +3 -0
  151. package/dist/utils/collection/word.entity.d.ts +3 -0
  152. package/dist/utils/dictionary-csv/csv.d.ts +13 -0
  153. package/dist/utils/dictionary-csv/decode.d.ts +7 -0
  154. package/dist/utils/dictionary-csv/dictionaryCsv.d.ts +55 -0
  155. package/dist/utils/dictionary-csv/index.d.ts +4 -0
  156. package/dist/utils/diff/types.d.ts +4 -0
  157. package/dist/utils/file/exportFile.d.ts +10 -0
  158. package/dist/utils/find-replace/findMatches.d.ts +10 -4
  159. package/dist/utils/find-replace/present.d.ts +1 -1
  160. package/dist/utils/find-replace/replaceActions.d.ts +9 -5
  161. package/dist/utils/focus.d.ts +2 -0
  162. package/dist/utils/formatCount.d.ts +10 -0
  163. package/dist/utils/keyboard-shortcut/index.d.ts +1 -1
  164. package/dist/utils/map-columns/alignTypes.d.ts +3 -3
  165. package/dist/utils/schema-sql/Databricks.d.ts +2 -2
  166. package/dist/utils/schema-sql/MSSQL.d.ts +1 -1
  167. package/dist/utils/schema-sql/MariaDB.d.ts +2 -2
  168. package/dist/utils/schema-sql/MySQL.d.ts +2 -2
  169. package/dist/utils/schema-sql/Oracle.d.ts +1 -1
  170. package/dist/utils/schema-sql/PostgreSQL.d.ts +1 -1
  171. package/dist/utils/schema-sql/SQLite.d.ts +2 -2
  172. package/dist/utils/schema-sql/Snowflake.d.ts +2 -2
  173. package/dist/utils/schema-sql/options.d.ts +2 -0
  174. package/dist/utils/schema-sql/utils.d.ts +14 -0
  175. package/dist/utils/table-clipboard/copy.d.ts +2 -3
  176. package/dist/utils/table-clipboard/index.d.ts +9 -1
  177. package/dist/utils/table-clipboard/paste.d.ts +2 -2
  178. package/dist/utils/table-clipboard/payload.d.ts +12 -0
  179. package/dist/utils/validation.d.ts +1 -0
  180. package/dist/workers/exportPng.shared-worker.js +30 -29
  181. package/package.json +7 -5
  182. package/dist/konva/batchDraw.d.ts +0 -42
  183. package/dist/konva/host.d.ts +0 -30
  184. package/dist/konva/jsx-types.test-d.d.ts +0 -2
  185. package/dist/loadValue-BKvXDYoC.js +0 -12925
  186. package/dist/shared-store-2IUOt99m.js +0 -1341
@@ -1,1341 +0,0 @@
1
- import { Aa as e, C as t, Ca as n, D as r, Da as i, E as a, Ea as o, Fa as s, Ia as c, Kn as l, Ko as u, Mo as d, Na as f, Oa as p, Sa as m, T as h, Ta as g, Vo as _, Xa as v, Ya as y, Za as b, Zo as x, _ as ee, _a as S, a as te, aa as C, b as ne, ba as w, c as T, ca as E, cs as D, da as O, dr as re, fa as k, g as ie, gs as ae, h as oe, ha as se, hr as ce, hs as A, i as le, ja as j, jo as M, ka as N, l as P, la as F, m as ue, ma as I, mr as de, n as fe, ni as L, o as pe, oa as R, oo as me, pa as z, pn as he, ps as B, r as ge, s as _e, sa as ve, ts as V, ua as H, va as U, w as ye, wa as W, x as be, xa as xe, ya as G } from "./loadValue-BKvXDYoC.js";
2
- import { Observable as K, Subject as q, debounceTime as Se, filter as Ce, map as we, merge as Te, race as Ee, startWith as De, switchMap as J, take as Oe, timer as ke } from "rxjs";
3
- import { isEmpty as Ae } from "es-toolkit/compat";
4
- import { isFunction as je, isNil as Y } from "es-toolkit";
5
- //#region src/engine/history.ts
6
- function X({ notify: e, dispatch: t, getNextVersion: n }, r) {
7
- let i = r?.commands ?? [], a = r?.cursor ?? -1, o = r?.limit ?? 0, s = !0, c = () => a !== -1, l = () => a < i.length - 1, u = (e) => o = e, d = () => ({
8
- hasRedo: l(),
9
- hasUndo: c()
10
- }), f = (e, r) => {
11
- s = !1, e[r](t, n), s = !0;
12
- };
13
- return Object.freeze({
14
- get cursor() {
15
- return a;
16
- },
17
- get size() {
18
- return i.length;
19
- },
20
- hasUndo: c,
21
- hasRedo: l,
22
- push: (t) => {
23
- s && (i.splice(a + 1, i.length - a), i.push(t), o !== 0 && i.length > o && (i = i.slice(i.length - o, i.length)), a = i.length - 1, e(d()));
24
- },
25
- undo: () => {
26
- if (!c()) return;
27
- let t = i[a];
28
- f(t, "undo"), a--, e(d());
29
- },
30
- redo: () => {
31
- if (!l()) return;
32
- let t = i[a + 1];
33
- f(t, "redo"), a++, e(d());
34
- },
35
- clear: () => {
36
- let t = i.length;
37
- i = [], a = -1, t > 0 && e(d());
38
- },
39
- setLimit: u,
40
- clone: (e) => X(e, {
41
- commands: [...i],
42
- cursor: a,
43
- limit: o
44
- })
45
- });
46
- }
47
- //#endregion
48
- //#region src/engine/rx-operators/flushOnNotifier.ts
49
- var Me = (e) => (t) => t.pipe(J((t) => e.pipe(Oe(1), we(() => t)))), Ne = (e, t = 200) => (n) => n.pipe(J((n) => Ee(ke(t), e.pipe(Oe(1))).pipe(we(() => n)))), Pe = (e) => {
50
- let t = (e) => (t) => {
51
- let n = Reflect.get(ie, t.type);
52
- return !n || !M(e, n);
53
- };
54
- return (n) => new K((r) => n.subscribe({
55
- next: (n) => {
56
- r.next(n.filter(t(e())));
57
- },
58
- error: (e) => r.error(e),
59
- complete: () => r.complete()
60
- })).pipe(P);
61
- }, Z = (e, t = []) => {
62
- let n = _(ee), r = (e) => !Y(e.tags) && t.some((t) => M(e.tags, t)) || !n(e.type);
63
- return (t) => new K((n) => t.subscribe({
64
- next: (t) => {
65
- n.next(e() ? t.filter(r) : t);
66
- },
67
- error: (e) => n.error(e),
68
- complete: () => n.complete()
69
- })).pipe(P);
70
- }, Fe = {
71
- [L.scrollTo]: u.viewScrollTo,
72
- [L.streamScrollTo]: u.viewStreamScrollTo,
73
- [L.changeZoomLevel]: u.viewChangeZoomLevel,
74
- [L.streamZoomLevel]: u.viewStreamZoomLevel
75
- }, Ie = ({ tags: e }) => !Y(e) && (M(e, y.shared) || M(e, y.following)), Le = (e) => {
76
- let t = Fe[e.type];
77
- return t && !Ie(e) ? {
78
- ...e,
79
- type: t
80
- } : e;
81
- }, Re = (e) => (t) => new K((n) => t.subscribe({
82
- next: (t) => {
83
- n.next(e() ? t.map(Le) : t);
84
- },
85
- error: (e) => n.error(e),
86
- complete: () => n.complete()
87
- })), ze = (e, t = []) => {
88
- let n = _(r), i = (e) => !Y(e.tags) && t.some((t) => M(e.tags, t)) || !n(e.type);
89
- return (t) => new K((n) => t.subscribe({
90
- next: (t) => {
91
- n.next(e() ? t.filter(i) : t);
92
- },
93
- error: (e) => n.error(e),
94
- complete: () => n.complete()
95
- })).pipe(P);
96
- }, Be = 2048;
97
- function Ve(e, { getReadonly: n = () => !1, getHistory: r, manualStreamFlush: i = !1, observable: o = !0 } = {}) {
98
- let s = /* @__PURE__ */ new Set(), c = ge(e, o), u = fe(c), d = {
99
- notify: (e) => c.dispatch(l(e)),
100
- dispatch: c.dispatchSync,
101
- getNextVersion: () => e.clock.getNextVersion()
102
- }, f = r?.(d) ?? X(d);
103
- f.setLimit(Be);
104
- let p = () => me(c.state), m = new q(), g = m.pipe(Re(p)), _ = new q(), v = new q(), b = new q(), x = v.pipe(De(void 0), J(() => _.pipe(pe(t, [
105
- [
106
- "@@move",
107
- h,
108
- y.drag
109
- ],
110
- ["@@scroll", a],
111
- ["@@color", ye]
112
- ], i ? Me(b) : void 0)))), ee = new K((e) => c.subscribe((t) => e.next(t))).pipe(T(ue), Pe(() => c.state.settings.lockSettings), Z(n, [y.shared]), Se(200)), S = (...t) => {
113
- let n = e.clock.getNextVersion();
114
- return ae(c.state, c.context, t).map((e) => (Y(e.version) && (e.version = n), e));
115
- }, C = (...e) => {
116
- let t = S(e);
117
- m.next(t);
118
- }, ne = (...e) => {
119
- queueMicrotask(() => C(e));
120
- }, w = () => {
121
- Array.from(s).forEach((e) => je(e) ? e() : e.unsubscribe()), s.clear(), c.destroy(), u.destroy(), f.clear(), m.complete(), b.complete();
122
- }, E = () => {
123
- v.next(), f.clear();
124
- }, D = () => {
125
- n() || p() || f.undo();
126
- }, O = () => {
127
- n() || p() || f.redo();
128
- }, re = () => {
129
- i && b.next();
130
- };
131
- return s.add(x.subscribe(he(c, f))).add(g.pipe(T(oe), te([y.changeOnly, y.shared]), Z(n), ze(p)).subscribe(_)).add(g.pipe(Z(n, [y.shared]), ze(p, [y.shared])).subscribe(c.dispatchSync)).add(c.subscribe((t) => {
132
- t.forEach((t) => e.clock.merge(t.version));
133
- })), Object.freeze({
134
- ...c,
135
- dispatch: ne,
136
- dispatchSync: C,
137
- destroy: w,
138
- undo: D,
139
- redo: O,
140
- history: f,
141
- resetHistory: E,
142
- change$: ee,
143
- flushStreamBuffers: re,
144
- getReadonly: n
145
- });
146
- }
147
- //#endregion
148
- //#region src/utils/focus.ts
149
- function He(e, t, n, r = null) {
150
- if (!e || n !== e.tableId) return !1;
151
- switch (t) {
152
- case "tableName":
153
- case "tableComment": return t === e.focusType;
154
- }
155
- return r === e.columnId && t === e.focusType;
156
- }
157
- var Ue = (e, t, n) => e?.tableId === t && e.selectColumnIds.includes(n);
158
- function We(e, t, n, r = null) {
159
- if (e?.tableId !== n) return !1;
160
- switch (t) {
161
- case d.tableName:
162
- case d.tableComment: return t === e.focusType && e.edit;
163
- }
164
- return r === e.columnId && t === e.focusType && e.edit;
165
- }
166
- function Ge(e) {
167
- let t = e.value.length;
168
- e.selectionStart = t, e.selectionEnd = t, e.focus();
169
- }
170
- var Ke = (e) => e ? {
171
- tableId: e.tableId,
172
- columnId: e.columnId,
173
- focusType: e.focusType
174
- } : null, qe = (e) => e ? JSON.stringify([
175
- e.tableId,
176
- e.columnId,
177
- e.focusType
178
- ]) : "", Q = "`";
179
- function Je(e) {
180
- return `'${e.replace(/[\\']/g, "\\$&")}'`;
181
- }
182
- var Ye = "NOT ENFORCED RELY", Xe = G(V.Databricks), Ze = /* @__PURE__ */ new Set(["BIGINT", "LONG"]);
183
- function Qe(e) {
184
- return M(e.options, x.autoIncrement) && Ze.has(e.dataType.trim().toUpperCase());
185
- }
186
- function $e(e, t, { statements: n, written: r } = {}) {
187
- let i = [], a = [], s = [""], { tables: c, relationships: l, indexes: u } = o(e, t);
188
- return c.forEach((t) => {
189
- r?.tables.push(t), et(e, {
190
- table: t,
191
- buffer: s,
192
- statements: n
193
- }), s.push(""), tt(e, {
194
- table: t,
195
- buffer: s
196
- });
197
- }), l.forEach((t) => {
198
- rt(e, {
199
- relationship: t,
200
- buffer: s,
201
- fkNames: i,
202
- statements: n
203
- }) && s.push("");
204
- }), u.forEach((t) => {
205
- it(e, {
206
- index: t,
207
- buffer: s,
208
- indexNames: a
209
- }), s.push("");
210
- }), s.join("\n");
211
- }
212
- function et(e, { buffer: t, table: n, statements: r }) {
213
- let { collections: i } = e, a = B(i).collection("tableColumnEntities").selectByIds(n.columnIds);
214
- t.push(`CREATE TABLE${I(r)} ${Q}${n.name}${Q}`), t.push("(");
215
- let o = S(a), s = O(a);
216
- if (a.forEach((n, r) => {
217
- nt(e, {
218
- column: n,
219
- isComma: o || a.length !== r + 1,
220
- spaceSize: s,
221
- buffer: t
222
- });
223
- }), o) {
224
- let e = U(a);
225
- t.push(` CONSTRAINT ${Q}PK_${n.name}${Q} PRIMARY KEY (${F(e, Q)}) ${Ye}`);
226
- }
227
- t.push(")"), n.comment.trim() === "" ? t.push("USING DELTA;") : (t.push("USING DELTA"), t.push(`COMMENT ${Je(n.comment)};`));
228
- let c = a.filter((e) => M(e.options, x.autoIncrement) && !Qe(e));
229
- c.length !== 0 && (t.push(""), c.forEach((e) => {
230
- t.push(`-- Databricks takes IDENTITY only on BIGINT, so ${Q}${n.name}${Q}.${Q}${e.name}${Q} is written without it.`);
231
- }));
232
- }
233
- function tt({ collections: e }, { buffer: t, table: n }) {
234
- let r = B(e).collection("tableColumnEntities").selectByIds(n.columnIds);
235
- N(r).forEach((e) => {
236
- t.push(`-- Databricks does not support UNIQUE constraints: ${Q}${n.name}${Q}.${Q}${e.name}${Q}`), t.push("");
237
- });
238
- }
239
- function nt(e, { buffer: t, column: n, isComma: r, spaceSize: i }) {
240
- let a = [];
241
- a.push(` ${Q}${n.name}${Q}` + k(i.name - n.name.length)), a.push(`${n.dataType}` + k(i.dataType - n.dataType.length));
242
- let o = M(n.options, x.notNull) || M(n.options, x.primaryKey);
243
- a.push(o ? "NOT NULL" : " "), Qe(n) ? a.push("GENERATED ALWAYS AS IDENTITY") : !M(n.options, x.autoIncrement) && n.default.trim() !== "" && a.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && a.push(`COMMENT ${Je(n.comment)}`), t.push(a.join(" ").trimEnd() + `${r ? "," : ""}`);
244
- }
245
- function rt(e, { buffer: t, relationship: n, fkNames: r, statements: i }) {
246
- let a = W(e, n);
247
- if (!a) return !1;
248
- let { startTable: o, endTable: s } = a, c = `FK_${o.name}_TO_${s.name}`;
249
- c = C(r, "", c), r.push({
250
- id: A(),
251
- name: c
252
- });
253
- let l = `ALTER TABLE ${Q}${s.name}${Q}`;
254
- return i === f.ifNotExists && t.push(`${l} DROP CONSTRAINT IF EXISTS ${Q}${c}${Q};`), t.push(l), t.push(` ADD CONSTRAINT ${Q}${c}${Q}`), t.push(` FOREIGN KEY (${F(a.end, Q)})`), t.push([
255
- ` REFERENCES ${Q}${o.name}${Q} (${F(a.start, Q)})`,
256
- ...H(n, Xe),
257
- `${Ye};`
258
- ].join(" ")), !0;
259
- }
260
- function it({ collections: e }, { buffer: t, index: n, indexNames: r }) {
261
- let i = B(e).collection("tableEntities").selectById(n.tableId);
262
- if (!i) return;
263
- let a = w(e, i, n).map(({ indexColumn: e, column: t }) => ({ name: `${Q}${t.name}${Q} ${g(e.orderType)}` }));
264
- if (a.length === 0) return;
265
- let o = n.name;
266
- n.name.trim() === "" && (o = `IDX_${i.name}`, o = C(r, "", o), r.push({
267
- id: A(),
268
- name: o
269
- })), t.push(`-- Databricks has no secondary indexes. ${Q}${o}${Q} on ${Q}${i.name}${Q} (${F(a)})`), t.push(`-- ALTER TABLE ${Q}${i.name}${Q} CLUSTER BY (${F(w(e, i, n).map(({ column: e }) => e), Q)});`);
270
- }
271
- function at(e, t, n) {
272
- let r = `${Q}${n}${Q}`, i = `USE SCHEMA ${r};`;
273
- return t === j.createAndUse ? `CREATE SCHEMA IF NOT EXISTS ${r};\n${i}` : i;
274
- }
275
- function ot(e, { tables: t }) {
276
- return t.map(({ name: e }) => `DROP TABLE IF EXISTS ${Q}${e}${Q};`).join("\n");
277
- }
278
- //#endregion
279
- //#region src/utils/schema-sql/MySQL.ts
280
- var st = G(V.MySQL), ct = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;", lt = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;";
281
- function ut(e, t, { statements: n, written: r } = {}) {
282
- if (n === f.ifNotExists) return dt(e, t, r);
283
- let i = [], a = [], s = [""], { tables: c, relationships: l, indexes: u } = o(e, t);
284
- return c.forEach((t) => {
285
- r?.tables.push(t), ft(e, {
286
- table: t,
287
- buffer: s
288
- }), s.push(""), ht(e, {
289
- table: t,
290
- buffer: s
291
- });
292
- }), l.forEach((t) => {
293
- vt(e, {
294
- relationship: t,
295
- buffer: s,
296
- fkNames: i
297
- }) && s.push("");
298
- }), u.forEach((t) => {
299
- bt(e, {
300
- index: t,
301
- buffer: s,
302
- indexNames: a
303
- }), s.push("");
304
- }), s.join("\n");
305
- }
306
- function dt(e, t, n) {
307
- let { settings: { bracketType: r }, collections: i } = e, { tables: a, relationships: s, indexes: c } = o(e, t);
308
- if (a.length === 0) return "";
309
- let l = [], u = /* @__PURE__ */ new Map();
310
- s.forEach((t) => {
311
- let n = _t(e, t, l);
312
- if (!n) return;
313
- let [r, ...i] = n.lines, a = u.get(n.table.id) ?? [];
314
- a.push([` ${r}`, ...i]), u.set(n.table.id, a);
315
- });
316
- let d = [], p = /* @__PURE__ */ new Map();
317
- c.forEach((t) => {
318
- let n = yt(e, t, d);
319
- if (!n) return;
320
- let r = p.get(n.table.id) ?? [];
321
- r.push([` ${t.unique ? "UNIQUE " : ""}INDEX ${n.name} (${n.columns})`]), p.set(n.table.id, r);
322
- });
323
- let m = [
324
- "",
325
- ct,
326
- ""
327
- ];
328
- return a.forEach((t) => {
329
- n?.tables.push(t);
330
- let a = B(i).collection("tableColumnEntities").selectByIds(t.columnIds);
331
- pt(e, m, t, f.ifNotExists, [
332
- ...N(a).map((e) => [` ${mt(r, t, e)}`]),
333
- ...p.get(t.id) ?? [],
334
- ...u.get(t.id) ?? []
335
- ]), m.push("");
336
- }), m.push(lt, ""), m.join("\n");
337
- }
338
- function ft(e, { buffer: t, table: n, statements: r }) {
339
- pt(e, t, n, r, []);
340
- }
341
- function pt(e, t, n, r, a) {
342
- let { settings: { bracketType: o }, collections: s } = e, c = z(o), l = B(s).collection("tableColumnEntities").selectByIds(n.columnIds);
343
- t.push(`CREATE TABLE${I(r)} ${c}${n.name}${c}`), t.push("(");
344
- let u = S(l), d = O(l), f = a.length !== 0;
345
- if (l.forEach((n, r) => {
346
- gt(e, {
347
- column: n,
348
- isComma: u || f || l.length !== r + 1,
349
- spaceSize: d,
350
- buffer: t
351
- });
352
- }), u) {
353
- let e = U(l);
354
- t.push(` PRIMARY KEY (${F(e, c)})${f ? "," : ""}`);
355
- }
356
- a.forEach((e, n) => {
357
- t.push(...e), n !== a.length - 1 && (t[t.length - 1] += ",");
358
- }), n.comment.trim() === "" ? t.push(");") : t.push(`) COMMENT ${i(n.comment)};`);
359
- }
360
- function mt(e, t, r) {
361
- let i = z(e);
362
- return `CONSTRAINT ${i}UQ_${n(t.name, e)}_${r.name}${i} UNIQUE (${i}${r.name}${i})`;
363
- }
364
- function ht({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
365
- let i = z(e), a = B(t).collection("tableColumnEntities").selectByIds(r.columnIds);
366
- p(a) && N(a).forEach((t) => {
367
- n.push(`ALTER TABLE ${i}${r.name}${i}`), n.push(` ADD ${mt(e, r, t)};`), n.push("");
368
- });
369
- }
370
- function gt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: a }) {
371
- let o = z(e), s = [];
372
- s.push(` ${o}${n.name}${o}` + k(a.name - n.name.length)), s.push(`${n.dataType}` + k(a.dataType - n.dataType.length)), s.push(`${M(n.options, x.notNull) ? "NOT NULL" : "NULL "}`), M(n.options, x.autoIncrement) ? s.push("AUTO_INCREMENT") : n.default.trim() !== "" && s.push(`DEFAULT ${E(n.default, V.MySQL, n.dataType)}`), n.comment.trim() !== "" && s.push(`COMMENT ${i(n.comment)}`), t.push(s.join(" ") + `${r ? "," : ""}`);
373
- }
374
- function _t(e, t, r) {
375
- let { settings: { bracketType: i } } = e, a = W(e, t);
376
- if (!a) return null;
377
- let { startTable: o, endTable: s } = a, c = z(i), l = n(o.name, i), u = n(s.name, i), d = R(r, `FK_${l}_TO_${u}`);
378
- return r.push({
379
- id: A(),
380
- name: d
381
- }), {
382
- table: s,
383
- lines: [
384
- `CONSTRAINT ${c}${d}${c}`,
385
- ` FOREIGN KEY (${F(a.end, c)})`,
386
- ` REFERENCES ${c}${o.name}${c} (${F(a.start, c)})`,
387
- ...H(t, st).map((e) => ` ${e}`)
388
- ]
389
- };
390
- }
391
- function vt(e, { buffer: t, relationship: n, fkNames: r }) {
392
- let i = _t(e, n, r);
393
- if (!i) return !1;
394
- let a = z(e.settings.bracketType), [o, ...s] = i.lines;
395
- return t.push(`ALTER TABLE ${a}${i.table.name}${a}`, ` ADD ${o}`, ...s), t[t.length - 1] += ";", !0;
396
- }
397
- function yt({ settings: { bracketType: e }, collections: t }, r, i) {
398
- let a = z(e), o = B(t).collection("tableEntities").selectById(r.tableId);
399
- if (!o) return null;
400
- let s = w(t, o, r).map(({ indexColumn: e, column: t }) => ({ name: `${a}${t.name}${a} ${g(e.orderType)}` }));
401
- if (s.length === 0) return null;
402
- let c = r.name;
403
- if (r.name.trim() === "") {
404
- let t = n(o.name, e);
405
- c = R(i, `IDX_${t}`), i.push({
406
- id: A(),
407
- name: c
408
- });
409
- }
410
- return {
411
- table: o,
412
- name: `${a}${c}${a}`,
413
- columns: F(s)
414
- };
415
- }
416
- function bt(e, { buffer: t, index: n, indexNames: r }) {
417
- let i = yt(e, n, r);
418
- if (!i) return;
419
- let a = z(e.settings.bracketType);
420
- t.push(`CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${i.name}`), t.push(` ON ${a}${i.table.name}${a} (${i.columns});`);
421
- }
422
- function xt({ settings: { bracketType: e } }, t, n) {
423
- let r = z(e), i = `${r}${n}${r}`, a = `USE ${i};`;
424
- return t === j.createAndUse ? `CREATE DATABASE IF NOT EXISTS ${i};\n${a}` : a;
425
- }
426
- function St({ settings: { bracketType: e } }, { tables: t }) {
427
- if (t.length === 0) return "";
428
- let n = z(e);
429
- return [
430
- ct,
431
- t.map((e) => `DROP TABLE IF EXISTS ${n}${e.name}${n};`).join("\n"),
432
- lt
433
- ].join("\n\n");
434
- }
435
- //#endregion
436
- //#region src/utils/schema-sql/MariaDB.ts
437
- var Ct = G(V.MariaDB);
438
- function wt(e, t, { statements: n, written: r } = {}) {
439
- let i = [], a = [], s = [""], { tables: c, relationships: l, indexes: u } = o(e, t);
440
- return c.forEach((t) => {
441
- r?.tables.push(t), Tt(e, {
442
- table: t,
443
- buffer: s,
444
- statements: n
445
- }), s.push(""), Et(e, {
446
- table: t,
447
- buffer: s,
448
- statements: n
449
- });
450
- }), l.forEach((t) => {
451
- Ot(e, {
452
- relationship: t,
453
- buffer: s,
454
- fkNames: i,
455
- statements: n
456
- }) && s.push("");
457
- }), u.forEach((t) => {
458
- kt(e, {
459
- index: t,
460
- buffer: s,
461
- indexNames: a,
462
- statements: n
463
- }), s.push("");
464
- }), s.join("\n");
465
- }
466
- function Tt(e, { buffer: t, table: n, statements: r }) {
467
- let { settings: { bracketType: a }, collections: o } = e, s = z(a), c = B(o).collection("tableColumnEntities").selectByIds(n.columnIds);
468
- t.push(`CREATE TABLE${I(r)} ${s}${n.name}${s}`), t.push("(");
469
- let l = S(c), u = O(c);
470
- if (c.forEach((n, r) => {
471
- l ? Dt(e, {
472
- column: n,
473
- isComma: !0,
474
- spaceSize: u,
475
- buffer: t
476
- }) : Dt(e, {
477
- column: n,
478
- isComma: c.length !== r + 1,
479
- spaceSize: u,
480
- buffer: t
481
- });
482
- }), l) {
483
- let e = U(c);
484
- t.push(` PRIMARY KEY (${F(e, s)})`);
485
- }
486
- n.comment.trim() === "" ? t.push(");") : t.push(`) COMMENT ${i(n.comment)};`);
487
- }
488
- function Et({ settings: { bracketType: e }, collections: t }, { buffer: r, table: i, statements: a }) {
489
- let o = z(e), s = B(t).collection("tableColumnEntities").selectByIds(i.columnIds);
490
- p(s) && N(s).forEach((t) => {
491
- r.push(`ALTER TABLE ${o}${i.name}${o}`), r.push(` ADD CONSTRAINT ${o}UQ_${n(i.name, e)}_${t.name}${o} UNIQUE${I(a)} (${o}${t.name}${o});`), r.push("");
492
- });
493
- }
494
- function Dt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: a }) {
495
- let o = z(e), s = [];
496
- s.push(` ${o}${n.name}${o}` + k(a.name - n.name.length)), s.push(`${n.dataType}` + k(a.dataType - n.dataType.length)), s.push(`${M(n.options, x.notNull) ? "NOT NULL" : "NULL "}`), M(n.options, x.autoIncrement) ? s.push("AUTO_INCREMENT") : n.default.trim() !== "" && s.push(`DEFAULT ${E(n.default, V.MariaDB)}`), n.comment.trim() !== "" && s.push(`COMMENT ${i(n.comment)}`), t.push(s.join(" ") + `${r ? "," : ""}`);
497
- }
498
- function Ot(e, { buffer: t, relationship: r, fkNames: i, statements: a }) {
499
- let { settings: { bracketType: o } } = e, s = W(e, r);
500
- if (!s) return !1;
501
- let { startTable: c, endTable: l } = s, u = z(o);
502
- t.push(`ALTER TABLE ${u}${l.name}${u}`);
503
- let d = n(c.name, o), f = n(l.name, o), p = R(i, `FK_${d}_TO_${f}`);
504
- return i.push({
505
- id: A(),
506
- name: p
507
- }), t.push(` ADD CONSTRAINT ${u}${p}${u}`), t.push(` FOREIGN KEY${I(a)} (${F(s.end, u)})`), t.push(` REFERENCES ${u}${c.name}${u} (${F(s.start, u)})`, ...H(r, Ct).map((e) => ` ${e}`)), t[t.length - 1] += ";", !0;
508
- }
509
- function kt({ settings: { bracketType: e }, collections: t }, { buffer: r, index: i, indexNames: a, statements: o }) {
510
- let s = z(e), c = B(t).collection("tableEntities").selectById(i.tableId);
511
- if (!c) return;
512
- let l = w(t, c, i).map(({ indexColumn: e, column: t }) => ({ name: `${s}${t.name}${s} ${g(e.orderType)}` }));
513
- if (l.length !== 0) {
514
- let t = i.name;
515
- if (i.name.trim() === "") {
516
- let r = n(c.name, e);
517
- t = R(a, `IDX_${r}`), a.push({
518
- id: A(),
519
- name: t
520
- });
521
- }
522
- r.push(`CREATE ${i.unique ? "UNIQUE " : ""}INDEX${I(o)} ${s}${t}${s}`), r.push(` ON ${s}${c.name}${s} (${F(l)});`);
523
- }
524
- }
525
- //#endregion
526
- //#region src/utils/schema-sql/MSSQL.ts
527
- var At = G(V.MSSQL), jt = "dbo";
528
- function Mt(e, t, { written: n } = {}) {
529
- let r = [], i = [], a = [""], { tables: s, relationships: c, indexes: l } = o(e, t);
530
- return s.forEach((t) => {
531
- n?.tables.push(t), Nt(e, {
532
- table: t,
533
- buffer: a
534
- }), a.push(""), Pt(e, {
535
- table: t,
536
- buffer: a
537
- }), Bt(e, {
538
- table: t,
539
- buffer: a
540
- });
541
- }), c.forEach((t) => {
542
- Vt(e, {
543
- relationship: t,
544
- buffer: a,
545
- fkNames: r
546
- }) && a.push("");
547
- }), l.forEach((t) => {
548
- Ht(e, {
549
- index: t,
550
- buffer: a,
551
- indexNames: i
552
- }), a.push("");
553
- }), a.join("\n");
554
- }
555
- function Nt(e, { buffer: t, table: r }) {
556
- let { settings: { bracketType: i }, collections: a } = e, o = z(i), s = B(a).collection("tableColumnEntities").selectByIds(r.columnIds);
557
- t.push(`CREATE TABLE ${o}${r.name}${o}`), t.push("(");
558
- let c = S(s), l = O(s);
559
- if (s.forEach((n, r) => {
560
- c ? Ft(e, {
561
- column: n,
562
- isComma: !0,
563
- spaceSize: l,
564
- buffer: t
565
- }) : Ft(e, {
566
- column: n,
567
- isComma: s.length !== r + 1,
568
- spaceSize: l,
569
- buffer: t
570
- });
571
- }), c) {
572
- let e = U(s), a = `PK_${n(r.name, i)}`;
573
- t.push(` CONSTRAINT ${o}${a}${o} PRIMARY KEY (${F(e, o)})`);
574
- }
575
- t.push(")\nGO");
576
- }
577
- function Pt({ settings: { bracketType: e }, collections: t }, { buffer: r, table: i }) {
578
- let a = z(e), o = B(t).collection("tableColumnEntities").selectByIds(i.columnIds);
579
- p(o) && N(o).forEach((t) => {
580
- r.push(`ALTER TABLE ${a}${i.name}${a}`), r.push(` ADD CONSTRAINT ${a}UQ_${n(i.name, e)}_${t.name}${a} UNIQUE (${a}${t.name}${a})\nGO`), r.push("");
581
- });
582
- }
583
- function Ft({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
584
- let a = z(e), o = [];
585
- o.push(` ${a}${n.name}${a}` + k(i.name - n.name.length)), o.push(`${n.dataType}` + k(i.dataType - n.dataType.length)), M(n.options, x.notNull) && o.push("NOT NULL"), M(n.options, x.autoIncrement) ? o.push("IDENTITY(1,1)") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), t.push(o.join(" ") + `${r ? "," : ""}`);
586
- }
587
- var It = /^[\p{L}_@#][\p{L}\p{N}_@#$]*$/u;
588
- function Lt(e) {
589
- return se(e) || It.test(e);
590
- }
591
- function Rt(e, t) {
592
- if (t) return "";
593
- let [, , n = ""] = xe(e).reverse();
594
- return Lt(n) ? `${n}.` : "";
595
- }
596
- function zt(t, n) {
597
- let [r, a = ""] = n ? [t] : xe(t).reverse(), o = e(a) || jt, s = n ? r : e(r);
598
- return {
599
- procedure: `${Rt(t, n)}sys.sp_addextendedproperty`,
600
- levels: `'schema', ${i(o)}, 'table', ${i(s)}`
601
- };
602
- }
603
- function Bt({ settings: { bracketType: e }, collections: t }, { table: n, buffer: r }) {
604
- let { procedure: a, levels: o } = zt(n.name, z(e));
605
- n.comment.trim() !== "" && (r.push(`EXECUTE ${a} 'MS_Description',`), r.push(` ${i(n.comment)}, ${o}\nGO`), r.push("")), B(t).collection("tableColumnEntities").selectByIds(n.columnIds).forEach((e) => {
606
- e.comment.trim() !== "" && (r.push(`EXECUTE ${a} 'MS_Description',`), r.push(` ${i(e.comment)}, ${o}, 'column', ${i(e.name)}\nGO`), r.push(""));
607
- });
608
- }
609
- function Vt(e, { buffer: t, relationship: r, fkNames: i }) {
610
- let { settings: { bracketType: a } } = e, o = W(e, r);
611
- if (!o) return !1;
612
- let { startTable: s, endTable: c } = o, l = z(a);
613
- t.push(`ALTER TABLE ${l}${c.name}${l}`);
614
- let u = n(s.name, a), d = n(c.name, a), f = R(i, `FK_${u}_TO_${d}`);
615
- return i.push({
616
- id: A(),
617
- name: f
618
- }), t.push(` ADD CONSTRAINT ${l}${f}${l}`), t.push(` FOREIGN KEY (${F(o.end, l)})`), t.push(` REFERENCES ${l}${s.name}${l} (${F(o.start, l)})`, ...H(r, At).map((e) => ` ${e}`)), t[t.length - 1] += "\nGO", !0;
619
- }
620
- function Ht({ settings: { bracketType: e }, collections: t }, { buffer: r, index: i, indexNames: a }) {
621
- let o = z(e), s = B(t).collection("tableEntities").selectById(i.tableId);
622
- if (!s) return;
623
- let c = w(t, s, i).map(({ indexColumn: e, column: t }) => ({ name: `${o}${t.name}${o} ${g(e.orderType)}` }));
624
- if (c.length !== 0) {
625
- let t = i.name;
626
- if (i.name.trim() === "") {
627
- let r = n(s.name, e);
628
- t = R(a, `IDX_${r}`), a.push({
629
- id: A(),
630
- name: t
631
- });
632
- }
633
- i.unique ? r.push(`CREATE UNIQUE INDEX ${o}${t}${o}`) : r.push(`CREATE INDEX ${o}${t}${o}`), r.push(` ON ${o}${s.name}${o} (${F(c)})\nGO`);
634
- }
635
- }
636
- function Ut({ settings: { bracketType: e } }, t, n) {
637
- let r = z(e), a = `${r}${n}${r}`, o = `USE ${a}\nGO`;
638
- return t === j.createAndUse ? `IF DB_ID(N${i(n)}) IS NULL\n CREATE DATABASE ${a}\nGO\n\n${o}` : o;
639
- }
640
- function Wt({ settings: { bracketType: e } }, { tables: t }) {
641
- if (t.length === 0) return "";
642
- let n = z(e), r = (e) => `${n}${e}${n}`;
643
- return [
644
- "BEGIN TRY",
645
- " BEGIN TRANSACTION",
646
- "",
647
- " DECLARE @sql NVARCHAR(MAX) = N''",
648
- ...t.flatMap(({ name: e }) => {
649
- let t = Rt(e, n), a = `OBJECT_ID(N${i(r(e))}, N'U')`, o = [
650
- `SELECT @sql += N${i(`ALTER TABLE ${r(e)} DROP CONSTRAINT `)} + QUOTENAME(name) + N';'`,
651
- ` FROM ${t}sys.foreign_keys`,
652
- ` WHERE parent_object_id = ${a}`
653
- ];
654
- return t ? [` IF ${a} IS NOT NULL`, ...o.map((e) => ` ${e}`)] : o.map((e) => ` ${e}`);
655
- }),
656
- " EXECUTE sp_executesql @sql",
657
- "",
658
- ` DROP TABLE IF EXISTS ${t.map(({ name: e }) => r(e)).join(", ")}`,
659
- "",
660
- " COMMIT TRANSACTION",
661
- "END TRY",
662
- "BEGIN CATCH",
663
- " IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;",
664
- " THROW;",
665
- "END CATCH",
666
- "GO"
667
- ].join("\n");
668
- }
669
- //#endregion
670
- //#region src/utils/schema-sql/Oracle.ts
671
- var Gt = G(V.Oracle);
672
- function Kt(e, t, { written: r } = {}) {
673
- let { settings: { bracketType: i }, collections: a } = e, s = [], c = [], l = [], u = [], d = [""], { tables: f, relationships: p, indexes: h } = o(e, t);
674
- return f.forEach((t) => {
675
- r?.tables.push(t), qt(e, {
676
- table: t,
677
- buffer: d,
678
- written: r
679
- }), d.push(""), Jt(e, {
680
- table: t,
681
- buffer: d,
682
- written: r
683
- });
684
- let o = B(a).collection("tableColumnEntities").selectByIds(t.columnIds), [s] = m(t.name, i), u = n(t.name, i), f = s === "" ? "" : `${s}.`;
685
- o.forEach((e) => {
686
- if (M(e.options, x.autoIncrement)) {
687
- let n = C(c, "", `SEQ_${u}`);
688
- c.push({
689
- id: A(),
690
- name: n
691
- });
692
- let i = `${f}${n}`;
693
- r?.sequences.push(i), r?.identifiers.push(n), d.push(`CREATE SEQUENCE ${i}`), d.push("START WITH 1"), d.push("INCREMENT BY 1;"), d.push("");
694
- let a = C(c, "", `SEQ_TRG_${u}`);
695
- l.push({
696
- id: A(),
697
- name: a
698
- }), r?.identifiers.push(a), d.push(`CREATE OR REPLACE TRIGGER ${f}${a}`), d.push(`BEFORE INSERT ON ${t.name}`), d.push("REFERENCING NEW AS NEW FOR EACH ROW"), d.push("BEGIN"), d.push(` SELECT ${i}.NEXTVAL`), d.push(` INTO :NEW.${e.name}`), d.push(" FROM DUAL;"), d.push("END;"), d.push("/"), d.push("");
699
- }
700
- }), Xt(e, {
701
- table: t,
702
- buffer: d
703
- });
704
- }), p.forEach((t) => {
705
- Zt(e, {
706
- relationship: t,
707
- buffer: d,
708
- fkNames: s,
709
- written: r
710
- }) && d.push("");
711
- }), h.forEach((t) => {
712
- Qt(e, {
713
- index: t,
714
- buffer: d,
715
- indexNames: u,
716
- written: r
717
- }), d.push("");
718
- }), d.join("\n");
719
- }
720
- function qt(t, { buffer: r, table: i, written: a }) {
721
- let { settings: { bracketType: o }, collections: s } = t, c = z(o), l = B(s).collection("tableColumnEntities").selectByIds(i.columnIds);
722
- if (a) {
723
- let [t, n] = m(i.name, o);
724
- t !== "" && a.identifiers.push(e(t)), a.identifiers.push(e(n)), a.identifiers.push(...l.map((e) => e.name));
725
- }
726
- r.push(`CREATE TABLE ${c}${i.name}${c}`), r.push("(");
727
- let u = S(l), d = O(l);
728
- if (l.forEach((e, n) => {
729
- u ? Yt(t, {
730
- column: e,
731
- isComma: !0,
732
- spaceSize: d,
733
- buffer: r
734
- }) : Yt(t, {
735
- column: e,
736
- isComma: l.length !== n + 1,
737
- spaceSize: d,
738
- buffer: r
739
- });
740
- }), u) {
741
- let e = U(l), t = `PK_${n(i.name, o)}`;
742
- a?.identifiers.push(t), r.push(` CONSTRAINT ${c}${t}${c} PRIMARY KEY (${F(e, c)})`);
743
- }
744
- r.push(");");
745
- }
746
- function Jt({ settings: { bracketType: e }, collections: t }, { buffer: r, table: i, written: a }) {
747
- let o = z(e), s = B(t).collection("tableColumnEntities").selectByIds(i.columnIds);
748
- p(s) && N(s).forEach((t) => {
749
- let s = `UQ_${n(i.name, e)}_${t.name}`;
750
- a?.identifiers.push(s), r.push(`ALTER TABLE ${o}${i.name}${o}`), r.push(` ADD CONSTRAINT ${o}${s}${o} UNIQUE (${o}${t.name}${o});`), r.push("");
751
- });
752
- }
753
- function Yt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
754
- let a = z(e), o = [];
755
- o.push(` ${a}${n.name}${a}` + k(i.name - n.name.length)), o.push(`${n.dataType}` + k(i.dataType - n.dataType.length)), n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), M(n.options, x.notNull) && o.push("NOT NULL"), t.push(o.join(" ") + `${r ? "," : ""}`);
756
- }
757
- function Xt({ settings: { bracketType: e }, collections: t }, { table: n, buffer: r }) {
758
- let a = z(e);
759
- n.comment.trim() !== "" && (r.push(`COMMENT ON TABLE ${a}${n.name}${a} IS ${i(n.comment)};`), r.push("")), B(t).collection("tableColumnEntities").selectByIds(n.columnIds).forEach((e) => {
760
- e.comment.trim() !== "" && (r.push(`COMMENT ON COLUMN ${a}${n.name}${a}.${a}${e.name}${a} IS ${i(e.comment)};`), r.push(""));
761
- });
762
- }
763
- function Zt(e, { buffer: t, relationship: r, fkNames: i, written: a }) {
764
- let { settings: { bracketType: o } } = e, s = W(e, r);
765
- if (!s) return !1;
766
- let { startTable: c, endTable: l } = s, u = z(o);
767
- t.push(`ALTER TABLE ${u}${l.name}${u}`);
768
- let d = n(c.name, o), f = n(l.name, o), p = R(i, `FK_${d}_TO_${f}`);
769
- return i.push({
770
- id: A(),
771
- name: p
772
- }), a?.identifiers.push(p), t.push(` ADD CONSTRAINT ${u}${p}${u}`), t.push(` FOREIGN KEY (${F(s.end, u)})`), t.push(` REFERENCES ${u}${c.name}${u} (${F(s.start, u)})`, ...H(r, Gt).map((e) => ` ${e}`)), t[t.length - 1] += ";", !0;
773
- }
774
- function Qt({ settings: { bracketType: e }, collections: t }, { buffer: r, index: i, indexNames: a, written: o }) {
775
- let s = z(e), c = B(t).collection("tableEntities").selectById(i.tableId);
776
- if (!c) return;
777
- let l = w(t, c, i).map(({ indexColumn: e, column: t }) => ({ name: `${s}${t.name}${s} ${g(e.orderType)}` }));
778
- if (l.length !== 0) {
779
- let [t] = m(c.name, e), u = i.name;
780
- if (i.name.trim() === "") {
781
- let t = n(c.name, e);
782
- u = R(a, `IDX_${t}`), a.push({
783
- id: A(),
784
- name: u
785
- });
786
- }
787
- let d = `${t === "" || u.includes(".") ? "" : `${t}.`}${s}${u}${s}`;
788
- o?.identifiers.push(u.slice(u.lastIndexOf(".") + 1)), i.unique ? r.push(`CREATE UNIQUE INDEX ${d}`) : r.push(`CREATE INDEX ${d}`), r.push(` ON ${s}${c.name}${s} (${F(l)});`);
789
- }
790
- }
791
- function $t(e, t) {
792
- let n = ve();
793
- Kt(e, t, { written: n });
794
- let r = new TextEncoder();
795
- return [...new Set(n.identifiers)].filter((e) => r.encode(e).length > 30);
796
- }
797
- function en({ settings: { bracketType: e } }, t, n) {
798
- if (t !== j.use) return "";
799
- let r = z(e);
800
- return `ALTER SESSION SET CURRENT_SCHEMA = ${r}${n}${r};`;
801
- }
802
- function tn(e, t) {
803
- return [
804
- "BEGIN",
805
- ` EXECUTE IMMEDIATE ${i(e)};`,
806
- "EXCEPTION WHEN OTHERS THEN",
807
- ` IF SQLCODE != ${t} THEN RAISE; END IF;`,
808
- "END;",
809
- "/"
810
- ].join("\n");
811
- }
812
- function nn({ settings: { bracketType: e } }, { tables: t, sequences: n }) {
813
- if (t.length === 0) return "";
814
- let r = z(e);
815
- return [...t.map(({ name: e }) => tn(`DROP TABLE ${r}${e}${r} CASCADE CONSTRAINTS`, -942)), ...n.map((e) => tn(`DROP SEQUENCE ${e}`, -2289))].join("\n\n");
816
- }
817
- //#endregion
818
- //#region src/utils/schema-sql/PostgreSQL.ts
819
- var rn = G(V.PostgreSQL), an = /* @__PURE__ */ new Set([
820
- "INT",
821
- "INTEGER",
822
- "BIGINT",
823
- "SMALLINT",
824
- "INT2",
825
- "INT4",
826
- "INT8"
827
- ]);
828
- function on(e) {
829
- return M(e.options, x.autoIncrement) && an.has(e.dataType.trim().toUpperCase());
830
- }
831
- function sn(e, t, { statements: n, written: r } = {}) {
832
- let i = [], a = [], s = [""], { tables: c, relationships: l, indexes: u } = o(e, t);
833
- return c.forEach((t) => {
834
- r?.tables.push(t), cn(e, {
835
- table: t,
836
- buffer: s,
837
- statements: n
838
- }), s.push(""), un(e, {
839
- table: t,
840
- buffer: s
841
- });
842
- }), l.forEach((t) => {
843
- dn(e, {
844
- relationship: t,
845
- buffer: s,
846
- fkNames: i,
847
- statements: n
848
- }) && s.push("");
849
- }), u.forEach((t) => {
850
- fn(e, {
851
- index: t,
852
- buffer: s,
853
- indexNames: a,
854
- statements: n
855
- }), s.push("");
856
- }), s.join("\n");
857
- }
858
- function cn(e, { buffer: t, table: n, statements: r }) {
859
- let { settings: { bracketType: i }, collections: a } = e, o = z(i), s = B(a).collection("tableColumnEntities").selectByIds(n.columnIds);
860
- t.push(`CREATE TABLE${I(r)} ${o}${n.name}${o}`), t.push("(");
861
- let c = S(s), l = O(s);
862
- if (s.forEach((n, r) => {
863
- c ? ln(e, {
864
- column: n,
865
- isComma: !0,
866
- spaceSize: l,
867
- buffer: t
868
- }) : ln(e, {
869
- column: n,
870
- isComma: s.length !== r + 1,
871
- spaceSize: l,
872
- buffer: t
873
- });
874
- }), c) {
875
- let e = U(s);
876
- t.push(` PRIMARY KEY (${F(e, o)})`);
877
- }
878
- t.push(");");
879
- let u = s.filter((e) => M(e.options, x.autoIncrement) && !on(e));
880
- u.length !== 0 && (t.push(""), u.forEach((e) => {
881
- t.push(`-- PostgreSQL takes IDENTITY only on smallint, integer or bigint, so ${o}${n.name}${o}.${o}${e.name}${o} is written without it.`);
882
- }));
883
- }
884
- function ln({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
885
- let a = z(e), o = [];
886
- o.push(` ${a}${n.name}${a}` + k(i.name - n.name.length)), o.push(`${n.dataType}` + k(i.dataType - n.dataType.length)), M(n.options, x.notNull) && o.push("NOT NULL"), M(n.options, x.autoIncrement) ? on(n) && o.push("GENERATED ALWAYS AS IDENTITY") : n.default.trim() !== "" && o.push(`DEFAULT ${E(n.default, V.PostgreSQL)}`), M(n.options, x.unique) && o.push("UNIQUE"), t.push(o.join(" ") + `${r ? "," : ""}`);
887
- }
888
- function un({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
889
- let a = z(e);
890
- r.comment.trim() !== "" && (n.push(`COMMENT ON TABLE ${a}${r.name}${a} IS ${i(r.comment)};`), n.push("")), B(t).collection("tableColumnEntities").selectByIds(r.columnIds).forEach((e) => {
891
- e.comment.trim() !== "" && (n.push(`COMMENT ON COLUMN ${a}${r.name}${a}.${a}${e.name}${a} IS ${i(e.comment)};`), n.push(""));
892
- });
893
- }
894
- function dn(e, { buffer: t, relationship: r, fkNames: i, statements: a }) {
895
- let { settings: { bracketType: o } } = e, s = W(e, r);
896
- if (!s) return !1;
897
- let { startTable: c, endTable: l } = s, u = z(o), d = n(c.name, o), p = n(l.name, o), m = R(i, `FK_${d}_TO_${p}`);
898
- i.push({
899
- id: A(),
900
- name: m
901
- });
902
- let h = `ALTER TABLE ${u}${l.name}${u}`;
903
- return a === f.ifNotExists && t.push(`${h} DROP CONSTRAINT IF EXISTS ${u}${m}${u};`), t.push(h), t.push(` ADD CONSTRAINT ${u}${m}${u}`), t.push(` FOREIGN KEY (${F(s.end, u)})`), t.push(` REFERENCES ${u}${c.name}${u} (${F(s.start, u)})`, ...H(r, rn).map((e) => ` ${e}`)), t[t.length - 1] += ";", !0;
904
- }
905
- function fn({ settings: { bracketType: e }, collections: t }, { buffer: r, index: i, indexNames: a, statements: o }) {
906
- let s = z(e), c = B(t).collection("tableEntities").selectById(i.tableId);
907
- if (!c) return;
908
- let l = w(t, c, i).map(({ indexColumn: e, column: t }) => ({ name: `${s}${t.name}${s} ${g(e.orderType)}` }));
909
- if (l.length !== 0) {
910
- let t = i.name;
911
- if (i.name.trim() === "") {
912
- let r = n(c.name, e);
913
- t = R(a, `IDX_${r}`), a.push({
914
- id: A(),
915
- name: t
916
- });
917
- }
918
- r.push(`CREATE ${i.unique ? "UNIQUE " : ""}INDEX${I(o)} ${s}${t}${s}`), r.push(` ON ${s}${c.name}${s} (${F(l)});`);
919
- }
920
- }
921
- function pn({ settings: { bracketType: e } }, t, n) {
922
- if (t !== j.createAndUse) return "";
923
- let r = z(e), i = `${r}${n}${r}`;
924
- return `CREATE SCHEMA IF NOT EXISTS ${i};\nSET search_path TO ${i}, public;`;
925
- }
926
- function mn({ settings: { bracketType: e } }, { tables: t }, n, r) {
927
- if (t.length === 0) return "";
928
- let i = z(e), a = n === j.createAndUse ? `${i}${r}${i}.` : "";
929
- return `DROP TABLE IF EXISTS ${t.map(({ name: t }) => {
930
- let [n] = m(t, e);
931
- return `${n === "" ? a : ""}${i}${t}${i}`;
932
- }).join(", ")};`;
933
- }
934
- //#endregion
935
- //#region src/utils/schema-sql/Snowflake.ts
936
- var hn = G(V.Snowflake), $ = (e) => z(e) === "" ? "" : "\"";
937
- function gn(e, t, { statements: n, written: r } = {}) {
938
- let i = [], a = [], s = [""], { tables: c, relationships: l, indexes: u } = o(e, t);
939
- return c.forEach((t) => {
940
- r?.tables.push(t), _n(e, {
941
- table: t,
942
- buffer: s,
943
- statements: n
944
- }), s.push("");
945
- }), l.forEach((t) => {
946
- yn(e, {
947
- relationship: t,
948
- buffer: s,
949
- fkNames: i
950
- }) && s.push("");
951
- }), u.forEach((t) => {
952
- xn(e, {
953
- index: t,
954
- buffer: s,
955
- indexNames: a
956
- }), s.push("");
957
- }), s.join("\n");
958
- }
959
- function _n(e, { buffer: t, table: n, statements: r }) {
960
- let { collections: a, settings: { bracketType: o } } = e, s = $(o), c = B(a).collection("tableColumnEntities").selectByIds(n.columnIds), l = r === f.recreate ? "CREATE OR REPLACE TABLE" : "CREATE TABLE";
961
- t.push(`${l} ${s}${n.name}${s}`), t.push("(");
962
- let u = S(c), d = O(c);
963
- if (c.forEach((n, r) => {
964
- vn(e, {
965
- column: n,
966
- isComma: u || c.length !== r + 1,
967
- spaceSize: d,
968
- buffer: t
969
- });
970
- }), u) {
971
- let e = U(c);
972
- t.push(` CONSTRAINT ${s}PK_${n.name}${s} PRIMARY KEY (${F(e, s)})`);
973
- }
974
- n.comment.trim() === "" ? t.push(");") : (t.push(")"), t.push(`COMMENT = ${i(n.comment)};`));
975
- }
976
- function vn({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: a }) {
977
- let o = $(e), s = [];
978
- s.push(` ${o}${n.name}${o}` + k(a.name - n.name.length)), s.push(`${n.dataType}` + k(a.dataType - n.dataType.length)), M(n.options, x.unique) && s.push("UNIQUE");
979
- let c = M(n.options, x.notNull) || M(n.options, x.primaryKey);
980
- s.push(c ? "NOT NULL" : " "), M(n.options, x.autoIncrement) ? s.push("AUTOINCREMENT") : n.default.trim() !== "" && s.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && s.push(`COMMENT ${i(n.comment)}`), t.push(s.join(" ").trimEnd() + `${r ? "," : ""}`);
981
- }
982
- function yn(e, { buffer: t, relationship: n, fkNames: r }) {
983
- let { settings: { bracketType: i } } = e, a = W(e, n);
984
- if (!a) return !1;
985
- let { startTable: o, endTable: s } = a, c = $(i), l = bn(n);
986
- l.length !== 0 && t.push(`-- Snowflake creates no foreign key with a referential action other than NO ACTION, so ${l.join(" and ")} ${l.length === 1 ? "is" : "are"} left out.`), t.push(`ALTER TABLE ${c}${s.name}${c}`);
987
- let u = `FK_${o.name}_TO_${s.name}`;
988
- return u = C(r, "", u), r.push({
989
- id: A(),
990
- name: u
991
- }), t.push(` ADD CONSTRAINT ${c}${u}${c}`), t.push(` FOREIGN KEY (${F(a.end, c)})`), t.push(` REFERENCES ${c}${o.name}${c} (${F(a.start, c)})`, ...H(n, hn).map((e) => ` ${e}`)), t[t.length - 1] += ";", !0;
992
- }
993
- function bn({ onDelete: e, onUpdate: t }) {
994
- let n = [];
995
- return D[e] && !hn.onDelete.includes(e) && n.push(`ON DELETE ${D[e]}`), D[t] && !hn.onUpdate.includes(t) && n.push(`ON UPDATE ${D[t]}`), n;
996
- }
997
- function xn({ collections: e, settings: { bracketType: t } }, { buffer: n, index: r, indexNames: i }) {
998
- let a = $(t), o = B(e).collection("tableEntities").selectById(r.tableId);
999
- if (!o) return;
1000
- let s = w(e, o, r), c = s.map(({ column: e }) => e);
1001
- if (c.length === 0) return;
1002
- let l = r.name;
1003
- if (r.name.trim() === "" && (l = `IDX_${o.name}`, l = C(i, "", l), i.push({
1004
- id: A(),
1005
- name: l
1006
- })), r.unique) {
1007
- n.push(`ALTER TABLE ${a}${o.name}${a}`), n.push(` ADD CONSTRAINT ${a}${l}${a} UNIQUE (${F(c, a)});`);
1008
- return;
1009
- }
1010
- let u = s.map(({ indexColumn: e, column: t }) => ({ name: `${a}${t.name}${a} ${g(e.orderType)}` }));
1011
- n.push(`-- Snowflake has no secondary indexes. ${a}${l}${a} on ${a}${o.name}${a} (${F(u)})`), n.push(`-- ALTER TABLE ${a}${o.name}${a} CLUSTER BY (${F(c, a)});`);
1012
- }
1013
- function Sn({ settings: { bracketType: e } }, t, n) {
1014
- let r = $(e), i = `${r}${n}${r}`, a = `USE SCHEMA ${i};`;
1015
- return t === j.createAndUse ? `CREATE SCHEMA IF NOT EXISTS ${i};\n${a}` : a;
1016
- }
1017
- function Cn() {
1018
- return "";
1019
- }
1020
- //#endregion
1021
- //#region src/utils/schema-sql/SQLite.ts
1022
- var wn = G(V.SQLite);
1023
- function Tn(e, t, { statements: n, written: r } = {}) {
1024
- let i = [], a = [""], { tables: s, indexes: c } = o(e, t);
1025
- return s.forEach((t) => {
1026
- r?.tables.push(t), Dn(e, {
1027
- table: t,
1028
- buffer: a,
1029
- statements: n
1030
- }), a.push("");
1031
- }), c.forEach((t) => {
1032
- kn(e, {
1033
- index: t,
1034
- buffer: a,
1035
- indexNames: i,
1036
- statements: n
1037
- }), a.push("");
1038
- }), a.join("\n");
1039
- }
1040
- function En(e) {
1041
- return /^(?:(?:TINY|SMALL|MEDIUM|BIG)?INT(?:EGER)?|INT[248]|UNSIGNED\s+BIG\s+INT)(?:\s*\(\s*\d+\s*\))?$/i.test(e.trim());
1042
- }
1043
- function Dn(e, { buffer: t, table: n, statements: r }) {
1044
- let { settings: { bracketType: i }, doc: { relationshipIds: a }, collections: o } = e, s = z(i), c = B(o).collection("tableColumnEntities").selectByIds(n.columnIds), l = U(c), u = l.length === 1 && M(l[0].options, x.autoIncrement) ? l[0] : null, d = u !== null && En(u.dataType), f = d ? c.map((e) => e === u ? {
1045
- ...e,
1046
- dataType: "INTEGER"
1047
- } : e) : c, p = B(o).collection("relationshipEntities").selectByIds(a).filter(({ end: e }) => e.tableId === n.id).flatMap((t) => {
1048
- let n = W(e, t);
1049
- return n ? [{
1050
- relationship: t,
1051
- ...n
1052
- }] : [];
1053
- }), h = p.length !== 0;
1054
- n.comment.trim() !== "" && t.push(`-- ${n.comment}`), t.push(`CREATE TABLE${I(r)} ${s}${n.name}${s}`), t.push("(");
1055
- let g = S(f), _ = O(f);
1056
- if (f.forEach((n, r) => {
1057
- On(e, {
1058
- column: n,
1059
- isComma: g || h || f.length !== r + 1,
1060
- spaceSize: _,
1061
- buffer: t
1062
- });
1063
- }), g) {
1064
- let e = d ? " AUTOINCREMENT" : "";
1065
- t.push(` PRIMARY KEY (${F(l, s)}${e})` + (h ? "," : ""));
1066
- }
1067
- p.forEach(({ relationship: e, startTable: n, start: r, end: a }, o) => {
1068
- let c = H(e, wn).map((e) => ` ${e}`).join(""), [, l] = m(n.name, i);
1069
- t.push(` FOREIGN KEY (${F(a, s)}) REFERENCES ${s}${l}${s} (${F(r, s)})${c}` + (p.length - 1 > o ? "," : ""));
1070
- }), t.push(");"), u !== null && !d && (t.push(""), t.push(`-- SQLite takes AUTOINCREMENT only on an INTEGER column, so ${s}${n.name}${s}.${s}${u.name}${s} is written without it.`));
1071
- }
1072
- function On({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
1073
- let a = z(e), o = [];
1074
- n.comment.trim() !== "" && t.push(` -- ${n.comment}`), o.push(` ${a}${n.name}${a}` + k(i.name - n.name.length)), o.push(`${n.dataType}` + k(i.dataType - n.dataType.length)), o.push(`${M(n.options, x.notNull) ? "NOT NULL" : "NULL "}`), M(n.options, x.unique) && o.push("UNIQUE"), !M(n.options, x.autoIncrement) && n.default.trim() !== "" && o.push(`DEFAULT ${E(n.default, V.SQLite)}`), t.push(o.join(" ") + `${r ? "," : ""}`);
1075
- }
1076
- function kn({ settings: { bracketType: e }, collections: t }, { buffer: r, index: i, indexNames: a, statements: o }) {
1077
- let s = z(e), c = B(t).collection("tableEntities").selectById(i.tableId);
1078
- if (!c) return;
1079
- let l = w(t, c, i).map(({ indexColumn: e, column: t }) => ({ name: `${s}${t.name}${s} ${g(e.orderType)}` }));
1080
- if (l.length !== 0) {
1081
- let [t, u] = m(c.name, e), d = i.name;
1082
- if (i.name.trim() === "") {
1083
- let t = n(c.name, e);
1084
- d = R(a, `IDX_${t}`), a.push({
1085
- id: A(),
1086
- name: d
1087
- });
1088
- }
1089
- let f = `${t === "" || d.includes(".") ? "" : `${t}.`}${s}${d}${s}`;
1090
- r.push(`CREATE ${i.unique ? "UNIQUE " : ""}INDEX${I(o)} ${f}`), r.push(` ON ${s}${u}${s} (${F(l)});`);
1091
- }
1092
- }
1093
- function An() {
1094
- return "";
1095
- }
1096
- function jn({ settings: { bracketType: e } }, { tables: t }) {
1097
- if (t.length === 0) return "";
1098
- let n = z(e);
1099
- return ["PRAGMA foreign_keys=OFF;", t.map(({ name: e }) => `DROP TABLE IF EXISTS ${n}${e}${n};`).join("\n")].join("\n\n");
1100
- }
1101
- //#endregion
1102
- //#region src/utils/schema-sql/index.ts
1103
- var Mn = {
1104
- [V.Databricks]: {
1105
- createSchema: $e,
1106
- formatHeader: at,
1107
- formatDropBlock: ot
1108
- },
1109
- [V.MariaDB]: {
1110
- createSchema: wt,
1111
- formatHeader: xt,
1112
- formatDropBlock: St
1113
- },
1114
- [V.MSSQL]: {
1115
- createSchema: Mt,
1116
- formatHeader: Ut,
1117
- formatDropBlock: Wt
1118
- },
1119
- [V.MySQL]: {
1120
- createSchema: ut,
1121
- formatHeader: xt,
1122
- formatDropBlock: St
1123
- },
1124
- [V.Oracle]: {
1125
- createSchema: Kt,
1126
- formatHeader: en,
1127
- formatDropBlock: nn
1128
- },
1129
- [V.PostgreSQL]: {
1130
- createSchema: sn,
1131
- formatHeader: pn,
1132
- formatDropBlock: mn
1133
- },
1134
- [V.Snowflake]: {
1135
- createSchema: gn,
1136
- formatHeader: Sn,
1137
- formatDropBlock: Cn
1138
- },
1139
- [V.SQLite]: {
1140
- createSchema: Tn,
1141
- formatHeader: An,
1142
- formatDropBlock: jn
1143
- }
1144
- };
1145
- function Nn(e) {
1146
- return e === "" ? "" : e.slice(1, -1);
1147
- }
1148
- function Pn(e, t, n, r) {
1149
- let i = t || e.settings.database, a = Mn[i];
1150
- if (!a) return "";
1151
- let { databaseName: o } = e.settings, l = c(i, r, o), u = ve(), d = Nn(a.createSchema(e, n, {
1152
- statements: l.statements,
1153
- written: u
1154
- })), p = r?.scripts ?? n === void 0 ? e.settings.ddlScripts : void 0, m = s(p?.before ?? "", i), h = s(p?.after ?? "", i), g = l.headerName === "valid" ? l.header : j.none, _ = l.statements === f.recreate ? a.formatDropBlock(e, u, g, o) : "";
1155
- return !m && !_ && !d && !h ? "" : `\n${[
1156
- g === j.none ? "" : a.formatHeader(e, g, o),
1157
- m,
1158
- _,
1159
- h ? d.replace(/\n+$/, "") : d,
1160
- h
1161
- ].filter(Boolean).join("\n\n")}\n`;
1162
- }
1163
- function Fn(e, t) {
1164
- return o(e, t).tables.map((e) => e.name);
1165
- }
1166
- function In(e, t) {
1167
- let { settings: n, doc: { indexIds: r }, collections: i } = e, a = [""], o = n.database, s = [], c = B(i).collection("indexEntities").selectByIds(r).filter((e) => e.tableId === t.id);
1168
- switch (o) {
1169
- case V.Databricks:
1170
- et(e, {
1171
- buffer: a,
1172
- table: t
1173
- }), a.push(""), tt(e, {
1174
- buffer: a,
1175
- table: t
1176
- }), c.forEach((t) => {
1177
- it(e, {
1178
- index: t,
1179
- buffer: a,
1180
- indexNames: s
1181
- }), a.push("");
1182
- });
1183
- break;
1184
- case V.MariaDB:
1185
- Tt(e, {
1186
- buffer: a,
1187
- table: t
1188
- }), a.push(""), Et(e, {
1189
- buffer: a,
1190
- table: t
1191
- }), c.forEach((t) => {
1192
- kt(e, {
1193
- index: t,
1194
- buffer: a,
1195
- indexNames: s
1196
- }), a.push("");
1197
- });
1198
- break;
1199
- case V.MSSQL:
1200
- Nt(e, {
1201
- buffer: a,
1202
- table: t
1203
- }), a.push(""), Pt(e, {
1204
- buffer: a,
1205
- table: t
1206
- }), c.forEach((t) => {
1207
- Ht(e, {
1208
- index: t,
1209
- buffer: a,
1210
- indexNames: s
1211
- }), a.push("");
1212
- });
1213
- break;
1214
- case V.MySQL:
1215
- ft(e, {
1216
- buffer: a,
1217
- table: t
1218
- }), a.push(""), ht(e, {
1219
- buffer: a,
1220
- table: t
1221
- }), c.forEach((t) => {
1222
- bt(e, {
1223
- index: t,
1224
- buffer: a,
1225
- indexNames: s
1226
- }), a.push("");
1227
- });
1228
- break;
1229
- case V.Oracle:
1230
- qt(e, {
1231
- buffer: a,
1232
- table: t
1233
- }), a.push(""), Jt(e, {
1234
- buffer: a,
1235
- table: t
1236
- }), c.forEach((t) => {
1237
- Qt(e, {
1238
- index: t,
1239
- buffer: a,
1240
- indexNames: s
1241
- }), a.push("");
1242
- });
1243
- break;
1244
- case V.PostgreSQL:
1245
- cn(e, {
1246
- buffer: a,
1247
- table: t
1248
- }), a.push(""), c.forEach((t) => {
1249
- fn(e, {
1250
- index: t,
1251
- buffer: a,
1252
- indexNames: s
1253
- }), a.push("");
1254
- });
1255
- break;
1256
- case V.Snowflake:
1257
- _n(e, {
1258
- buffer: a,
1259
- table: t
1260
- }), a.push(""), c.forEach((t) => {
1261
- xn(e, {
1262
- index: t,
1263
- buffer: a,
1264
- indexNames: s
1265
- }), a.push("");
1266
- });
1267
- break;
1268
- case V.SQLite: Dn(e, {
1269
- buffer: a,
1270
- table: t
1271
- }), a.push(""), c.forEach((t) => {
1272
- kn(e, {
1273
- index: t,
1274
- buffer: a,
1275
- indexNames: s
1276
- }), a.push("");
1277
- });
1278
- }
1279
- return a.join("\n");
1280
- }
1281
- //#endregion
1282
- //#region src/engine/shared-store.ts
1283
- var Ln = 2, Rn = _(be);
1284
- function zn(e, t, n) {
1285
- let r = n?.manualStreamFlush ?? !1, i = { editorId: e.state.editor.id }, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = new q(), c = new q(), l = new q(), u = new q(), d = new q(), f = le(r ? Me(d) : Ne(d)), p = !0, m = !0;
1286
- a.add(Te(new K((t) => e.subscribe((e) => t.next(e))), c).pipe(T(ne), te([y.shared]), f, _e(l, u), f, we((e) => b(y.shared, e.map((e) => {
1287
- let n = {
1288
- ...e,
1289
- meta: Object.assign({}, e.meta ?? {}, {
1290
- ...i,
1291
- nickname: t?.getNickname?.()
1292
- })
1293
- };
1294
- return Rn(e.type) ? v(y.following, n) : n;
1295
- })))).subscribe((e) => s.next(e)));
1296
- let h = () => {
1297
- c.next([{
1298
- ...re(),
1299
- version: e.context.clock.getVersion()
1300
- }]);
1301
- };
1302
- a.add(new K((t) => e.subscribe((e) => t.next(e))).pipe(Ce((e) => !m && e.some(({ type: e }) => e === de.type))).subscribe(h));
1303
- let g = () => {
1304
- let e = 0 < o.size;
1305
- p && e ? l.next() : u.next();
1306
- }, _ = (t) => {
1307
- let n = (Array.isArray(t) ? t : [t]).some((e) => e.type === re.type), r = e.state.lww;
1308
- n && !Ae(r) && c.next([{
1309
- ...ce({ lww: r }),
1310
- version: e.context.clock.getVersion()
1311
- }]);
1312
- };
1313
- return Object.freeze({
1314
- connection: () => {
1315
- p = !0, g();
1316
- },
1317
- disconnect: () => {
1318
- p = !1, g();
1319
- },
1320
- dispatch: (t) => {
1321
- e.dispatch(t), _(t);
1322
- },
1323
- dispatchSync: (t) => {
1324
- e.dispatchSync(t), _(t);
1325
- },
1326
- subscribe: (e) => {
1327
- let t = s.subscribe((t) => e(t));
1328
- return o.add(t), g(), m &&= (h(), !1), () => {
1329
- t.unsubscribe(), o.delete(t), g();
1330
- };
1331
- },
1332
- flushStreamBuffers: () => {
1333
- for (let e = 0; e < Ln; e++) d.next();
1334
- },
1335
- destroy: () => {
1336
- Array.from(a).forEach((e) => e.unsubscribe()), Array.from(o).forEach((e) => e.unsubscribe()), a.clear(), o.clear(), s.complete(), l.complete(), u.complete(), d.complete();
1337
- }
1338
- });
1339
- }
1340
- //#endregion
1341
- export { En as a, He as c, Ke as d, qe as f, X as h, Fn as i, Ue as l, Ve as m, Pn as n, $t as o, Be as p, In as r, We as s, zn as t, Ge as u };