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