mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
fix: ConvertStringDataType
This commit is contained in:
parent
53a74759a5
commit
f073e6c1ad
@ -227,7 +227,7 @@ func ConvertDataType(dataBaseType int, isDefaultNull, unsigned, strict bool) (st
|
|||||||
func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict bool) (
|
func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict bool) (
|
||||||
goType string, thirdPkg string, isPQArray bool, err error) {
|
goType string, thirdPkg string, isPQArray bool, err error) {
|
||||||
if env.UseExperimental() {
|
if env.UseExperimental() {
|
||||||
customTp, thirdImport := convertDatatypeWithConfig(dataBaseType, isDefaultNull, unsigned)
|
customTp, thirdImport := convertDatatypeWithConfig(dataBaseType, isDefaultNull, unsigned, strict)
|
||||||
if len(customTp) != 0 {
|
if len(customTp) != 0 {
|
||||||
return customTp, thirdImport, false, nil
|
return customTp, thirdImport, false, nil
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict
|
|||||||
return mayConvertNullType(tp, isDefaultNull, unsigned, strict), "", false, nil
|
return mayConvertNullType(tp, isDefaultNull, unsigned, strict), "", false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool) (string, string) {
|
func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool, strict bool) (string, string) {
|
||||||
externalConfig, err := config.GetExternalConfig()
|
externalConfig, err := config.GetExternalConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
@ -272,7 +272,7 @@ func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool
|
|||||||
if len(opt.NullType) != 0 {
|
if len(opt.NullType) != 0 {
|
||||||
return opt.NullType, opt.Pkg
|
return opt.NullType, opt.Pkg
|
||||||
}
|
}
|
||||||
} else if unsigned {
|
} else if unsigned && strict {
|
||||||
if len(opt.UnsignedType) != 0 {
|
if len(opt.UnsignedType) != 0 {
|
||||||
return opt.UnsignedType, opt.Pkg
|
return opt.UnsignedType, opt.Pkg
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ func mayConvertNullType(goDataType string, isDefaultNull, unsigned, strict bool)
|
|||||||
case "time.Time":
|
case "time.Time":
|
||||||
return "sql.NullTime"
|
return "sql.NullTime"
|
||||||
default:
|
default:
|
||||||
if unsigned {
|
if unsigned && strict {
|
||||||
ret, ok := unsignedTypeMap[goDataType]
|
ret, ok := unsignedTypeMap[goDataType]
|
||||||
if ok {
|
if ok {
|
||||||
return ret
|
return ret
|
||||||
|
@ -80,6 +80,17 @@ func TestConvertStringDataType(t *testing.T) {
|
|||||||
unsigned: true,
|
unsigned: true,
|
||||||
strict: false,
|
strict: false,
|
||||||
},
|
},
|
||||||
|
want: result{
|
||||||
|
goType: "int64",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: input{
|
||||||
|
dataType: "bigint",
|
||||||
|
isDefaultNull: false,
|
||||||
|
unsigned: true,
|
||||||
|
strict: true,
|
||||||
|
},
|
||||||
want: result{
|
want: result{
|
||||||
goType: "uint64",
|
goType: "uint64",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user