2024-08-07 19:16:40 +00:00
|
|
|
package filters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-08-20 19:10:21 +00:00
|
|
|
"github.com/nesterow/dal/pkg/utils"
|
2024-08-07 19:16:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Between struct {
|
|
|
|
Between []interface{} `json:"$between"`
|
|
|
|
}
|
|
|
|
|
2024-08-08 17:26:29 +00:00
|
|
|
func (f Between) FromJSON(data interface{}) IFilter {
|
2024-08-07 19:16:40 +00:00
|
|
|
return FromJson[Between](data)
|
|
|
|
}
|
|
|
|
|
2024-08-12 18:21:34 +00:00
|
|
|
func (f Between) ToSQLPart(ctx Dialect) (string, Values) {
|
2024-08-07 19:16:40 +00:00
|
|
|
if f.Between == nil {
|
2024-08-12 18:21:34 +00:00
|
|
|
return "", nil
|
2024-08-07 19:16:40 +00:00
|
|
|
}
|
|
|
|
name := ctx.GetFieldName()
|
|
|
|
values := utils.Map(f.Between, ctx.NormalizeValue)
|
2024-08-12 18:21:34 +00:00
|
|
|
placeholders := utils.Map(values, ValueOrPlaceholder)
|
|
|
|
condition := fmt.Sprintf("%s AND %s", placeholders[0], placeholders[1])
|
|
|
|
return fmt.Sprintf("%s BETWEEN %v", name, condition), values
|
2024-08-07 19:16:40 +00:00
|
|
|
}
|