Skip to content

Commit 0f40936

Browse files
committed
add "Enable Drop" switch in index.html
1 parent 60854e7 commit 0f40936

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

.mcp.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"mcpServers": {
3+
"lsmcp-go": {
4+
"type": "stdio",
5+
"command": "npx",
6+
"args": [
7+
"-y",
8+
"@mizchi/lsmcp",
9+
"-p",
10+
"gopls"
11+
],
12+
"env": {}
13+
},
14+
"lsmcp-ts": {
15+
"type": "stdio",
16+
"command": "npx",
17+
"args": [
18+
"-y",
19+
"@mizchi/lsmcp",
20+
"-p",
21+
"tsgo"
22+
],
23+
"env": {}
24+
}
25+
}
26+
}

app.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { sqldef, getVersion } from "./sqldef_browser.mjs";
22

33
const dbType = document.getElementById("dbType");
4+
const enableDrop = document.getElementById("enableDrop");
45
const inputA = document.getElementById("inputA");
56
const inputB = document.getElementById("inputB");
67
const outputUp = document.getElementById("outputUp");
@@ -63,7 +64,8 @@ async function runDiff() {
6364
const result = await sqldef(
6465
dbType.value,
6566
inputB.value,
66-
inputA.value
67+
inputA.value,
68+
enableDrop.checked
6769
);
6870
outputUp.innerHTML = result;
6971
outputUp.style.display = "block";
@@ -79,7 +81,8 @@ async function runDiff() {
7981
const result = await sqldef(
8082
dbType.value,
8183
inputA.value,
82-
inputB.value
84+
inputB.value,
85+
enableDrop.checked
8386
);
8487
outputDown.innerHTML = result;
8588
outputDown.style.display = "block";
@@ -100,6 +103,7 @@ dbType.addEventListener("change", () => {
100103

101104
inputA.addEventListener("input", runDiff);
102105
inputB.addEventListener("input", runDiff);
106+
enableDrop.addEventListener("change", runDiff);
103107

104108
// Run diff on initial load
105109
runDiff();

index.html

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,19 @@
109109

110110
<body>
111111
<h1>sqldef</h1>
112-
<p>sqldef is a <a href="https://github.com/sqldef/sqldef">CLI tool</a>, <a
113-
href="https://github.com/sqldef/sqldef.github.io">Wasm library</a>, and <a
114-
href="https://github.com/sqldef/node-sqldef">nodejs tool/library</a> for diffing two SQL schemas. You can use it
115-
to
116-
manage migration of PostgreSQL, MySQL, SQLite3, and SQL Server databases, using regular SQL DDLs.</p>
117-
118-
<h2>Demo</h2>
119-
<p>You can generate DDLs to update the DB schema:</p>
120-
112+
<p>sqldef is a <a href="https://github.com/sqldef/sqldef">CLI tool</a> for diffing two SQL schemas. You can use it to
113+
manage the migration of PostgreSQL, MySQL, SQLite3, and SQL Server databases, using regular SQL DDLs.</p>
114+
<h2>Online Demo</h2>
121115
<div>
122116
<select id="dbType">
123117
<option value="mysql">MySQL</option>
124118
<option value="postgres">PostgreSQL</option>
125119
<option value="sqlite3">SQLite3</option>
126120
<option value="mssql">SQL Server</option>
127121
</select>
122+
<label style="margin-left: 20px;">
123+
<input type="checkbox" id="enableDrop"> Enable DROP
124+
</label>
128125
</div>
129126

130127
<div class="schema-row">
@@ -157,6 +154,14 @@ <h4 class="schema-header">Desired schema</h4>
157154
<pre id="errorDown" class="error"></pre>
158155
</div>
159156

157+
<section>
158+
<h2>How It Works</h2>
159+
<p>
160+
The online demo uses the <a href="https://github.com/sqldef/sqldef.github.io">WebAssembly build of sqldef</a> to
161+
diff two SQL schemas and generate DDLs.
162+
</p>
163+
</section>
164+
160165
<footer>
161166
<p id="version"></p>
162167
<p>

sqldef-wasm.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
"github.com/sqldef/sqldef/v3/schema"
1515
)
1616

17-
// diff function (mode: string, desiredDDLs: string, currentDDLs: string, callback: (err: string | null, result: string | null): void)
17+
// diff function (mode: string, desiredDDLs: string, currentDDLs: string, enableDrop: bool, callback: (err: string | null, result: string | null): void)
1818
func sqldefDiff(this js.Value, args []js.Value) any {
1919
mode := args[0].String()
2020
desiredDDLs := args[1].String()
2121
currentDDLs := args[2].String()
22-
callback := args[3]
22+
enableDrop := args[3].Bool()
23+
callback := args[4]
2324

2425
generatorMode := schema.GeneratorModeMysql
2526
parserMode := parser.ParserModeMysql
@@ -42,7 +43,10 @@ func sqldefDiff(this js.Value, args []js.Value) any {
4243
}
4344

4445
sqlParser := database.NewParser(parserMode)
45-
config := database.GeneratorConfig{}
46+
config := database.GeneratorConfig{
47+
EnableDrop: enableDrop,
48+
LegacyIgnoreQuotes: false,
49+
}
4650
defaultSchema := ""
4751

4852
ddls, err := schema.GenerateIdempotentDDLs(generatorMode, sqlParser, desiredDDLs, currentDDLs, config, defaultSchema)

sqldef.wasm

532 Bytes
Binary file not shown.

sqldef_browser.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const getInstance = async () => {
2121
return SQLDEF;
2222
};
2323

24-
export async function sqldef(dbType, desiredDDLs, currentDDLs) {
24+
export async function sqldef(dbType, desiredDDLs, currentDDLs, enableDrop = false) {
2525
if (typeof WebAssembly === "undefined") {
2626
throw new Error("WebAssembly is not supported in your browser");
2727
}
2828

2929
const SQLDEF = await getInstance();
3030

3131
return new Promise((resolve, reject) => {
32-
SQLDEF.diff(dbType, desiredDDLs, currentDDLs, (err, ret) => {
32+
SQLDEF.diff(dbType, desiredDDLs, currentDDLs, enableDrop, (err, ret) => {
3333
if (err) {
3434
return reject(new Error(err));
3535
}

0 commit comments

Comments
 (0)