mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Backport of #25613 Fixes #25564 Fixes #23191 - Api v2 search endpoint should return only the latest version matching the query - Api v3 search endpoint should return `take` packages not package versions
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// 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)}
 | 
						|
}
 | 
						|
 | 
						|
// 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 ""
 | 
						|
	}
 | 
						|
}
 |