From 1becaeb7be80041b902f72afe3e1435ae4d3c9e2 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Wed, 15 Dec 2021 20:44:23 +0800 Subject: [PATCH] chore: refactor (#1331) --- .../goctl/api/parser/g4/gen/api/apiparser_parser.go | 1 - tools/goctl/model/sql/converter/types.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go b/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go index aa5a9b85..fbb26a9a 100755 --- a/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go +++ b/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go @@ -633,4 +633,3 @@ func NewSyntaxLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, in return p } - diff --git a/tools/goctl/model/sql/converter/types.go b/tools/goctl/model/sql/converter/types.go index 6c62b722..eee7c18d 100644 --- a/tools/goctl/model/sql/converter/types.go +++ b/tools/goctl/model/sql/converter/types.go @@ -7,7 +7,7 @@ import ( "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 // number parser.Bool: "int64", @@ -53,7 +53,7 @@ var commonMysqlDataTypeMap = map[int]string{ parser.TinyBlob: "string", } -var commonMysqlDataTypeMap2 = map[string]string{ +var commonMysqlDataTypeMapString = map[string]string{ // For consistency, all integer types are converted to int64 // number "bool": "int64", @@ -67,7 +67,7 @@ var commonMysqlDataTypeMap2 = map[string]string{ "float": "float64", "double": "float64", "decimal": "float64", - // date&time + // date & time "date": "time.Time", "datetime": "time.Time", "timestamp": "time.Time", @@ -76,7 +76,7 @@ var commonMysqlDataTypeMap2 = map[string]string{ // string "char": "string", "varchar": "string", - "binary": "string", + "binary": "string", "bytea": "string", "varbinary": "string", "tinytext": "string", @@ -95,7 +95,7 @@ var commonMysqlDataTypeMap2 = map[string]string{ // ConvertDataType converts mysql column type into golang type func ConvertDataType(dataBaseType int, isDefaultNull bool) (string, error) { - tp, ok := commonMysqlDataTypeMap[dataBaseType] + tp, ok := commonMysqlDataTypeMapInt[dataBaseType] if !ok { 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 func ConvertStringDataType(dataBaseType string, isDefaultNull bool) (string, error) { - tp, ok := commonMysqlDataTypeMap2[strings.ToLower(dataBaseType)] + tp, ok := commonMysqlDataTypeMapString[strings.ToLower(dataBaseType)] if !ok { return "", fmt.Errorf("unsupported database type: %s", dataBaseType) }