dao.go 530 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/credit-timer/conf"
  5. "go-common/library/database/sql"
  6. )
  7. // Dao struct info of Dao.
  8. type Dao struct {
  9. db *sql.DB
  10. c *conf.Config
  11. }
  12. // New new a Dao and return.
  13. func New(c *conf.Config) (d *Dao) {
  14. d = &Dao{
  15. c: c,
  16. db: sql.NewMySQL(c.Mysql),
  17. }
  18. return
  19. }
  20. // Close close connections of mc, redis, db.
  21. func (d *Dao) Close() {
  22. if d.db != nil {
  23. d.db.Close()
  24. }
  25. }
  26. // Ping ping health of db.
  27. func (d *Dao) Ping(c context.Context) (err error) {
  28. return d.db.Ping(c)
  29. }