dao.go 635 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/job/main/videoup-report/conf"
  5. "go-common/library/database/sql"
  6. )
  7. // Dao is redis dao.
  8. type Dao struct {
  9. c *conf.Config
  10. // db
  11. db *sql.DB
  12. }
  13. // New new a dao.
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. c: c,
  17. db: sql.NewMySQL(c.DB.Archive),
  18. }
  19. // select
  20. return d
  21. }
  22. // BeginTran begin transcation.
  23. func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
  24. return d.db.Begin(c)
  25. }
  26. // Close close dao.
  27. func (d *Dao) Close() {
  28. if d.db != nil {
  29. d.db.Close()
  30. }
  31. }
  32. // Ping ping cpdb
  33. func (d *Dao) Ping(c context.Context) (err error) {
  34. return d.db.Ping(c)
  35. }