-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.mjs
More file actions
77 lines (70 loc) · 2.2 KB
/
app.mjs
File metadata and controls
77 lines (70 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { sqldef, getFullVersion } from "./sqldef.mjs";
import { schemaExamples } from "./schema_examples.mjs";
const dbType = document.getElementById("dbType");
const enableDrop = document.getElementById("enableDrop");
const inputA = document.getElementById("inputA");
const inputB = document.getElementById("inputB");
const outputUp = document.getElementById("outputUp");
const errorUp = document.getElementById("errorUp");
const outputDown = document.getElementById("outputDown");
const errorDown = document.getElementById("errorDown");
const versionEl = document.getElementById("version");
async function runDiff() {
// Run up diff (current -> desired)
errorUp.classList.add("hidden");
try {
const result = await sqldef(
dbType.value,
inputB.value,
inputA.value,
enableDrop.checked
);
outputUp.textContent = result;
outputUp.className = "language-sql";
Prism.highlightElement(outputUp);
} catch (e) {
outputUp.innerHTML = " ";
errorUp.classList.remove("hidden");
errorUp.innerHTML = e.message;
}
// Run down diff (desired -> current)
errorDown.classList.add("hidden");
try {
const result = await sqldef(
dbType.value,
inputA.value,
inputB.value,
enableDrop.checked
);
outputDown.textContent = result;
outputDown.className = "language-sql";
Prism.highlightElement(outputDown);
} catch (e) {
outputDown.innerHTML = " ";
errorDown.classList.remove("hidden");
errorDown.innerHTML = e.message;
}
}
dbType.addEventListener("change", () => {
const examples = schemaExamples[dbType.value];
if (examples) {
inputA.value = examples.current;
inputB.value = examples.desired;
}
runDiff();
});
inputA.addEventListener("input", runDiff);
inputB.addEventListener("input", runDiff);
enableDrop.addEventListener("change", runDiff);
// Populate textareas and run diff on initial load
const initialExamples = schemaExamples[dbType.value];
if (initialExamples) {
inputA.value = initialExamples.current;
inputB.value = initialExamples.desired;
}
runDiff();
// Display version info
(async () => {
const version = await getFullVersion();
versionEl.textContent = `powered by sqldef v${version}`;
})();