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.
54 lines
1021 B
54 lines
1021 B
package hasaki_{{.app_name}}
|
|
|
|
import (
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
|
|
"git.ouxuan.net/hasaki-service/hasaki-service-{{.app_name}}/hasaki_{{.app_name}}_options"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
type Api struct {
|
|
db *xorm.Engine
|
|
config interface{}
|
|
session *xorm.Session
|
|
}
|
|
|
|
func NewApi(dbs ...*xorm.Engine) *Api {
|
|
var db *xorm.Engine
|
|
if len(dbs) > 0 {
|
|
db = dbs[0]
|
|
} else {
|
|
db = hskdb.GetXormAuto()
|
|
}
|
|
return &Api{
|
|
db: db,
|
|
session: db.NewSession(),
|
|
}
|
|
}
|
|
|
|
func (api *Api) SetSession(s *xorm.Session) {
|
|
api.session = s
|
|
}
|
|
|
|
func (api *Api) NewSession() *xorm.Session {
|
|
return api.session
|
|
}
|
|
|
|
func GetApi(ctx interface{}) *Api {
|
|
config := hasaki_value_card_options.GetMysqlConfig(ctx)
|
|
if config == nil {
|
|
api := NewApi(hskdb.GetXormAuto())
|
|
return api
|
|
} else {
|
|
api := NewApi(hskdb.GetXormAuto(config))
|
|
api.config = config
|
|
return api
|
|
}
|
|
}
|
|
|
|
func (api *Api) InitDb() (err error) {
|
|
return InitDb(api.config)
|
|
}
|
|
|
|
func InitDbByConfig(config interface{}) (err error) {
|
|
return InitDb(config)
|
|
}
|