dao.go 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package manager
  2. import (
  3. "context"
  4. "go-common/app/service/main/videoup/conf"
  5. "go-common/library/database/sql"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. const (
  9. _searchUpdateURL = "/x/admin/search/upsert"
  10. )
  11. // Dao is redis dao.
  12. type Dao struct {
  13. c *conf.Config
  14. managerDB *sql.DB
  15. // select stmt
  16. upsStmt *sql.Stmt
  17. httpW *bm.Client
  18. searchUpdateURL string
  19. }
  20. // New fn
  21. func New(c *conf.Config) (d *Dao) {
  22. d = &Dao{
  23. c: c,
  24. managerDB: sql.NewMySQL(c.DB.Manager),
  25. httpW: bm.NewClient(c.HTTPClient.Write),
  26. searchUpdateURL: c.Host.Manager + _searchUpdateURL,
  27. }
  28. // select stmt
  29. d.upsStmt = d.managerDB.Prepared(_upsSQL)
  30. return d
  31. }
  32. // Close fn
  33. func (d *Dao) Close() {
  34. if d.managerDB != nil {
  35. d.managerDB.Close()
  36. }
  37. }
  38. // Ping ping cpdb
  39. func (d *Dao) Ping(c context.Context) (err error) {
  40. return d.managerDB.Ping(c)
  41. }