mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-07-03 17:22:33 +00:00
Add context query support to a single deleting
This commit is contained in:
@@ -19,6 +19,7 @@ func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err er
|
|||||||
opts := &options.FindOneAndDeleteOptions{}
|
opts := &options.FindOneAndDeleteOptions{}
|
||||||
composed := query.Compose(filters...)
|
composed := query.Compose(filters...)
|
||||||
protected := base.GetProtection(target)
|
protected := base.GetProtection(target)
|
||||||
|
ctx := query.WithContext(d.Context(), composed)
|
||||||
|
|
||||||
opts.Sort = composed.Sorter()
|
opts.Sort = composed.Sorter()
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err er
|
|||||||
protected.V = time.Now().Unix()
|
protected.V = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
result := collection.FindOneAndDelete(d.Context(), 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())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user