数据模型使用指针类型字段以避免空值自动更新的问题

This commit is contained in:
2025-05-26 10:57:39 +08:00
parent 1e7b5777a2
commit c08d625975
43 changed files with 457 additions and 397 deletions

View File

@@ -26,6 +26,8 @@ func main() {
g = gen.NewGenerator(gen.Config{
OutPath: "web/queries",
ModelPkgPath: "models",
FieldNullable: true,
FieldSignable: true,
FieldWithTypeTag: true,
Mode: gen.WithDefaultQuery | gen.WithoutContext,
})
@@ -34,10 +36,12 @@ func main() {
// 公共参数
common := []gen.ModelOpt{
gen.FieldModify(func(field gen.Field) gen.Field {
if field.Type == "time.Time" {
switch {
case field.Type == "*time.Time":
field.Type = "*orm.LocalDateTime"
case field.Type == "time.Time":
field.Type = "orm.LocalDateTime"
}
if strings.Contains(field.Tags(), "numeric") {
case strings.Contains(field.Tags(), "numeric"):
field.Type = "decimal.Decimal"
}
return field