Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package db
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/setting"
|
|
"code.gitcaddy.com/server/v3/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)
|
|
}
|
|
|
|
// BuilderDialect returns the xorm.Builder dialect of the engine
|
|
func BuilderDialect() string {
|
|
switch {
|
|
case setting.Database.Type.IsMySQL():
|
|
return builder.MYSQL
|
|
case setting.Database.Type.IsSQLite3():
|
|
return builder.SQLITE
|
|
case setting.Database.Type.IsPostgreSQL():
|
|
return builder.POSTGRES
|
|
case setting.Database.Type.IsMSSQL():
|
|
return builder.MSSQL
|
|
default:
|
|
return ""
|
|
}
|
|
}
|