Add callback support to a saving

This commit is contained in:
Nikita Tokarchuk
2020-07-22 04:45:32 +02:00
parent 06f6f48f11
commit 87708fee04
+13 -1
View File
@@ -32,10 +32,22 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
protected.V = time.Now().Unix()
}
defer composed.OnClose().Invoke(ctx, source)
result := collection.FindOneAndReplace(ctx, composed.M(), source, opts)
if result.Err() != nil {
return result.Err()
}
return result.Decode(source)
err = result.Decode(source)
if err != nil {
return
}
err = composed.OnDecode().Invoke(ctx, source)
if err != nil {
return
}
return
}