[feat] add filter registry

Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
Anton Nesterov 2024-08-15 09:19:33 +02:00
parent 296595cfea
commit ffb64f1d65
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
2 changed files with 7 additions and 1 deletions

View file

@ -22,6 +22,12 @@ var FilterRegistry = map[string]IFilter{
"NotLike": &NotLike{}, "NotLike": &NotLike{},
} }
// RegisterFilter registers a new filter for a given name.
// `name` is the name of the filter, and `filter` is an empty instance (&reference) of the IFilter.
func RegisterFilter(name string, filter IFilter) {
FilterRegistry[name] = filter
}
func Convert(ctx Dialect, data interface{}) (string, []interface{}) { func Convert(ctx Dialect, data interface{}) (string, []interface{}) {
for _, impl := range FilterRegistry { for _, impl := range FilterRegistry {
filter := impl.FromJSON(data) filter := impl.FromJSON(data)

View file

@ -7,7 +7,7 @@ import (
adapter "l12.xyz/dal/adapter" adapter "l12.xyz/dal/adapter"
) )
type SQLiteContext = adapter.SQLite type SQLiteContext = adapter.CommonDialect
func TestEq(t *testing.T) { func TestEq(t *testing.T) {
ctx := SQLiteContext{ ctx := SQLiteContext{