2024-08-07 19:16:40 +00:00
|
|
|
package filters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Eq struct {
|
|
|
|
Eq interface{} `json:"$eq"`
|
|
|
|
}
|
|
|
|
|
2024-08-08 17:26:29 +00:00
|
|
|
func (f Eq) FromJSON(data interface{}) IFilter {
|
2024-08-07 19:16:40 +00:00
|
|
|
return FromJson[Eq](data)
|
|
|
|
}
|
|
|
|
|
2024-08-12 18:21:34 +00:00
|
|
|
func (f Eq) ToSQLPart(ctx Dialect) (string, Values) {
|
2024-08-07 19:16:40 +00:00
|
|
|
if f.Eq == nil {
|
2024-08-12 18:21:34 +00:00
|
|
|
return "", nil
|
2024-08-07 19:16:40 +00:00
|
|
|
}
|
|
|
|
name := ctx.GetFieldName()
|
|
|
|
value := ctx.NormalizeValue(f.Eq)
|
|
|
|
if value == "NULL" {
|
2024-08-12 18:21:34 +00:00
|
|
|
return fmt.Sprintf("%s IS NULL", ValueOrPlaceholder(name)), Values{name}
|
2024-08-07 19:16:40 +00:00
|
|
|
}
|
2024-08-12 18:21:34 +00:00
|
|
|
return FmtCompare("=", name, value)
|
2024-08-07 19:16:40 +00:00
|
|
|
}
|