Colleciton.Has convenience function

master v0.8.0
jdl 2023-12-16 21:06:36 +01:00
parent c2828592ac
commit 91b2ba30f6
1 changed files with 9 additions and 0 deletions

View File

@ -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 {