feat: update
This commit is contained in:
@@ -101,6 +101,25 @@ func Generate(tables []string, transformer Transformer) error {
|
|||||||
}
|
}
|
||||||
items = append(items, tableInfo)
|
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 := fmt.Sprintf("%s/%s.go", baseDir, table)
|
||||||
// 如果 modelFile 已存在,则跳过
|
// 如果 modelFile 已存在,则跳过
|
||||||
if _, err := os.Stat(modelFile); err == nil {
|
if _, err := os.Stat(modelFile); err == nil {
|
||||||
@@ -109,7 +128,7 @@ func Generate(tables []string, transformer Transformer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 如果 modelFile 不存在,则创建
|
// 如果 modelFile 不存在,则创建
|
||||||
fd, err := os.Create(modelFile)
|
fd, err = os.Create(modelFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create model file %s: %w", modelFile, err)
|
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)
|
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 文件
|
// 渲染总的 provider 文件
|
||||||
|
|||||||
Reference in New Issue
Block a user