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 }