Add callback support to a single deleting

v2
Nikita Tokarchuk 4 years ago
parent 8fcd764a8c
commit 848703d56d
  1. 10
      mongox/database/deleteone.go

@ -33,12 +33,22 @@ func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err er
protected.V = time.Now().Unix() protected.V = time.Now().Unix()
} }
defer composed.OnClose().Invoke(ctx, target)
result := collection.FindOneAndDelete(ctx, composed.M(), opts) result := collection.FindOneAndDelete(ctx, composed.M(), opts)
if result.Err() != nil { if result.Err() != nil {
return fmt.Errorf("can't create find one and delete result: %w", result.Err()) return fmt.Errorf("can't create find one and delete result: %w", result.Err())
} }
err = result.Decode(target) err = result.Decode(target)
if err != nil {
return
}
err = composed.OnDecode().Invoke(ctx, target)
if err != nil {
return
}
return return
} }

Loading…
Cancel
Save