From 38f2ed1a29446209a32995f4f6d193ac663359b0 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 24 Dec 2023 16:38:47 +0800 Subject: [PATCH] refactor: using UsingPostgreSQL as condition --- model/user.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/model/user.go b/model/user.go index 06cf685c..e738b1ba 100644 --- a/model/user.go +++ b/model/user.go @@ -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 }