mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-07-03 17:22:33 +00:00
Compose query inside common functions
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// LoadArray loads an array of documents from the database by query
|
// LoadArray loads an array of documents from the database by query
|
||||||
func LoadArray(db *mongox.Database, target interface{}, composed *query.Query) error {
|
func LoadArray(db *mongox.Database, target interface{}, filters ...interface{}) error {
|
||||||
|
|
||||||
targetV := reflect.ValueOf(target)
|
targetV := reflect.ValueOf(target)
|
||||||
targetT := targetV.Type()
|
targetT := targetV.Type()
|
||||||
@@ -34,6 +34,7 @@ func LoadArray(db *mongox.Database, target interface{}, composed *query.Query) e
|
|||||||
dummy := reflect.Zero(targetSliceElemT)
|
dummy := reflect.Zero(targetSliceElemT)
|
||||||
collection := db.GetCollectionOf(dummy.Interface())
|
collection := db.GetCollectionOf(dummy.Interface())
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
|
composed := query.Compose(filters...)
|
||||||
|
|
||||||
opts.Sort = composed.Sorter()
|
opts.Sort = composed.Sorter()
|
||||||
opts.Limit = composed.Limiter()
|
opts.Limit = composed.Limiter()
|
||||||
|
|||||||
@@ -41,10 +41,11 @@ func (l *ManyLoader) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadMany function loads documents one by one into a target channel
|
// LoadMany function loads documents one by one into a target channel
|
||||||
func LoadMany(db *mongox.Database, target interface{}, composed *query.Query) (*ManyLoader, error) {
|
func LoadMany(db *mongox.Database, target interface{}, filters ...interface{}) (*ManyLoader, error) {
|
||||||
|
|
||||||
collection := db.GetCollectionOf(target)
|
collection := db.GetCollectionOf(target)
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
|
composed := query.Compose(filters...)
|
||||||
|
|
||||||
opts.Sort = composed.Sorter()
|
opts.Sort = composed.Sorter()
|
||||||
opts.Limit = composed.Limiter()
|
opts.Limit = composed.Limiter()
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// LoadOne function loads a first single target document by a query
|
// LoadOne function loads a first single target document by a query
|
||||||
func LoadOne(db *mongox.Database, target interface{}, composed *query.Query) error {
|
func LoadOne(db *mongox.Database, target interface{}, filters ...interface{}) error {
|
||||||
|
|
||||||
collection := db.GetCollectionOf(target)
|
collection := db.GetCollectionOf(target)
|
||||||
opts := options.FindOne()
|
opts := options.FindOne()
|
||||||
|
composed := query.Compose(filters...)
|
||||||
|
|
||||||
opts.Sort = composed.Sorter()
|
opts.Sort = composed.Sorter()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user