add models generation and josn print

This commit is contained in:
2026-03-26 02:22:14 +01:00
parent 7c5a993623
commit af2b276599
319 changed files with 7394 additions and 27 deletions

View File

@@ -8,7 +8,6 @@ import (
"strings"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
)
@@ -30,7 +29,11 @@ func (m *GormGenModels) GormGenModels(ctx context.Context) error {
g := gen.NewGenerator(gen.Config{
OutPath: GENERATED_FILES_FOLDER,
ModelPkgPath: GENERATED_MODEL_PKG,
Mode: gen.WithoutContext,
// Mode: gen.WithoutContext,
// OutFile: GENERATED_FILES_FOLDER + "/../gen.go",
FieldNullable: true,
FieldWithIndexTag: true,
// Mode: gen.WithoutContext,
})
g.UseDB(m.db)
@@ -42,10 +45,10 @@ func (m *GormGenModels) GormGenModels(ctx context.Context) error {
}
// Generate models only for tables with 'ps_' prefix
// Use gen.FieldRelateModel to add foreign key relations
// Generate models without relations - relations can be added manually if needed
for _, tableName := range tableNames {
if strings.HasPrefix(tableName, "ps_") {
g.GenerateModel(tableName, gen.FieldRelateModel(field.BelongsTo, "*", nil, &field.RelateConfig{}))
g.GenerateModel(tableName)
}
}
@@ -103,7 +106,7 @@ func (m *GormGenModels) cleanupGeneratedFiles() error {
oldPath := filepath.Join(absDir, name)
// Extract name: ps_category.gen.go -> category
baseName := strings.TrimSuffix(name, ".gen.go")
baseName, _ = strings.CutPrefix(baseName, "ps_")
// baseName, _ = strings.CutPrefix(baseName, "ps_")
newPath := filepath.Join(absDir, baseName+".go")
// Read file content