dao.go 690 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package show
  2. import (
  3. "context"
  4. "go-common/app/admin/main/feed/conf"
  5. "go-common/library/database/orm"
  6. "github.com/jinzhu/gorm"
  7. )
  8. // Dao struct user of color egg Dao.
  9. type Dao struct {
  10. // db
  11. DB *gorm.DB
  12. }
  13. // New create a instance of color egg Dao and return.
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. // db
  17. DB: orm.NewMySQL(c.ORM),
  18. }
  19. d.initORM()
  20. return
  21. }
  22. func (d *Dao) initORM() {
  23. d.DB.LogMode(true)
  24. }
  25. // Ping check connection of db , mc.
  26. func (d *Dao) Ping(c context.Context) (err error) {
  27. if d.DB != nil {
  28. err = d.DB.DB().PingContext(c)
  29. return
  30. }
  31. return
  32. }
  33. // Close close connection of db , mc.
  34. func (d *Dao) Close() {
  35. if d.DB != nil {
  36. d.DB.Close()
  37. }
  38. }