dao.go 623 B

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