mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-07-03 17:22:33 +00:00
Allow to combine query filter purposes
This commit is contained in:
+15
-10
@@ -9,6 +9,8 @@ import (
|
|||||||
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
|
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type applyFilterFunc = func(query *Query, filter interface{}) (ok bool)
|
||||||
|
|
||||||
// Compose is a function to compose filters into a single query
|
// Compose is a function to compose filters into a single query
|
||||||
func Compose(filters ...interface{}) (query *Query) {
|
func Compose(filters ...interface{}) (query *Query) {
|
||||||
|
|
||||||
@@ -30,17 +32,20 @@ func Push(q *Query, f interface{}) (ok bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = false
|
for _, applier := range []applyFilterFunc{
|
||||||
ok = ok || applyBson(q, f)
|
applyBson,
|
||||||
ok = ok || applyLimit(q, f)
|
applyLimit,
|
||||||
ok = ok || applySort(q, f)
|
applySort,
|
||||||
ok = ok || applySkip(q, f)
|
applySkip,
|
||||||
ok = ok || applyProtection(q, f)
|
applyProtection,
|
||||||
ok = ok || applyPreloader(q, f)
|
applyPreloader,
|
||||||
ok = ok || applyUpdater(q, f)
|
applyUpdater,
|
||||||
ok = ok || applyCallbacks(q, f)
|
applyCallbacks,
|
||||||
|
} {
|
||||||
|
ok = applier(q, f) || ok
|
||||||
|
}
|
||||||
|
|
||||||
return ok
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyBson is a fallback for a custom primitive.M
|
// applyBson is a fallback for a custom primitive.M
|
||||||
|
|||||||
Reference in New Issue
Block a user