From b3f22c698739bdd57dab77af45a0b8a43da72ca4 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sun, 1 Jan 2023 16:48:37 -0500 Subject: working ids and activity lookups --- models/persister.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'models/persister.go') diff --git a/models/persister.go b/models/persister.go index 669480e..69e79f4 100644 --- a/models/persister.go +++ b/models/persister.go @@ -60,3 +60,29 @@ func (p *Persister) Collect(model model) ([][]byte, error) { }) return result, err } + +func (p *Persister) Find(model model) ([]byte, error) { + var result []byte + var item *badger.Item + err := p.db.View(func(txn *badger.Txn) error { + var getErr error + item, getErr = txn.Get([]byte(model.Key())) + if getErr != nil { + return getErr + } + return nil + }) + if err != nil { + return nil, err + } + err = item.Value(func(v []byte) error { + result = v + return nil + }) + + if err != nil { + return nil, err + } + + return result, nil +} -- cgit v1.2.3