fix(user): Adding quotes to the user keyword to fix compatibility issues under PostgreSQL #424

This commit is contained in:
LinkinStars 2023-08-31 16:16:45 +08:00
parent 9fded40c3d
commit 50beae6104
2 changed files with 7 additions and 7 deletions

View File

@ -258,7 +258,7 @@ func (ar *answerRepo) SearchList(ctx context.Context, search *entity.AnswerSearc
search.PageSize = constant.DefaultPageSize
}
offset := search.Page * search.PageSize
session := ar.data.DB.Context(ctx).Where("")
session := ar.data.DB.Context(ctx)
if search.QuestionID != "" {
session = session.And("question_id = ?", search.QuestionID)

View File

@ -131,21 +131,21 @@ func (ur *userAdminRepo) GetUserPage(ctx context.Context, page, pageSize int, us
session := ur.data.DB.Context(ctx)
switch user.Status {
case entity.UserStatusDeleted:
session.Desc("user.deleted_at")
session.Desc("`user`.deleted_at")
case entity.UserStatusSuspended:
session.Desc("user.suspended_at")
session.Desc("`user`.suspended_at")
default:
session.Desc("user.created_at")
session.Desc("`user`.created_at")
}
if len(usernameOrDisplayName) > 0 {
session.And(builder.Or(
builder.Like{"user.username", usernameOrDisplayName},
builder.Like{"user.display_name", usernameOrDisplayName},
builder.Like{"`user`.username", usernameOrDisplayName},
builder.Like{"`user`.display_name", usernameOrDisplayName},
))
}
if isStaff {
session.Join("INNER", "user_role_rel", "user.id = user_role_rel.user_id AND user_role_rel.role_id > 1")
session.Join("INNER", "user_role_rel", "`user`.id = `user_role_rel`.user_id AND `user_role_rel`.role_id > 1")
}
total, err = pager.Help(page, pageSize, &users, user, session)