2024-08-07 19:16:40 +00:00
|
|
|
package filters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"l12.xyz/dal/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type In struct {
|
|
|
|
In []interface{} `json:"$in"`
|
|
|
|
}
|
|
|
|
|
2024-08-08 17:26:29 +00:00
|
|
|
func (f In) FromJSON(data interface{}) IFilter {
|
2024-08-07 19:16:40 +00:00
|
|
|
return FromJson[In](data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f In) ToSQLPart(ctx Context) string {
|
|
|
|
if f.In == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
name := ctx.GetFieldName()
|
|
|
|
values := utils.Map(f.In, 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 IN (%v)", name, value)
|
|
|
|
}
|