refactor: using UsingPostgreSQL as condition

This commit is contained in:
JustSong 2023-12-24 16:38:47 +08:00
parent 45813555b2
commit 38f2ed1a29

View File

@ -6,7 +6,6 @@ import (
"gorm.io/gorm"
"one-api/common"
"strings"
"strconv"
)
// User if you add sensitive fields, don't forget to clean them in setupLogin function.
@ -43,12 +42,11 @@ func GetAllUsers(startIdx int, num int) (users []*User, err error) {
}
func SearchUsers(keyword string) (users []*User, err error) {
if uid, ok := strconv.Atoi(keyword); ok == nil {
err = DB.Omit("password").Where("id = ? or username LIKE ? or email LIKE ? or display_name LIKE ?", uid, keyword+"%", keyword+"%", keyword+"%").Find(&users).Error
if !common.UsingPostgreSQL {
err = DB.Omit("password").Where("id = ? or username LIKE ? or email LIKE ? or display_name LIKE ?", keyword, keyword+"%", keyword+"%", keyword+"%").Find(&users).Error
} else {
err = DB.Omit("password").Where("username LIKE ? or email LIKE ? or display_name LIKE ?", keyword+"%", keyword+"%", keyword+"%").Find(&users).Error
}
return users, err
}