feat: update

This commit is contained in:
yanghao05
2025-05-23 22:02:36 +08:00
parent 8277c79d23
commit 3617c68a91

View File

@@ -101,6 +101,25 @@ func Generate(tables []string, transformer Transformer) error {
}
items = append(items, tableInfo)
// tableFuncsFile
tableFuncsFile := fmt.Sprintf("%s/%s.funcs.gen.go", baseDir, table)
// 如果 modelFuncsFile 已存在,则跳过
if _, err := os.Stat(tableFuncsFile); err == nil {
fmt.Printf("Model funcs file %s already exists. Skipping...\n", tableFuncsFile)
continue
}
// 如果 modelFuncsFile 不存在,则创建
fd, err := os.Create(tableFuncsFile)
if err != nil {
return fmt.Errorf("failed to create model funcs file %s: %w", tableFuncsFile, err)
}
defer fd.Close()
if err := tableFuncsTpl.Execute(fd, tableInfo); err != nil {
return fmt.Errorf("failed to render model funcs template: %w", err)
}
modelFile := fmt.Sprintf("%s/%s.go", baseDir, table)
// 如果 modelFile 已存在,则跳过
if _, err := os.Stat(modelFile); err == nil {
@@ -109,7 +128,7 @@ func Generate(tables []string, transformer Transformer) error {
}
// 如果 modelFile 不存在,则创建
fd, err := os.Create(modelFile)
fd, err = os.Create(modelFile)
if err != nil {
return fmt.Errorf("failed to create model file %s: %w", modelFile, err)
}
@@ -137,24 +156,6 @@ func Generate(tables []string, transformer Transformer) error {
return fmt.Errorf("failed to render model test template: %w", err)
}
// tableFuncsFile
tableFuncsFile := fmt.Sprintf("%s/%s.funcs.gen.go", baseDir, table)
// 如果 modelFuncsFile 已存在,则跳过
if _, err := os.Stat(tableFuncsFile); err == nil {
fmt.Printf("Model funcs file %s already exists. Skipping...\n", tableFuncsFile)
continue
}
// 如果 modelFuncsFile 不存在,则创建
fd, err = os.Create(tableFuncsFile)
if err != nil {
return fmt.Errorf("failed to create model funcs file %s: %w", tableFuncsFile, err)
}
defer fd.Close()
if err := tableFuncsTpl.Execute(fd, tableInfo); err != nil {
return fmt.Errorf("failed to render model funcs template: %w", err)
}
}
// 渲染总的 provider 文件