@@ -2,6 +2,24 @@ This is a wasm-compiled version of [sqldef](https://github.com/sqldef/sqldef) fo
22
33## usage
44
5+ ### CLI
6+
7+ I made a node-based CLI wrapper:
8+
9+ ``` bash
10+ npx -y sqldef@latest --help
11+ ```
12+
13+ If you want to install it globally:
14+
15+ ``` bash
16+ npm i -g sqldef@latest
17+ sqldef --help
18+ ```
19+
20+ I recommend using the [ upstream CLI] ( https://github.com/sqldef/sqldef ) , though, if you are not using nodejs for other things.
21+
22+
523### node/bun/etc
624
725``` bash
@@ -26,11 +44,40 @@ CREATE TABLE user (
2644) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
2745`
2846
47+ // this will tell you the SQL needed to change sql1 into sql2
2948const output = await sqldef (' mysql' , sql1, sql2)
3049```
3150
3251Supported types: ` mysql ` , ` sqlite3 ` , ` mssql ` , ` postgres ` .
3352
53+ For node specifically, you can also use a wrapper I made to do real database operations:
54+
55+ ``` js
56+ import sqldef from ' sqldef'
57+ import {getStructure , executeQuery } from ' sqldef/db'
58+ import { readFile } from ' node:fs/promises'
59+
60+ const db = {type, host, database, user, password, socket, port }
61+ const current = await getStructure (db)
62+ const newStruct = await readFile (' db.sql' , ' utf8' )
63+ const diff = await sqldef (db .type , current, newStruct)
64+ console .log (diff)
65+ if (diff .trim ()) {
66+ await executeQuery ({query: diff, ... db})
67+ }
68+ ```
69+
70+ ### web
71+
72+ ``` html
73+ <script type =" module" >
74+ import sqldef from ' https://sqldef.github.io/sqldef-wasm/sqldef/index.js'
75+
76+ const output = await sqldef (' mysql' , sql1, sql2)
77+ </script >
78+ ```
79+
80+
3481### development
3582
3683Normally, you should not need to do this stuff, but for local dev:
0 commit comments