aboutsummaryrefslogtreecommitdiff
path: root/models/persister.go
diff options
context:
space:
mode:
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
+}