findone.go 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. package gen
  2. import (
  3. "github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
  4. "github.com/tal-tech/go-zero/tools/goctl/util"
  5. "github.com/tal-tech/go-zero/tools/goctl/util/stringx"
  6. )
  7. func genFindOne(table Table, withCache bool) (string, error) {
  8. camel := table.Name.ToCamel()
  9. text, err := util.LoadTemplate(category, findOneTemplateFile, template.FindOne)
  10. if err != nil {
  11. return "", err
  12. }
  13. output, err := util.With("findOne").
  14. Parse(text).
  15. Execute(map[string]interface{}{
  16. "withCache": withCache,
  17. "upperStartCamelObject": camel,
  18. "lowerStartCamelObject": stringx.From(camel).UnTitle(),
  19. "originalPrimaryKey": table.PrimaryKey.Name.Source(),
  20. "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(),
  21. "dataType": table.PrimaryKey.DataType,
  22. "cacheKey": table.CacheKey[table.PrimaryKey.Name.Source()].KeyExpression,
  23. "cacheKeyVariable": table.CacheKey[table.PrimaryKey.Name.Source()].Variable,
  24. })
  25. if err != nil {
  26. return "", err
  27. }
  28. return output.String(), nil
  29. }