Add reset to other load functions

v2
Nikita Tokarchuk 6 years ago
parent dad0a0598b
commit 61621c0a3a
  1. 7
      mongox/common/loadarray.go
  2. 3
      mongox/common/loadone.go

@ -4,6 +4,7 @@ import (
"reflect"
"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/mainnika/mongox-go-driver/mongox/query"
"go.mongodb.org/mongo-driver/mongo"
@ -58,9 +59,13 @@ func LoadArray(db *mongox.Database, target interface{}, filters ...interface{})
} else {
continue
}
} else if err = result.Decode(targetSliceV.Index(i).Interface()); err != nil {
} else {
elem := targetSliceV.Index(i).Interface()
base.Reset(elem)
if err = result.Decode(elem); err != nil {
continue
}
}
i++
}

@ -2,6 +2,7 @@ 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/mainnika/mongox-go-driver/mongox/query"
"go.mongodb.org/mongo-driver/mongo"
@ -30,5 +31,7 @@ func LoadOne(db *mongox.Database, target interface{}, filters ...interface{}) er
return errors.NotFoundErrorf("can't find result: %s", result.Err())
}
base.Reset(target)
return result.Decode(target)
}

Loading…
Cancel
Save