From 91b2ba30f6dd0704a362f44ba886027fb086002d Mon Sep 17 00:00:00 2001 From: jdl Date: Sat, 16 Dec 2023 21:06:36 +0100 Subject: [PATCH] Colleciton.Has convenience function --- mdb/collection.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mdb/collection.go b/mdb/collection.go index 57970a8..27d06c4 100644 --- a/mdb/collection.go +++ b/mdb/collection.go @@ -159,6 +159,15 @@ func (c *Collection[T]) Get(tx *Snapshot, id uint64) *T { return c.ByID.Get(tx, item) } +func (c *Collection[T]) Has(tx *Snapshot, id uint64) bool { + if tx == nil { + tx = c.db.Snapshot() + } + item := new(T) + c.setID(item, id) + return c.ByID.Has(tx, item) +} + func (c *Collection[T]) Insert(tx *Snapshot, userItem *T) error { if tx == nil { return c.db.Update(func(tx *Snapshot) error {