-
Notifications
You must be signed in to change notification settings - Fork 26
/
generate.go
43 lines (36 loc) · 802 Bytes
/
generate.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 gen
import (
"fmt"
"regexp"
"strings"
)
type Opts struct {
From string
Out string
Package string
FieldTags []string
ShouldGenTblName bool
RememberAlias bool
Recursive bool
Exclude string
}
// Generate go model
func Generate(opts Opts) {
var pattern *regexp.Regexp
if strings.TrimSpace(opts.Exclude) != "" {
pattern, _ = regexp.Compile(opts.Exclude)
}
dbmls := parseDBML(opts.From, opts.Recursive, pattern)
g := newgen()
g.out = opts.Out
g.gopackage = opts.Package
g.fieldtags = opts.FieldTags
g.shouldGenTblName = opts.ShouldGenTblName
for _, dbml := range dbmls {
g.reset(opts.RememberAlias)
g.dbml = dbml
if err := g.generate(); err != nil {
fmt.Printf("Error generate file %s", err)
}
}
}