mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package db
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
|
|
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
|
|
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
|
|
if setting.Database.Type.IsSQLite3() {
|
|
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
|
|
}
|
|
return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
|
|
}
|
|
|
|
// BuildCaseInsensitiveIn returns a condition to check if the given value is in the given values case-insensitively.
|
|
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
|
|
func BuildCaseInsensitiveIn(key string, values []string) builder.Cond {
|
|
uppers := make([]string, 0, len(values))
|
|
if setting.Database.Type.IsSQLite3() {
|
|
for _, value := range values {
|
|
uppers = append(uppers, util.ToUpperASCII(value))
|
|
}
|
|
} else {
|
|
for _, value := range values {
|
|
uppers = append(uppers, strings.ToUpper(value))
|
|
}
|
|
}
|
|
|
|
return builder.In("UPPER("+key+")", uppers)
|
|
}
|
|
|