dao.go 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/rank/conf"
  5. xsql "go-common/library/database/sql"
  6. )
  7. // Dao dao
  8. type Dao struct {
  9. c *conf.Config
  10. dbArchive *xsql.DB
  11. dbStat *xsql.DB
  12. dbTV *xsql.DB
  13. }
  14. // New init mysql db
  15. func New(c *conf.Config) (dao *Dao) {
  16. dao = &Dao{
  17. c: c,
  18. dbArchive: xsql.NewMySQL(c.MySQL.BilibiliArchive),
  19. dbStat: xsql.NewMySQL(c.MySQL.ArchiveStat),
  20. dbTV: xsql.NewMySQL(c.MySQL.BilibiliTV),
  21. }
  22. return
  23. }
  24. // Close close the resource.
  25. func (d *Dao) Close() {
  26. d.dbArchive.Close()
  27. d.dbStat.Close()
  28. d.dbTV.Close()
  29. }
  30. // Ping dao ping
  31. func (d *Dao) Ping(c context.Context) error {
  32. var err error
  33. if err = d.dbArchive.Ping(c); err != nil {
  34. return err
  35. }
  36. if err = d.dbStat.Ping(c); err != nil {
  37. return err
  38. }
  39. return d.dbTV.Ping(c)
  40. }