Add resetter interface

v2
Nikita Tokarchuk 6 years ago
parent ea72b26e1d
commit 2207dc5afd
  1. 5
      mongox/common.go
  2. 5
      mongox/common/loadmany.go

@ -19,6 +19,11 @@ type Loader interface {
Load(db *Database, filters ...interface{}) error Load(db *Database, filters ...interface{}) error
} }
// Resetter is an interface for documenta that can be resetted
type Resetter interface {
Reset()
}
// BaseObjectID is an interface for documents that have objectId type for the _id field // BaseObjectID is an interface for documents that have objectId type for the _id field
type BaseObjectID interface { type BaseObjectID interface {
GetID() primitive.ObjectID GetID() primitive.ObjectID

@ -25,6 +25,11 @@ func (l *ManyLoader) Get() error {
return errors.NotFoundErrorf("%s", mongo.ErrNoDocuments) return errors.NotFoundErrorf("%s", mongo.ErrNoDocuments)
} }
resettable, canReset := l.target.(mongox.Resetter)
if canReset {
resettable.Reset()
}
err := l.Decode(l.target) err := l.Decode(l.target)
if err != nil { if err != nil {
return errors.InternalErrorf("can't decode desult: %s", err) return errors.InternalErrorf("can't decode desult: %s", err)

Loading…
Cancel
Save