dal/pkg/filters/NotIn.go

32 lines
563 B
Go
Raw Normal View History

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 {
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)
}