-
Notifications
You must be signed in to change notification settings - Fork 0
/
column_struct.go
47 lines (42 loc) · 1.03 KB
/
column_struct.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
package types
import (
"github.com/bnulwh/mybatis-go/log"
"reflect"
"strings"
)
type ColumnStucture struct {
Name string
Type reflect.Type
DbType string
Comment string
Primary bool
}
func newColumnStructure(row map[string]interface{}) *ColumnStucture {
log.Debugf("row %v", row)
return &ColumnStucture{
Name: row["column_name"].(string),
Type: ParseJdbcTypeFrom(row["column_type"].(string)),
DbType: row["column_type"].(string),
Comment: row["column_comment"].(string),
Primary: row["column_key"].(string) == "PRI",
}
}
func (cs ColumnStucture) getJdbcType() string {
jt := strings.ToUpper(GetJdbcTypePart(cs.DbType))
if jt == "TEXT" || jt == "LONGTEXT" || jt == "TINYTEXT" {
return "VARCHAR"
}
if jt == "CHARACTER" {
return "VARCHAR"
}
return jt
}
func (cs ColumnStucture) getPropertyName() string {
arr := strings.Split(cs.Name, "_")
var res []string
res = append(res, arr[0])
for i := 1; i < len(arr); i++ {
res = append(res, UpperFirst(strings.TrimSpace(arr[i])))
}
return strings.Join(res, "")
}