Skip to content

Commit 1dbd7d5

Browse files
committed
throw on invalid type
1 parent f3db324 commit 1dbd7d5

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ CREATE TABLE user (
2929
const output = await sqldef('mysql', sql1, sql2)
3030
```
3131

32+
Supported types: `mysql`, `sqlite3`, `mssql`, `postgres`.
33+
3234
### development
3335

3436
Normally, you should not need to do this stuff, but for local dev:

build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const buf = new Uint8Array([${[...buf].join(',')}])
99
const go = new Go()
1010
1111
export default async (t,s1,s2) => {
12+
if (!['mysql', 'sqlite3', 'mssql', 'postgres'].includes(t)) {
13+
throw new Error(\`Invalid type: \${t}. Use mysql/sqlite3/mssql/postgres\`)
14+
}
1215
const inst = await WebAssembly.instantiate(buf, go.importObject)
1316
go.run(inst.instance)
1417
const sqlDefModule = createSqlDefModule()

index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldef.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('should be able to diff some sqlite', async ({ assert }) => {
4949
name VARCHAR NOT NULL
5050
);
5151
`
52-
const r = await sqldef('sqlite', sql1, sql2)
52+
const r = await sqldef('sqlite3', sql1, sql2)
5353
assert.snapshot(r)
5454
})
5555

@@ -78,4 +78,25 @@ test('should throw on bad SQL', async ({assert}) => {
7878
} catch(e) {
7979
assert.snapshot(e.message)
8080
}
81+
})
82+
83+
test('should throw on bad type', async ({ assert }) => {
84+
const sql1 = `
85+
CREATE TABLE IF NOT EXISTS user (
86+
id INT PRIMARY KEY
87+
);
88+
`
89+
90+
const sql2 = `
91+
CREATE TABLE IF NOT EXISTS user (
92+
id INT PRIMARY KEY,
93+
name VARCHAR NOT NULL
94+
);
95+
`
96+
try {
97+
await sqldef('sqlite', sql1, sql2)
98+
assert.equal(true, 'Should have thrown')
99+
} catch(e) {
100+
assert.snapshot(e.message)
101+
}
81102
})

sqldef.test.js.snapshot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ exports[`should be able to diff some postgres 1`] = `
1111
`;
1212

1313
exports[`should be able to diff some sqlite 1`] = `
14-
"ALTER TABLE \`user\` CHANGE COLUMN \`id\` \`id\` int NOT NULL;\\nALTER TABLE \`user\` DROP COLUMN \`name\`"
14+
"ALTER TABLE \`user\` DROP COLUMN \`name\`"
1515
`;
1616

1717
exports[`should throw on bad SQL 1`] = `
1818
"found syntax error when parsing DDL \\"BAD STUFF\\": syntax error at position 4 near 'BAD'"
1919
`;
20+
21+
exports[`should throw on bad type 1`] = `
22+
"Invalid type: sqlite. Use mysql/sqlite3/mssql/postgres"
23+
`;

0 commit comments

Comments
 (0)