-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht2t.go
43 lines (34 loc) · 809 Bytes
/
t2t.go
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
package main
import (
"flag"
"github.com/jmoiron/sqlx"
"github.com/ndlinh/t2t/dialect"
)
func main() {
pk := flag.String("p", "", "Package name")
table := flag.String("t", "", "Optional. Tables to export. Use commas to separate table's name")
output := flag.String("o", "", "Optional. Output directory. Use current directory if empty")
dsn := flag.String("dsn", "", "DB connect DSN. Ex: root:root@localhost/flarum?parseTime=true")
flag.Parse()
if *dsn == "" {
flag.PrintDefaults()
return
}
if *pk == "" {
flag.PrintDefaults()
return
}
if *output == "" {
*output = "./"
}
db, err := sqlx.Connect("mysql", *dsn)
if err != nil {
panic(err)
}
d := dialect.NewMySQLDialect(*pk, *output, db)
if *table == "" {
d.BuildStruct()
} else {
d.BuildStructForTable(*table)
}
}