new.go 789 B

123456789101112131415161718192021222324252627282930313233
  1. package gen
  2. import (
  3. "fmt"
  4. "github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
  5. "github.com/tal-tech/go-zero/tools/goctl/util"
  6. )
  7. func genNew(table Table, withCache, postgreSql bool) (string, error) {
  8. text, err := util.LoadTemplate(category, modelNewTemplateFile, template.New)
  9. if err != nil {
  10. return "", err
  11. }
  12. t := fmt.Sprintf(`"%s"`, wrapWithRawString(table.Name.Source(), postgreSql))
  13. if postgreSql {
  14. t = "`" + fmt.Sprintf(`"%s"."%s"`, table.Db.Source(), table.Name.Source()) + "`"
  15. }
  16. output, err := util.With("new").
  17. Parse(text).
  18. Execute(map[string]interface{}{
  19. "table": t,
  20. "withCache": withCache,
  21. "upperStartCamelObject": table.Name.ToCamel(),
  22. })
  23. if err != nil {
  24. return "", err
  25. }
  26. return output.String(), nil
  27. }