findone.go 1.0 KB

123456789101112131415161718192021222324252627
  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/stringx"
  5. "github.com/tal-tech/go-zero/tools/goctl/util/templatex"
  6. )
  7. func genFindOne(table Table, withCache bool) (string, error) {
  8. camel := table.Name.Snake2Camel()
  9. output, err := templatex.With("findOne").
  10. Parse(template.FindOne).
  11. Execute(map[string]interface{}{
  12. "withCache": withCache,
  13. "upperStartCamelObject": camel,
  14. "lowerStartCamelObject": stringx.From(camel).LowerStart(),
  15. "originalPrimaryKey": table.PrimaryKey.Name.Source(),
  16. "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.Snake2Camel()).LowerStart(),
  17. "dataType": table.PrimaryKey.DataType,
  18. "cacheKey": table.CacheKey[table.PrimaryKey.Name.Source()].KeyExpression,
  19. "cacheKeyVariable": table.CacheKey[table.PrimaryKey.Name.Source()].Variable,
  20. })
  21. if err != nil {
  22. return "", err
  23. }
  24. return output.String(), nil
  25. }