-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
438 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<!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"> | ||
<style> | ||
body { | ||
font-family: 'Inter', sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
background-color: #f4f4f8; | ||
} | ||
|
||
header { | ||
background-color: #4CAF50; | ||
color: white; | ||
padding: 10px 20px; | ||
text-align: center; | ||
font-size: 1.5rem; | ||
font-weight: 600; | ||
} | ||
|
||
main { | ||
display: flex; | ||
flex: 1; | ||
} | ||
|
||
.left-panel { | ||
width: 40%; | ||
padding: 20px; | ||
background: #fff; | ||
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.left-panel textarea { | ||
width: 100%; | ||
height: 80%; | ||
padding: 10px; | ||
font-size: 1rem; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
resize: none; | ||
} | ||
|
||
.left-panel button { | ||
margin-top: 10px; | ||
padding: 10px 20px; | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 1rem; | ||
} | ||
|
||
.left-panel button:hover { | ||
background-color: #45a049; | ||
} | ||
|
||
.right-panel { | ||
flex: 1; | ||
padding: 20px; | ||
} | ||
|
||
.right-panel pre { | ||
background: #2d2d2d; | ||
color: #f4f4f8; | ||
padding: 20px; | ||
border-radius: 5px; | ||
font-size: 1rem; | ||
overflow: auto; | ||
height: 100%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<header>SQL to Mermaid ER Diagram</header> | ||
<main> | ||
<div class="left-panel"> | ||
<h2>SQL 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> | ||
|
||
<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(); | ||
}); | ||
|
||
// Mock function to simulate SQL to Mermaid ER Diagram conversion | ||
function generate(sqlQuery) { | ||
// Replace this with the actual logic for SQL parsing and Mermaid ER generation | ||
const res = echo(sqlQuery); | ||
console.log("got res:", res); | ||
return res; | ||
} | ||
|
||
import { WASI } from 'https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.3.0/+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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.