package sqlutil import ( "bytes" "fmt" "strings" ) var escapeArray = []string{"\\", "%"} func LikeFormat(name string) string { return "%" + escape(name) + "%" } func LeftLikeFormat(name string) string { return "%" + escape(name) } func RightLikeFormat(name string) string { return escape(name) + "%" } func escape(name string) string { for i := range escapeArray { name = strings.ReplaceAll(name, escapeArray[i], "\\"+escapeArray[i]) } return name } func OrderByFieldInt(column string, arg ...int) string { of := bytes.NewBufferString("FIELD(" + column + ", ") for i := range arg { if i < len(arg)-1 { of.WriteString(fmt.Sprintf("%v, ", arg[i])) } else { of.WriteString(fmt.Sprintf("%v) ", arg[i])) } } return of.String() }