|
@@ -36,11 +36,23 @@ func (s *List) Result(pg *gorm.DB, fields rest.FieldNamesList, res any) (count i
|
|
|
err = rest.ErrorFiled(cond.Field, "Unexpected field")
|
|
|
return
|
|
|
}
|
|
|
- q := fmt.Sprintf("%s %s ?", CamelToSnake(cond.Field), cond.Operator)
|
|
|
- if i == 0 || cond.Logic == rest.LogicAND {
|
|
|
- pg = pg.Where(q, cond.Value)
|
|
|
+ if cond.Value == nil {
|
|
|
+ q := fmt.Sprintf("%s %s ?", CamelToSnake(cond.Field), cond.Operator)
|
|
|
+ if i == 0 || cond.Logic == rest.LogicAND {
|
|
|
+ pg = pg.Where(q, cond.Value)
|
|
|
+ } else {
|
|
|
+ pg = pg.Or(q, cond.Value)
|
|
|
+ }
|
|
|
} else {
|
|
|
- pg = pg.Or(q, cond.Value)
|
|
|
+ if cond.Operator != "" && cond.Operator != rest.OperatorNot {
|
|
|
+ err = rest.ErrorFiled(cond.Field, "Expected empty operator or not")
|
|
|
+ }
|
|
|
+ q := fmt.Sprintf("%s is %s null", CamelToSnake(cond.Field), cond.Operator)
|
|
|
+ if i == 0 || cond.Logic == rest.LogicAND {
|
|
|
+ pg = pg.Where(q, cond.Value)
|
|
|
+ } else {
|
|
|
+ pg = pg.Or(q, cond.Value)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|