dao.go 698 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/up-rating/conf"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. // Dao dao
  9. type Dao struct {
  10. c *conf.Config
  11. db *sql.DB
  12. }
  13. // New fn
  14. func New(c *conf.Config) (d *Dao) {
  15. log.Info("dao start")
  16. d = &Dao{
  17. c: c,
  18. db: sql.NewMySQL(c.MySQL.Rating),
  19. }
  20. //d.db.State = prom.LibClient
  21. return
  22. }
  23. // Ping ping health.
  24. func (d *Dao) Ping(c context.Context) (err error) {
  25. return d.db.Ping(c)
  26. }
  27. // Close close connections of mc, redis, db.
  28. func (d *Dao) Close() {
  29. if d.db != nil {
  30. d.db.Close()
  31. }
  32. }
  33. // BeginTran begin transcation
  34. func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
  35. return d.db.Begin(c)
  36. }