@@ -2,6 +2,24 @@ This is a wasm-compiled version of [sqldef](https://github.com/sqldef/sqldef) fo
2
2
3
3
## usage
4
4
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
+
5
23
### node/bun/etc
6
24
7
25
``` bash
@@ -26,11 +44,40 @@ CREATE TABLE user (
26
44
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
27
45
`
28
46
47
+ // this will tell you the SQL needed to change sql1 into sql2
29
48
const output = await sqldef (' mysql' , sql1, sql2)
30
49
```
31
50
32
51
Supported types: ` mysql ` , ` sqlite3 ` , ` mssql ` , ` postgres ` .
33
52
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
+
34
81
### development
35
82
36
83
Normally, you should not need to do this stuff, but for local dev:
0 commit comments