Colleciton.Has convenience function

This commit is contained in:
jdl 2023-12-16 21:06:36 +01:00
parent c2828592ac
commit 91b2ba30f6

View File

@ -159,6 +159,15 @@ func (c *Collection[T]) Get(tx *Snapshot, id uint64) *T {
return c.ByID.Get(tx, item) 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 { func (c *Collection[T]) Insert(tx *Snapshot, userItem *T) error {
if tx == nil { if tx == nil {
return c.db.Update(func(tx *Snapshot) error { return c.db.Update(func(tx *Snapshot) error {