2023-06-06 21:33:49 +02:00
|
|
|
package wmo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
2023-07-24 09:16:37 +02:00
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
2023-06-06 21:33:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Coll[TData]) InsertOne(ctx context.Context, valueIn TData) (TData, error) {
|
|
|
|
insRes, err := c.coll.InsertOne(ctx, valueIn)
|
|
|
|
if err != nil {
|
|
|
|
return *new(TData), err
|
|
|
|
}
|
|
|
|
|
2023-06-10 16:22:14 +02:00
|
|
|
mongoRes := c.coll.FindOne(ctx, bson.M{"_id": insRes.InsertedID})
|
2023-06-06 21:33:49 +02:00
|
|
|
|
2023-06-10 16:22:14 +02:00
|
|
|
return c.decodeSingle(ctx, mongoRes)
|
2023-06-06 21:33:49 +02:00
|
|
|
}
|
2023-07-24 09:13:19 +02:00
|
|
|
|
2023-07-24 09:16:37 +02:00
|
|
|
func (c *Coll[TData]) InsertMany(ctx context.Context, valueIn []TData) (*mongo.InsertManyResult, error) {
|
|
|
|
return c.coll.InsertMany(ctx, langext.ArrayToInterface(valueIn))
|
2023-07-24 09:13:19 +02:00
|
|
|
}
|