dal/pkg/filters/registry.go

39 lines
769 B
Go
Raw Normal View History

package filters
2024-08-08 17:26:29 +00:00
import (
"reflect"
)
var FilterRegistry = map[string]IFilter{
"And": &And{},
"Or": &Or{},
"Eq": &Eq{},
"Ne": &Ne{},
"Gt": &Gt{},
"Gte": &Gte{},
"Lt": &Lt{},
"Lte": &Lte{},
"In": &In{},
"Nin": &NotIn{},
"Between": &Between{},
"NotBetween": &NotBetween{},
"Glob": &Glob{},
"Like": &Like{},
"NotLike": &NotLike{},
}
2024-08-08 17:26:29 +00:00
func Convert(ctx Context, data interface{}) (string, error) {
for _, impl := range FilterRegistry {
filter := impl.FromJSON(data)
if reflect.DeepEqual(impl, filter) {
2024-08-08 17:26:29 +00:00
continue
}
value := filter.ToSQLPart(ctx)
if value != "" {
2024-08-08 17:26:29 +00:00
return value, nil
}
}
2024-08-08 17:26:29 +00:00
value := Eq{Eq: data}.ToSQLPart(ctx)
return value, nil
}