dao.go 431 B

123456789101112131415161718192021222324252627282930313233
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/space/conf"
  5. "go-common/library/database/orm"
  6. "github.com/jinzhu/gorm"
  7. )
  8. // Dao .
  9. type Dao struct {
  10. c *conf.Config
  11. DB *gorm.DB
  12. }
  13. // New .
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. // conf
  17. c: c,
  18. // db
  19. DB: orm.NewMySQL(c.ORM),
  20. }
  21. d.DB.LogMode(true)
  22. return
  23. }
  24. // Ping .
  25. func (d *Dao) Ping(c context.Context) error {
  26. return d.DB.DB().PingContext(c)
  27. }