Skip to content

Commit 72e516b

Browse files
committed
content must be in root of master for domain projects
1 parent 59b0e89 commit 72e516b

File tree

4 files changed

+626
-0
lines changed

4 files changed

+626
-0
lines changed

index.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="wasm_exec.js"></script>
6+
<script src="sqldef_browser.js"></script>
7+
<style>
8+
body {
9+
font-family: sans-serif;
10+
width: 960px;
11+
margin: 20px auto;
12+
color: #fff;
13+
background: #000;
14+
}
15+
textarea, pre {
16+
border: 1px solid #000;
17+
background: #eee;
18+
color: #000;
19+
padding: 20px;
20+
margin-bottom: 20px;
21+
width: 100%;
22+
}
23+
pre {
24+
display: none;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<p>You can diff these 2 schemas:</p>
30+
31+
<textarea id="inputA" rows="10">
32+
CREATE TABLE user (
33+
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
34+
name VARCHAR(128) DEFAULT 'konsumer'
35+
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
36+
</textarea>
37+
38+
<textarea id="inputB" rows="10">
39+
CREATE TABLE user (
40+
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
41+
name VARCHAR(128) DEFAULT 'konsumer',
42+
created_at DATETIME NOT NULL
43+
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
44+
</textarea>
45+
<div>
46+
<select id="dbType">
47+
<option value="mysql">MySQL</option>
48+
<option value="postgres">PostgreSQL</option>
49+
</select>
50+
<button id="buttonDiff">DIFF</button>
51+
</div>
52+
<pre id="output"></pre>
53+
</body>
54+
55+
<script>
56+
const button = document.getElementById('buttonDiff')
57+
const dbType = document.getElementById('dbType')
58+
const inputA = document.getElementById('inputA')
59+
const inputB = document.getElementById('inputB')
60+
const output = document.getElementById('output')
61+
62+
button.addEventListener('click', async () => {
63+
output.style.display = 'none'
64+
output.innerHTML = await window.sqldef(dbType.value, inputB.value, inputA.value)
65+
output.style.display = 'block'
66+
})
67+
</script>
68+
69+
</html>

sqldef.wasm

3.89 MB
Binary file not shown.

sqldef_browser.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* global WebAssembly, fetch, Go,_SQLDEF */
2+
window.sqldef = async (dbType, desiredDDLs, currentDDLs) => {
3+
if (WebAssembly) {
4+
if (WebAssembly && !WebAssembly.instantiateStreaming) { // polyfill
5+
WebAssembly.instantiateStreaming = async (resp, importObject) => {
6+
const source = await (await resp).arrayBuffer()
7+
return WebAssembly.instantiate(source, importObject)
8+
}
9+
}
10+
const go = new Go()
11+
const result = await WebAssembly.instantiateStreaming(fetch('sqldef.wasm'), go.importObject)
12+
go.run(result.instance)
13+
return new Promise((resolve, reject) => {
14+
_SQLDEF(dbType, desiredDDLs, currentDDLs, (err, ret) => {
15+
if (err) {
16+
return reject(err)
17+
}
18+
resolve(ret)
19+
})
20+
})
21+
} else {
22+
throw new Error('WebAssembly is not supported in your browser')
23+
}
24+
}

0 commit comments

Comments
 (0)