dao.go 536 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package dao

import (
	"github.com/go-kratos/kratos/v2/log"
	"github.com/google/wire"
	"gorm.io/gorm"
	"hilo/app/service/mgr/internal/conf"
	"hilo/common/mysql"
)

// ProviderSet is dao providers.
var ProviderSet = wire.NewSet(NewDao)

// Dao .
type Dao struct {
	// TODO wrapped database client
	DB *gorm.DB
}

// NewDao .
func NewDao(c *conf.Data) (*Dao, func(), error) {
	db := mysql.NewDB(c.Mysql)
	cleanup := func() {
		d, _ := db.DB()
		d.Close()
		log.Debug("close data resources")
	}

	return &Dao{
		DB: db,
	}, cleanup, nil
}