Files
2026-07-10 17:07:54 +01:00

33 lines
608 B
Go

package sqimple
import "regexp"
var whereRegexp = regexp.MustCompile("^((and|or) )?(.+) (=|!=|>|>=|<|<=) (.+)?$")
type Where string
func (w Where) IsValid() bool {
return whereRegexp.MatchString(string(w))
}
func (w Where) Parse() (glue, column, operator string, value any, ok bool) {
if whereRegexp.MatchString(string(w)) {
ok = true
result := whereRegexp.FindAllStringSubmatch(string(w), -1)
for _, r := range result {
glue, column, operator, value = r[2], r[3], r[4], r[5]
if value == "?" {
value = nil
}
}
}
return
}
func (w Where) String() string {
return string(w)
}