utiltemplate.go 713 B

12345678910111213141516171819202122232425262728293031323334
  1. package modelgen
  2. const (
  3. utilTemplateText = `package {{.Package}}
  4. import (
  5. "errors"
  6. {{if .WithCache}}"github.com/tal-tech/go-zero/core/stores/redis"
  7. "github.com/tal-tech/go-zero/core/stores/sqlc"
  8. "github.com/tal-tech/go-zero/core/stores/sqlx"{{end}}
  9. )
  10. {{if .WithCache}}
  11. type CachedModel struct {
  12. table string
  13. conn sqlx.SqlConn
  14. rds *redis.Redis
  15. sqlc.CachedConn
  16. }
  17. func NewCachedModel(conn sqlx.SqlConn, table string, rds *redis.Redis) *CachedModel {
  18. return &CachedModel{
  19. table: table,
  20. conn: conn,
  21. rds: rds,
  22. CachedConn: sqlc.NewCachedConn(conn, rds),
  23. }
  24. }
  25. {{end}}
  26. var (
  27. ErrNotFound = errors.New("not found")
  28. )
  29. `
  30. )