From e909d656d991acd6acb8a75f365895e24798f0be Mon Sep 17 00:00:00 2001 From: risqy Date: Mon, 24 Jul 2023 09:13:19 +0200 Subject: [PATCH] v0.0.186 convert array to interface arr --- goextVersion.go | 4 ++-- langext/array.go | 8 ++++++++ wmo/queryInsert.go | 11 +++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index 05a824b..56af569 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.185" +const GoextVersion = "0.0.186" -const GoextVersionTimestamp = "2023-07-19T19:34:39+0200" +const GoextVersionTimestamp = "2023-07-24T09:13:19+0200" diff --git a/langext/array.go b/langext/array.go index d71536c..7b9b460 100644 --- a/langext/array.go +++ b/langext/array.go @@ -459,3 +459,11 @@ func ArrExcept[T comparable](arr []T, needles ...T) []T { } return r } + +func ArrayToInterface[T any](t []T) []interface{} { + res := make([]interface{}, 0, len(t)) + for i, _ := range t { + res = append(res, t[i]) + } + return res +} diff --git a/wmo/queryInsert.go b/wmo/queryInsert.go index 8ea13ca..ce7deff 100644 --- a/wmo/queryInsert.go +++ b/wmo/queryInsert.go @@ -15,3 +15,14 @@ func (c *Coll[TData]) InsertOne(ctx context.Context, valueIn TData) (TData, erro return c.decodeSingle(ctx, mongoRes) } + +func (c *Coll[TData]) InsertMany(ctx context.Context, valueIn []TData) (TData, error) { + insRes, err := c.coll.InsertMany(ctx, langext.TovalueIn) + if err != nil { + return *new(TData), err + } + + mongoRes := c.coll.FindOne(ctx, bson.M{"_id": insRes.InsertedID}) + + return c.decodeSingle(ctx, mongoRes) +}