2024-08-08 09:09:17 +00:00
|
|
|
package filters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"l12.xyz/dal/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f NotIn) ToSQLPart(ctx Context) string {
|
|
|
|
if f.NotIn == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
name := ctx.GetFieldName()
|
|
|
|
values := utils.Map(f.NotIn, ctx.NormalizeValue)
|
|
|
|
data := make([]string, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
data[i] = fmt.Sprintf("%v", v)
|
|
|
|
}
|
|
|
|
value := strings.Join(data, ", ")
|
|
|
|
return fmt.Sprintf("%s NOT IN (%v)", name, value)
|
|
|
|
}
|