fix(goctl): Fix issues (#2543)

* fix #2541

* fix #2432

* Fix review comment

* foramt code

* foramt code
This commit is contained in:
anqiansong 2022-10-22 21:01:15 +08:00 committed by GitHub
parent bbadbe0175
commit 7c9ef3ca67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -77,6 +77,7 @@ var commonMysqlDataTypeMapString = map[string]string{
// For consistency, all integer types are converted to int64
// bool
"bool": "bool",
"_bool": "pq.BoolArray",
"boolean": "bool",
// number
"tinyint": "int64",
@ -85,14 +86,20 @@ var commonMysqlDataTypeMapString = map[string]string{
"int": "int64",
"int1": "int64",
"int2": "int64",
"_int2": "pq.Int64Array",
"int3": "int64",
"int4": "int64",
"_int4": "pq.Int64Array",
"int8": "int64",
"_int8": "pq.Int64Array",
"integer": "int64",
"_integer": "pq.Int64Array",
"bigint": "int64",
"float": "float64",
"float4": "float64",
"_float4": "pq.Float64Array",
"float8": "float64",
"_float8": "pq.Float64Array",
"double": "float64",
"decimal": "float64",
"dec": "float64",
@ -111,14 +118,17 @@ var commonMysqlDataTypeMapString = map[string]string{
"nvarchar": "string",
"nchar": "string",
"char": "string",
"_char": "pq.StringArray",
"character": "string",
"varchar": "string",
"_varchar": "pq.StringArray",
"binary": "string",
"bytea": "string",
"longvarbinary": "string",
"varbinary": "string",
"tinytext": "string",
"text": "string",
"_text": "pq.StringArray",
"mediumtext": "string",
"longtext": "string",
"enum": "string",
@ -129,6 +139,7 @@ var commonMysqlDataTypeMapString = map[string]string{
"longblob": "string",
"mediumblob": "string",
"tinyblob": "string",
"ltree": "[]byte",
}
// ConvertDataType converts mysql column type into golang type
@ -148,6 +159,10 @@ func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict
return "", fmt.Errorf("unsupported database type: %s", dataBaseType)
}
if strings.HasPrefix(dataBaseType, "_") {
return tp, nil
}
return mayConvertNullType(tp, isDefaultNull, unsigned, strict), nil
}

View File

@ -10,11 +10,16 @@ import (
const ModelCustom = `package {{.pkg}}
{{if .withCache}}
import (
"github.com/lib/pq"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
{{else}}
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"github.com/lib/pq"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
{{end}}
var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil)