models.go中(由默认库切换到Logdb库)
```go
func GiftList(params *GiftQueryParam) ([]*Gift, int64) {
o := orm.NewOrm()
o.Using("Logdb")
query := o.QueryTable(GiftTBName())
data := make([]*Gift, 0)
//默认排序
sortorder := "ID"
switch params.Sort {
case "ID":
sortorder = "ID"
}
if params.Order == "desc" {
sortorder = "-" + sortorder
}
query = query.Filter("creatname__istartswith", params.CreatNameLike)
total, _ := query.Count()
query.OrderBy(sortorder).Limit(params.Limit, params.Offset).All(&data)
return data, total
}
```
在initDatabases里边也配置了Logdb:
```go
case "mysql":
dbCharset := beego.AppConfig.String(dbType + "::db_charset")
orm.RegisterDataBase(dbAlias, dbType, dbUser+":"+dbPwd+"@tcp("+dbHost+":"+
dbPort+")/"+dbName+"?charset="+dbCharset, 30)
orm.RegisterDataBase("Logdb", "mysql", beego.AppConfig.String(dbType+"::Logdb"))
}
```
当我执行是出现:
user:<Ormer.QueryTable> table name: `gift_score_log` not exists
还是使用的我的default库 如何才能切换过去,跪谢各位大神给个栗子
有疑问加站长微信联系(非本文作者)