dal/pkg/filters/Between.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

27 lines
587 B
Go

package filters
import (
"fmt"
"l12.xyz/dal/utils"
)
type Between struct {
Between []interface{} `json:"$between"`
}
func (f Between) FromJSON(data interface{}) IFilter {
return FromJson[Between](data)
}
func (f Between) ToSQLPart(ctx Dialect) (string, Values) {
if f.Between == nil {
return "", nil
}
name := ctx.GetFieldName()
values := utils.Map(f.Between, ctx.NormalizeValue)
placeholders := utils.Map(values, ValueOrPlaceholder)
condition := fmt.Sprintf("%s AND %s", placeholders[0], placeholders[1])
return fmt.Sprintf("%s BETWEEN %v", name, condition), values
}