feat: add transformer for model
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -22,7 +23,7 @@ type TableModelParam struct {
|
||||
PascalTable string // User
|
||||
}
|
||||
|
||||
func Generate(tables []string) error {
|
||||
func Generate(tables []string, transformer Transformer) error {
|
||||
baseDir := "app/models"
|
||||
|
||||
tableTpl := template.Must(template.New("model").Parse(string(tableTpl)))
|
||||
@@ -30,6 +31,11 @@ func Generate(tables []string) error {
|
||||
|
||||
items := []TableModelParam{}
|
||||
for _, table := range tables {
|
||||
if lo.Contains(transformer.Ignores.Model, table) {
|
||||
log.Printf("[WARN] skip model %s\n", table)
|
||||
continue
|
||||
}
|
||||
|
||||
items = append(items, TableModelParam{
|
||||
CamelTable: lo.CamelCase(table),
|
||||
PascalTable: lo.PascalCase(table),
|
||||
@@ -68,7 +74,16 @@ func Generate(tables []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
|
||||
baseName := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
if lo.Contains(transformer.Ignores.Model, baseName) {
|
||||
log.Printf("[WARN] skip model %s\n", baseName)
|
||||
continue
|
||||
}
|
||||
|
||||
if !lo.Contains(tables, baseName) {
|
||||
items = append(items, TableModelParam{
|
||||
CamelTable: lo.CamelCase(baseName),
|
||||
|
||||
9
pkg/ast/model/transformer.go
Normal file
9
pkg/ast/model/transformer.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
type Transformer struct {
|
||||
Ignores struct {
|
||||
Jet []string `mapstructure:"jet"`
|
||||
Model []string `mapstructure:"model"`
|
||||
} `mapstructure:"ignores"`
|
||||
Types map[string]map[string]string `mapstructure:"types"`
|
||||
}
|
||||
Reference in New Issue
Block a user