aboutsummaryrefslogtreecommitdiff
path: root/models/persister.go
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-01 21:48:37 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-01 21:48:37 +0000
commitb3f22c698739bdd57dab77af45a0b8a43da72ca4 (patch)
tree07d4bca01bc49d71d2ddceaa89f51487f0768047 /models/persister.go
parent71495ac61587e3380f413b4d34669a68b5cd8068 (diff)
downloadcommunique-b3f22c698739bdd57dab77af45a0b8a43da72ca4.tar.gz
working ids and activity lookups
Diffstat (limited to '')
-rw-r--r--models/persister.go26
1 files changed, 26 insertions, 0 deletions
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
+}