Add ILIKE helper function
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2021-07-30 17:51:11 +02:00
parent d0bde0cfd3
commit 549a87856e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 35 additions and 0 deletions

35
pkg/db/helpers.go Normal file
View File

@ -0,0 +1,35 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public Licensee as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package db
import (
"code.vikunja.io/api/pkg/config"
"xorm.io/builder"
)
// ILIKE returns an ILIKE query on postgres and a LIKE query on all other platforms.
// Postgres' is case sensitive by default.
// To work around this, we're using ILIKE as opposed to normal LIKE statements.
// ILIKE is preferred over LOWER(text) LIKE for performance reasons.
// See https://stackoverflow.com/q/7005302/10924593
func ILIKE(column, search string) builder.Cond {
if config.DatabaseType.GetString() == "postgres" {
return builder.Expr("`"+column+"` ILIKE ?", "%"+search+"%")
}
return &builder.Like{column, "%" + search + "%"}
}