-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
52 lines (49 loc) · 1.12 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
package converter
import (
"fmt"
"strings"
)
var (
commonMysqlDataTypeMap = map[string]string{
// For consistency, all integer types are converted to int64
// number
"bool": "int64",
"boolean": "int64",
"tinyint": "int64",
"smallint": "int64",
"mediumint": "int64",
"int": "int64",
"integer": "int64",
"bigint": "int64",
"float": "float64",
"double": "float64",
"decimal": "float64",
// date&time
"date": "time.Time",
"datetime": "time.Time",
"timestamp": "time.Time",
"time": "string",
"year": "int64",
// string
"char": "string",
"varchar": "string",
"binary": "string",
"varbinary": "string",
"tinytext": "string",
"text": "string",
"mediumtext": "string",
"longtext": "string",
"enum": "string",
"set": "string",
"json": "string",
}
)
func ConvertDataType(dataBaseType string) (goDataType string, err error) {
tp, ok := commonMysqlDataTypeMap[strings.ToLower(dataBaseType)]
if !ok {
err = fmt.Errorf("unexpected database type: %s", dataBaseType)
return
}
goDataType = tp
return
}