go-gorm / gen

Gen: Friendly & Safer GORM powered by Code Generation
https://gorm.io/gen/
MIT License
2.18k stars 282 forks source link

gorm Gen Tool int32 #1134

Open WaterCool8258 opened 3 months ago

WaterCool8258 commented 3 months ago

Your Question

想请问下gorm 的 Gen Tool使用配置文件生成模型的时候,可以像代码那样指定INTEGER为int64吗?我使用的数据库是sqlite,目前会把INTEGER类型定义为int32,但是数据库存储值范围已经大于int32了

The document you expected this should be explained

Expected answer

zplzpl commented 3 weeks ago
    g := gen.NewGenerator(gen.Config{
        OutPath:      "./dal",
        ModelPkgPath: "./models",
        Mode:         gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode

    })

    g.WithOpts(gen.FieldModify(func(field gen.Field) gen.Field {
        if field.Type == "int32" {
            field.Type = "int64"
        }
        return field
    }))

maybe like that.