enhance(repository):改进查询条件的生成方式。

This commit is contained in:
徐涛
2022-08-12 13:53:52 +08:00
parent b9b9a9c738
commit 0692b246c1
3 changed files with 7 additions and 4 deletions

View File

@@ -4,6 +4,8 @@ import (
"electricity_bill_calc/cache"
"electricity_bill_calc/global"
"electricity_bill_calc/model"
"xorm.io/builder"
)
type _UserRepository struct{}
@@ -16,7 +18,7 @@ func (_UserRepository) FindUserByUsername(username string) (*model.User, error)
return cachedUser, nil
}
user := new(model.User)
has, err := global.DBConn.Where("username=?", username).Get(user)
has, err := global.DBConn.Where(builder.Eq{"username": username}).Get(user)
if has {
cache.CacheData(user, "user", username)
}
@@ -29,7 +31,7 @@ func (_UserRepository) RetreiveUserDetail(uid string) (*model.UserDetail, error)
return cachedUser, nil
}
user := new(model.UserDetail)
has, err := global.DBConn.Where("id=?", uid).Get(user)
has, err := global.DBConn.ID(uid).Get(user)
if has {
cache.CacheData(user, "user_detail", uid)
}