db 管理初始化

This commit is contained in:
wuchao 2024-11-27 16:56:37 +08:00
parent 09d482ac5f
commit 16eddb135c
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package crondbmodel
import (
"github.com/qit-team/snow-core/db"
"sync"
"time"
)
var (
once sync.Once
m *CronDbModel
)
// 实体
type CronDb struct {
DbId string `xorm:"'db_id' UNSIGNED INT"`
DbName string `xorm:"'db_name' varchar(20)"`
DbType string `xorm:"'db_type' varchar(10)"`
DbPermission int `xorm:"'db_permission' TINYINT"`
Source string `xorm:"'source' varchar(150)"`
Desc string `xorm:"'desc' varchar(200)"`
CreateTime time.Time `xorm:"'create_time' datetime"`
UpdateTime time.Time `xorm:"'update_time' timestamp"`
Status int `xorm:"'status' TINYINT"`
}
// 表名
func (m *CronDb) TableName() string {
return "cron_db"
}
// 私有化防止被外部new
type CronDbModel struct {
db.Model //组合基础Model集成基础Model的属性和方法
}
// 单例模式
func GetInstance() *CronDbModel {
once.Do(func() {
m = new(CronDbModel)
//m.DiName = "" //设置数据库实例连接默认db.SingletonMain
})
return m
}