chore: refactor (#1331)

master
Kevin Wan 3 years ago committed by GitHub
parent 171afaadb9
commit 1becaeb7be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -633,4 +633,3 @@ func NewSyntaxLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, in
return p return p
} }

@ -7,7 +7,7 @@ import (
"github.com/zeromicro/ddl-parser/parser" "github.com/zeromicro/ddl-parser/parser"
) )
var commonMysqlDataTypeMap = map[int]string{ var commonMysqlDataTypeMapInt = map[int]string{
// For consistency, all integer types are converted to int64 // For consistency, all integer types are converted to int64
// number // number
parser.Bool: "int64", parser.Bool: "int64",
@ -53,7 +53,7 @@ var commonMysqlDataTypeMap = map[int]string{
parser.TinyBlob: "string", parser.TinyBlob: "string",
} }
var commonMysqlDataTypeMap2 = map[string]string{ var commonMysqlDataTypeMapString = map[string]string{
// For consistency, all integer types are converted to int64 // For consistency, all integer types are converted to int64
// number // number
"bool": "int64", "bool": "int64",
@ -67,7 +67,7 @@ var commonMysqlDataTypeMap2 = map[string]string{
"float": "float64", "float": "float64",
"double": "float64", "double": "float64",
"decimal": "float64", "decimal": "float64",
// date&time // date & time
"date": "time.Time", "date": "time.Time",
"datetime": "time.Time", "datetime": "time.Time",
"timestamp": "time.Time", "timestamp": "time.Time",
@ -95,7 +95,7 @@ var commonMysqlDataTypeMap2 = map[string]string{
// ConvertDataType converts mysql column type into golang type // ConvertDataType converts mysql column type into golang type
func ConvertDataType(dataBaseType int, isDefaultNull bool) (string, error) { func ConvertDataType(dataBaseType int, isDefaultNull bool) (string, error) {
tp, ok := commonMysqlDataTypeMap[dataBaseType] tp, ok := commonMysqlDataTypeMapInt[dataBaseType]
if !ok { if !ok {
return "", fmt.Errorf("unsupported database type: %v", dataBaseType) return "", fmt.Errorf("unsupported database type: %v", dataBaseType)
} }
@ -105,7 +105,7 @@ func ConvertDataType(dataBaseType int, isDefaultNull bool) (string, error) {
// ConvertStringDataType converts mysql column type into golang type // ConvertStringDataType converts mysql column type into golang type
func ConvertStringDataType(dataBaseType string, isDefaultNull bool) (string, error) { func ConvertStringDataType(dataBaseType string, isDefaultNull bool) (string, error) {
tp, ok := commonMysqlDataTypeMap2[strings.ToLower(dataBaseType)] tp, ok := commonMysqlDataTypeMapString[strings.ToLower(dataBaseType)]
if !ok { if !ok {
return "", fmt.Errorf("unsupported database type: %s", dataBaseType) return "", fmt.Errorf("unsupported database type: %s", dataBaseType)
} }

Loading…
Cancel
Save