dal/pkg/filters/Eq.go
Anton Nesterov 42ab71e964
[ref] use sfmt arguments i/of values in find expressions
Signed-off-by: Anton Nesterov <anton@demiurg.io>
2024-08-12 20:21:47 +02:00

26 lines
458 B
Go

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