This commit is contained in:
Mike Schwörer 2023-06-08 16:24:15 +02:00
parent dc2d8a9103
commit 93c4cf31a8
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 16 additions and 7 deletions

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.152"
const GoextVersion = "0.0.153"
const GoextVersionTimestamp = "2023-06-08T16:17:01+0200"
const GoextVersionTimestamp = "2023-06-08T16:24:15+0200"

View File

@ -6,7 +6,7 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)
func (c *Coll[TData]) DeleteOne(ctx context.Context, id EntityID) error {
func (c *Coll[TData]) DeleteOnebyID(ctx context.Context, id EntityID) error {
_, err := c.coll.DeleteOne(ctx, bson.M{"_id": id})
if err != nil {
return err
@ -15,6 +15,15 @@ func (c *Coll[TData]) DeleteOne(ctx context.Context, id EntityID) error {
return nil
}
func (c *Coll[TData]) DeleteOne(ctx context.Context, filterQuery bson.M) error {
_, err := c.coll.DeleteOne(ctx, filterQuery)
if err != nil {
return err
}
return nil
}
func (c *Coll[TData]) DeleteMany(ctx context.Context, filterQuery bson.M) (*mongo.DeleteResult, error) {
res, err := c.coll.DeleteMany(ctx, filterQuery)
if err != nil {

View File

@ -45,8 +45,8 @@ func (c *Coll[TData]) UpdateMany(ctx context.Context, filterQuery bson.M, update
return res, nil
}
func (c *Coll[TData]) ReplaceOne(ctx context.Context, id EntityID, value TData) error {
_, err := c.coll.UpdateOne(ctx, bson.M{"_id": id}, bson.M{"$set": value})
func (c *Coll[TData]) ReplaceOne(ctx context.Context, filterQuery bson.M, value TData) error {
_, err := c.coll.UpdateOne(ctx, filterQuery, bson.M{"$set": value})
if err != nil {
return err
}
@ -54,10 +54,10 @@ func (c *Coll[TData]) ReplaceOne(ctx context.Context, id EntityID, value TData)
return nil
}
func (c *Coll[TData]) FindOneAndReplace(ctx context.Context, id EntityID, value TData) (TData, error) {
func (c *Coll[TData]) FindOneAndReplace(ctx context.Context, filterQuery bson.M, value TData) (TData, error) {
var res TData
err := c.coll.FindOneAndUpdate(ctx, bson.M{"_id": id}, bson.M{"$set": value}, options.FindOneAndUpdate().SetReturnDocument(options.After)).Decode(&res)
err := c.coll.FindOneAndUpdate(ctx, filterQuery, bson.M{"$set": value}, options.FindOneAndUpdate().SetReturnDocument(options.After)).Decode(&res)
if err != nil {
return *new(TData), err
}