2024-08-08 09:09:17 +00:00
|
|
|
package filters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2024-08-20 13:53:12 +00:00
|
|
|
"github.com/nesterow/dal/pkg/utils"
|
2024-08-08 09:09:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type NotIn struct {
|
|
|
|
NotIn []interface{} `json:"$nin"`
|
|
|
|
}
|
|
|
|
|
2024-08-08 17:26:29 +00:00
|
|
|
func (f NotIn) FromJSON(data interface{}) IFilter {
|
2024-08-08 09:09:17 +00:00
|
|
|
return FromJson[NotIn](data)
|
|
|
|
}
|
|
|
|
|
2024-08-12 18:21:34 +00:00
|
|
|
func (f NotIn) ToSQLPart(ctx Dialect) (string, Values) {
|
2024-08-08 09:09:17 +00:00
|
|
|
if f.NotIn == nil {
|
2024-08-12 18:21:34 +00:00
|
|
|
return "", nil
|
2024-08-08 09:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
name := ctx.GetFieldName()
|
|
|
|
values := utils.Map(f.NotIn, ctx.NormalizeValue)
|
2024-08-12 18:21:34 +00:00
|
|
|
returnValues := make(Values, 0)
|
2024-08-08 09:09:17 +00:00
|
|
|
data := make([]string, len(values))
|
2024-08-12 18:21:34 +00:00
|
|
|
for i, value := range values {
|
|
|
|
val := ValueOrPlaceholder(value).(string)
|
|
|
|
data[i] = val
|
|
|
|
if val == "?" {
|
|
|
|
returnValues = append(returnValues, value)
|
|
|
|
}
|
2024-08-08 09:09:17 +00:00
|
|
|
}
|
|
|
|
value := strings.Join(data, ", ")
|
2024-08-12 18:21:34 +00:00
|
|
|
return fmt.Sprintf("%s NOT IN (%v)", name, value), returnValues
|
2024-08-08 09:09:17 +00:00
|
|
|
}
|