123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package kfc
- import (
- "context"
- "go-common/app/admin/main/activity/conf"
- "go-common/library/database/orm"
- "github.com/jinzhu/gorm"
- )
- type Dao struct {
- c *conf.Config
- DB *gorm.DB
- }
- func New(c *conf.Config) (d *Dao) {
- d = &Dao{
- c: c,
- DB: orm.NewMySQL(c.ORM),
- }
- d.initORM()
- return
- }
- func (d *Dao) initORM() {
- gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
- if defaultTableName == "act_matchs" {
- return defaultTableName
- }
- return defaultTableName
- }
- d.DB.LogMode(true)
- }
- func (d *Dao) Ping(c context.Context) (err error) {
- if d.DB != nil {
- err = d.DB.DB().PingContext(c)
- }
- return
- }
- func (d *Dao) Close() {
- if d.DB != nil {
- d.DB.Close()
- }
- }
|