v0.0.136
This commit is contained in:
parent
6622c9003d
commit
d76d7b5cb9
@ -92,6 +92,17 @@ func (c *Coll[TData]) FindOneOptByID(ctx context.Context, id EntityID) (*TData,
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) FindOneAndUpdate(ctx context.Context, filterQuery bson.M, updateQuery bson.M) (TData, error) {
|
||||
var res TData
|
||||
|
||||
err := c.coll.FindOneAndUpdate(ctx, filterQuery, updateQuery, options.FindOneAndUpdate().SetReturnDocument(options.After)).Decode(&res)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) Find(ctx context.Context, filter bson.M, opts ...*options.FindOptions) ([]TData, error) {
|
||||
cursor, err := c.coll.Find(ctx, filter, opts...)
|
||||
if err != nil {
|
||||
@ -149,22 +160,6 @@ func (c *Coll[TData]) UpdateOneByID(ctx context.Context, id EntityID, updateQuer
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) UpdateOneAndReturn(ctx context.Context, id EntityID, updateQuery bson.M) (TData, error) {
|
||||
_, err := c.coll.UpdateOne(ctx, bson.M{"_id": id}, updateQuery)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
var res TData
|
||||
|
||||
err = c.coll.FindOne(ctx, bson.M{"_id": id}).Decode(&res)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) DeleteOne(ctx context.Context, id EntityID) error {
|
||||
_, err := c.coll.DeleteOne(ctx, bson.M{"_id": id})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user