dal/pkg/filters/NotIn.go
2024-08-08 19:26:29 +02:00

32 lines
563 B
Go

package filters
import (
"fmt"
"strings"
"l12.xyz/dal/utils"
)
type NotIn struct {
NotIn []interface{} `json:"$nin"`
}
func (f NotIn) FromJSON(data interface{}) IFilter {
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)
}