dal/pkg/filters/Between.go

27 lines
587 B
Go
Raw Normal View History

package filters
import (
"fmt"
"l12.xyz/dal/utils"
)
type Between struct {
Between []interface{} `json:"$between"`
}
2024-08-08 17:26:29 +00:00
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
}