-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
79 lines (66 loc) · 1.8 KB
/
types.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
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
73
74
75
76
77
78
79
package gen
import (
"fmt"
"github.com/tal-tech/go-zero/tools/goctl/model/pgsql/model"
"github.com/tal-tech/go-zero/tools/goctl/model/pgsql/template"
"github.com/tal-tech/go-zero/tools/goctl/util"
)
func genTypes(table PgTable, methods, comment string, withCache bool) (string, error) {
fields := table.Fields
fieldsString, err := genFields(fields, &table.PrimaryKey.Field)
if err != nil {
return "", err
}
text, err := util.LoadTemplate(category, typesTemplateFile, template.Types)
if err != nil {
return "", err
}
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
"withCache": withCache,
"method": methods,
"upperStartCamelObject": table.Name.ToCamel(),
"fields": fieldsString,
"comment": comment,
})
if err != nil {
return "", err
}
return output.String(), nil
}
func genPgFactoryTypes(pkg string, table map[string]*model.PgTable) (string, error) {
//for _,k:=range table {
// tables, err := parser.ConvertDataType(k)
// if err != nil {
// return "", err
// }
//}
fieldsString, err := genPgFactoryFields(table)
if err != nil {
return "", err
}
text, err := util.LoadTemplate(Factory, factoryTypesFile, template.FactoryTypes)
if err != nil {
return "", err
}
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
//"upperStartCamelObject": table.Name.ToCamel(),
//"upperStartModelObject": table.Name.ToCamel(),
"upperStartCamelObject": fmt.Sprintf("%s%s", UpdateUpper(pkg), "Dao"),
"fields": fieldsString,
})
if err != nil {
return "", err
}
return output.String(), nil
}
func UpdateUpper(a string) string {
vv := []rune(a)
if len(vv) != 0 && vv[0] >= 97 && vv[0] <= 132 {
vv[0] = vv[0] - 32
}
return string(vv)
}