-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
206 lines (173 loc) · 5.78 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SQL to Mermaid ER Diagram</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css" />
<style>
body {
font-family: 'Inter', sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
background-color: #f0f0f5;
}
header {
background-color: #3c40c6;
color: white;
padding: 15px;
text-align: center;
font-size: 1.8rem;
font-weight: 600;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
main {
display: flex;
flex: 1;
}
.left-panel {
width: 40%;
padding: 20px;
background: #ffffff;
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}
.left-panel h2 {
color: #333;
font-size: 1.5rem;
margin-bottom: 10px;
}
.left-panel textarea {
width: 100%;
height: 75%;
padding: 12px;
font-size: 1rem;
border: 1px solid #ddd;
border-radius: 8px;
resize: none;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
.left-panel button {
margin-top: 12px;
padding: 10px 25px;
background-color: #3c40c6;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s ease;
}
.left-panel button:hover {
background-color: #575fcf;
}
.right-panel {
flex: 1;
padding: 20px;
background: #f8f9fa;
box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
}
.right-panel h2 {
color: #333;
font-size: 1.5rem;
margin-bottom: 10px;
}
.right-panel pre {
background: #1e272e;
color: #d2dae2;
padding: 20px;
border-radius: 8px;
font-size: 1rem;
overflow: auto;
height: calc(100% - 40px);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<header>SQL to Mermaid ER Diagram</header>
<main>
<div class="left-panel">
<h2>PostgreSQL Query</h2>
<textarea id="sqlInput" placeholder="Type your SQL query here..."></textarea>
<button id="runBtn">Run</button>
</div>
<div class="right-panel">
<h2>Mermaid Diagram</h2>
<pre class="mermaid" id="mermaidOutput">
erDiagram
customer {
string name
string custNumber
string sector
}
order {
int orderNumber
string deliveryAddress
}
customer ||--o{ order : places
</pre>
</div>
</main>
<a class="github-fork-ribbon" href="https://github.com/tusharad/sql2er" data-ribbon="Fork me on GitHub" title="Fork me on GitHub">Fork me on GitHub</a>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
document.getElementById('runBtn').addEventListener('click', () => {
const sqlQuery = document.getElementById('sqlInput').value;
const diagram = generate(sqlQuery);
const mermaidOutput = document.getElementById('mermaidOutput');
mermaidOutput.textContent = diagram;
mermaidOutput.removeAttribute("data-processed");
mermaid.run();
});
function generate(sqlQuery) {
const res = echo(sqlQuery) ;
console.log(`Mocked Diagram: ${res}`);
return res;
}
import { WASI } from 'https://cdn.jsdelivr.net/npm/@bjorn3/[email protected]/+esm'
const wasi = new WASI([], [], []);
const wasm = await WebAssembly.compileStreaming(fetch("sql2er-wasm.wasm"));
let inst = await WebAssembly.instantiate(wasm, {
"wasi_snapshot_preview1": wasi.wasiImport,
});
wasi.initialize(inst);
inst.exports.hs_init(0, 0);
function bufferAt(pos, len) {
return new Uint8Array(inst.exports.memory.buffer, pos, len);
}
function cstringBufferAt(cstr) {
let b = new Uint8Array(inst.exports.memory.buffer, cstr);
let l = b.findIndex(i => i == 0, b);
return bufferAt(cstr, l);
}
function withCStrings(strs, op) {
const cstrs = strs.map(str => {
const s = new TextEncoder().encode(str);
const l = s.length + 1;
const p = inst.exports.callocBuffer(l);
const b = new bufferAt(p, l);
b.set(s);
return p;
});
const r = op(cstrs);
cstrs.forEach(inst.exports.freeBuffer);
return r;
}
function withCString(str, op) {
return withCStrings([str], strs => op(strs[0]));
}
function fromCString(cstr) {
const s = new TextDecoder("utf8").decode(cstringBufferAt(cstr));
return s;
}
function echo(str) {
return fromCString(withCString(str, cstr => inst.exports.hs_runWorker(cstr)));
}
</script>
</body>
</html>