推送
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

package hasaki_push
import (
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hsktime"
"git.ouxuan.net/tommy/hasaki-service-push/hasaki_push_options"
"xorm.io/xorm"
)
type Api struct {
db *xorm.Engine
config interface{}
}
func NewApi(db ...*xorm.Engine) *Api {
if len(db) > 0 {
return &Api{
db: db[0],
}
} else {
return &Api{
db: hskdb.GetXormAuto(),
}
}
}
func GetApi(ctx interface{}) *Api {
config := hasaki_push_options.GetMysqlConfig(ctx)
if config == nil {
api := NewApi(hskdb.GetXormAuto())
return api
} else {
api := NewApi(hskdb.GetXormAuto(config))
api.config = config
return api
}
}
type Model struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CreatedAt hsktime.Time `json:"created_at" xorm:"created comment('创建时间')"`
UpdatedAt hsktime.Time `json:"updated_at" xorm:"updated comment('更新时间')"`
DeletedAt hsktime.Time `json:"-" xorm:"deleted comment('是否删除') TIMESTAMP"`
Db *xorm.Engine `json:"-" xorm:"-"`
}
func NewModel(engs ...*xorm.Engine) *Model {
var eng *xorm.Engine
if len(engs) > 0 {
eng = engs[0]
} else {
eng = hskdb.GetXormAuto()
}
return &Model{
Db: eng,
}
}
func (api *Api) NewModel() *Model {
return &Model{Db: api.db}
}