fix(models): use client/orm instead of adapter/orm

- using new orm api, change some related logics
- newer orm api has the concept of TxOrmer, for purpose of transaction
handling. A transaction ormer in v2 is a stateful object, it should be
dropped after using. A Ormer object is stateless and thread(routine)
    safe, and should not be used for transaction handling. More details
    count be found at official doc:
    https://beego.me/docs/mvc/model/orm.md, and pr note: https://github.com/mindoc-org/mindoc/pull/662#issuecomment-807040262
This commit is contained in:
roberChen
2021-03-26 11:34:02 +08:00
parent 8b7d56a547
commit 916c9c6c2a
35 changed files with 135 additions and 89 deletions

View File

@@ -19,7 +19,7 @@ import (
"math"
"github.com/beego/beego/v2/adapter/orm"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"github.com/mindoc-org/mindoc/conf"
@@ -81,7 +81,7 @@ func (m *Member) Login(account string, password string) (*Member, error) {
logs.Info("转入 HTTP 接口登陆 ->", account)
return member.httpLogin(account, password)
} else {
logs.Error("user login for `%s`: %s",account, err)
logs.Error("user login for `%s`: %s", account, err)
return member, ErrMemberNoExist
}
}
@@ -180,7 +180,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
}
func (m *Member) httpLogin(account, password string) (*Member, error) {
urlStr,_ := web.AppConfig.String("http_login_url")
urlStr, _ := web.AppConfig.String("http_login_url")
if urlStr == "" {
return nil, ErrMemberAuthMethodInvalid
}
@@ -462,9 +462,9 @@ func (m *Member) Valid(is_hash_password bool) error {
//删除一个用户.
func (m *Member) Delete(oldId int, newId int) error {
o := orm.NewOrm()
ormer := orm.NewOrm()
err := o.Begin()
o, err := ormer.Begin()
if err != nil {
return err