Code cleanup
This commit is contained in:
14
filter.go
14
filter.go
@@ -1,6 +1,5 @@
|
||||
package mongo
|
||||
|
||||
// import "runtime"
|
||||
import "log"
|
||||
|
||||
type Query struct {
|
||||
@@ -14,9 +13,6 @@ type Filter struct {
|
||||
}
|
||||
|
||||
func makeFilter(name string, value any) *Filter {
|
||||
|
||||
log.Printf("type is %T", value)
|
||||
|
||||
var op string
|
||||
|
||||
var v string
|
||||
@@ -53,7 +49,6 @@ func Mongofy(q *Query) map[string]any {
|
||||
|
||||
logic := "and"
|
||||
|
||||
// runtime.Breakpoint()
|
||||
for k, v := range q.Filter {
|
||||
if k == "_logic" {
|
||||
logic = v.(string)
|
||||
@@ -63,21 +58,20 @@ func Mongofy(q *Query) map[string]any {
|
||||
|
||||
f := makeFilter(k, v)
|
||||
|
||||
log.Printf("=> filter: %#v", f)
|
||||
|
||||
mongoOp := mapToOp(f.Op)
|
||||
|
||||
conditions = append(conditions, map[string]any{ k: map[string]any{ mongoOp: f.Value }})
|
||||
}
|
||||
|
||||
if len(conditions) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if logic == "or" {
|
||||
return map[string]any{
|
||||
"$or": conditions,
|
||||
}
|
||||
}
|
||||
// if filter == nil {
|
||||
// return filter
|
||||
// }
|
||||
|
||||
return map[string]any{
|
||||
"$and": conditions,
|
||||
|
||||
Reference in New Issue
Block a user