mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-23 00:03:36 +00:00
Limiter and Sorter should return ready-to-use values
This commit is contained in:
@@ -33,15 +33,10 @@ func LoadArray(db *mongox.Database, target interface{}, composed *query.Query) e
|
||||
|
||||
dummy := reflect.Zero(targetSliceElemT)
|
||||
collection := db.GetCollectionOf(dummy.Interface())
|
||||
opts := &options.FindOptions{}
|
||||
opts := options.Find()
|
||||
|
||||
if composed.Sorter() != nil {
|
||||
opts.Sort = composed.Sorter().Sort()
|
||||
}
|
||||
if composed.Limiter() != nil {
|
||||
limit := int64(composed.Limiter().Limit())
|
||||
opts.Limit = &limit
|
||||
}
|
||||
opts.Sort = composed.Sorter()
|
||||
opts.Limit = composed.Limiter()
|
||||
|
||||
result, err := collection.Find(db.Context(), composed.M(), opts)
|
||||
if err != nil {
|
||||
|
||||
@@ -44,15 +44,10 @@ func (l *ManyLoader) Close() error {
|
||||
func LoadMany(db *mongox.Database, target interface{}, composed *query.Query) (*ManyLoader, error) {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := &options.FindOptions{}
|
||||
opts := options.Find()
|
||||
|
||||
if composed.Sorter() != nil {
|
||||
opts.Sort = composed.Sorter().Sort()
|
||||
}
|
||||
if composed.Limiter() != nil {
|
||||
limit := int64(composed.Limiter().Limit())
|
||||
opts.Limit = &limit
|
||||
}
|
||||
opts.Sort = composed.Sorter()
|
||||
opts.Limit = composed.Limiter()
|
||||
|
||||
cursor, err := collection.Find(db.Context(), composed.M(), opts)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,11 +12,9 @@ import (
|
||||
func LoadOne(db *mongox.Database, target interface{}, composed *query.Query) error {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := &options.FindOneOptions{}
|
||||
opts := options.FindOne()
|
||||
|
||||
if composed.Sorter() != nil {
|
||||
opts.Sort = composed.Sorter().Sort()
|
||||
}
|
||||
opts.Sort = composed.Sorter()
|
||||
|
||||
result := collection.FindOne(db.Context(), composed.M(), opts)
|
||||
if result.Err() != nil {
|
||||
|
||||
@@ -2,9 +2,9 @@ package common
|
||||
|
||||
import (
|
||||
"github.com/mainnika/mongox-go-driver/mongox"
|
||||
"github.com/mainnika/mongox-go-driver/mongox/base"
|
||||
"github.com/mainnika/mongox-go-driver/mongox/errors"
|
||||
"github.com/mongodb/mongo-go-driver/bson"
|
||||
"github.com/mongodb/mongo-go-driver/bson/primitive"
|
||||
"github.com/mongodb/mongo-go-driver/mongo/options"
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func SaveOne(db *mongox.Database, source interface{}) error {
|
||||
|
||||
collection := db.GetCollectionOf(source)
|
||||
opts := &options.FindOneAndReplaceOptions{}
|
||||
opts := options.FindOneAndReplace()
|
||||
id := base.GetID(source)
|
||||
|
||||
opts.SetUpsert(true)
|
||||
|
||||
Reference in New Issue
Block a user