-
Notifications
You must be signed in to change notification settings - Fork 0
/
norm.ts
72 lines (59 loc) · 1.29 KB
/
norm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { parseArgs } from "./deps.ts";
import { version } from "./version.ts";
import { norm } from "./mod.ts";
type Args = {
conn: string;
help: boolean;
out: string;
version: boolean;
};
const help = `norm ${version}
Generate TypeScript types from a database schema.
Examples:
norm -c mysql://user:password@localhost:3306/public
norm -c postgres://user:password@localhost:5432/public
Supported databases:
* MySQL
* PostgreSQL
OPTIONS:
-c, --conn Database connection string
-h, --help Show help information
-o, --out Types filename (default: ./types.ts)
-v, --version Show version
`;
const args = parseArgs(Deno.args, {
alias: {
"conn": "c",
"help": "h",
"out": "o",
"version": "v",
},
string: [
"conn",
"out",
],
boolean: [
"help",
"version",
],
default: {
conn: undefined,
out: "./types.ts",
},
}) as unknown as Args;
if (args.help) {
console.info(help);
Deno.exit(0);
}
if (args.version) {
console.info(`norm ${version}`);
Deno.exit(0);
}
if (!args.conn) {
console.error("You didn't specified a database connection string.");
Deno.exit(1);
}
const types = await norm(args.conn);
await Deno.writeTextFile(args.out, types);
console.info(`Types written to ${args.out}`);
Deno.exit(0);