dao.go 463 B

123456789101112131415161718192021222324252627282930313233
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/infra/databus/conf"
  5. "go-common/library/database/sql"
  6. )
  7. // Dao mysql struct
  8. type Dao struct {
  9. db *sql.DB
  10. }
  11. // New new a Dao and return
  12. func New(c *conf.Config) (d *Dao) {
  13. d = &Dao{
  14. db: sql.NewMySQL(c.MySQL),
  15. }
  16. return
  17. }
  18. // Ping ping mysql
  19. func (d *Dao) Ping(c context.Context) error {
  20. return d.db.Ping(c)
  21. }
  22. // Close release mysql connection
  23. func (d *Dao) Close() {
  24. if d.db != nil {
  25. d.db.Close()
  26. }
  27. }