modify model

This commit is contained in:
2024-01-22 18:18:24 +08:00
parent c08e741d7a
commit 4e4ae034f1
9 changed files with 80 additions and 44 deletions

View File

@@ -15,7 +15,11 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
)
const timeImport = "time.Time"
const (
timeImport = "time.Time"
decimalImport = "decimal.Decimal"
decimalImportPtr = "*decimal.Decimal"
)
type (
// Table describes a mysql table
@@ -263,6 +267,16 @@ func (t *Table) ContainsTime() bool {
return false
}
// ContainsDecimal returns true if contains golang type decimal.Decimal
func (t *Table) ContainsDecimal() bool {
for _, item := range t.Fields {
if item.DataType == decimalImport || item.DataType == decimalImportPtr {
return true
}
}
return false
}
// ConvertDataType converts mysql data type into golang data type
func ConvertDataType(table *model.Table, strict bool) (*Table, error) {
isPrimaryDefaultNull := table.PrimaryKey.ColumnDefault == nil && table.PrimaryKey.IsNullAble == "YES"