forked from mcos/schemabuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (35 loc) · 1.12 KB
/
main.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
44
45
46
package main
import (
"database/sql"
"flag"
"fmt"
"log"
"strings"
_ "github.com/go-sql-driver/mysql"
"github.com/gleez/schemabuf/schemabuf"
)
func main() {
dbType := flag.String("db", "mysql", "the database type")
host := flag.String("host", "localhost", "the database host")
port := flag.Int("port", 3306, "the database port")
user := flag.String("user", "root", "the database user")
password := flag.String("password", "root", "the database password")
schema := flag.String("schema", "db_name", "the database schema")
packageName := flag.String("package", *schema, "the protocol buffer package. defaults to the database schema.")
ignoreTableStr := flag.String("ignore_tables", "", "a comma spaced list of tables to ignore")
flag.Parse()
connStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", *user, *password, *host, *port, *schema)
db, err := sql.Open(*dbType, connStr)
if err != nil {
log.Fatal(err)
}
defer db.Close()
ignoreTables := strings.Split(*ignoreTableStr, ",")
s, err := schemabuf.GenerateSchema(db, *packageName, ignoreTables)
if nil != err {
log.Fatal(err)
}
if nil != s {
fmt.Println(s)
}
}