- Most functions now live directly in the dbx package - dbxp and dbxm are now ONLY the few functions that cannot be shared
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package dbx
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/go-jet/jet/v2/mysql"
|
|
)
|
|
|
|
// StringToFilter processes a string to be used as a filter in an SQL LIKE
|
|
// statement. It replaces all spaces with % and adds % to the beginning and
|
|
// end of the string.
|
|
func StringToFilter(str string) string {
|
|
// Remove any existing leading or trailing % characters
|
|
str = strings.Trim(str, "%")
|
|
|
|
// Replace all spaces with % and add % to the beginning and end of the string
|
|
str = strings.ReplaceAll(str, " ", "%")
|
|
str = "%" + str + "%"
|
|
|
|
return str
|
|
}
|
|
|
|
// ExprID converts a list of uint64 values to a list of mysql.Expression values
|
|
func ExprID(ids []uint64) []mysql.Expression {
|
|
expressions := make([]mysql.Expression, len(ids))
|
|
for i, id := range ids {
|
|
expressions[i] = mysql.Uint64(id)
|
|
}
|
|
return expressions
|
|
}
|
|
|
|
// ExprEnum converts a list of uint8 values to a list of mysql.Expression values
|
|
func ExprEnum(enums []uint8) []mysql.Expression {
|
|
expressions := make([]mysql.Expression, len(enums))
|
|
for i, enum := range enums {
|
|
expressions[i] = mysql.Uint8(enum)
|
|
}
|
|
return expressions
|
|
}
|