dal/pkg/filters/Eq.go
Anton Nesterov d28d976b8e
[wip] dal golang
Signed-off-by: Anton Nesterov <anton@demiurg.io>
2024-08-07 21:16:40 +02:00

26 lines
415 B
Go

package filters
import (
"fmt"
)
type Eq struct {
Eq interface{} `json:"$eq"`
}
func (f Eq) FromJSON(data interface{}) Filter {
return FromJson[Eq](data)
}
func (f Eq) ToSQLPart(ctx Context) string {
if f.Eq == nil {
return ""
}
name := ctx.GetFieldName()
value := ctx.NormalizeValue(f.Eq)
if value == "NULL" {
return fmt.Sprintf("%s IS NULL", name)
}
return fmt.Sprintf("%s = %v", name, value)
}