diff options
Diffstat (limited to 'models/persister.go')
-rw-r--r-- | models/persister.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/models/persister.go b/models/persister.go index 71cddc8..3729c81 100644 --- a/models/persister.go +++ b/models/persister.go @@ -35,3 +35,23 @@ func (p *Persister) Count(model model) (int, error) { }) return count, err } + +func (p *Persister) Collect(model model) ([]string, error) { + var result []string + err := p.db.View(func(txn *badger.Txn) error { + opts := badger.DefaultIteratorOptions + opts.PrefetchValues = false // TODO Maybe we want true here + it := txn.NewIterator(opts) + defer it.Close() + prefix := []byte(model.Keybase()) + for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() { + item := it.Item() + item.Value(func(v []byte) error { + result = append(result, string(v)) + return nil + }) + } + return nil + }) + return result, err +} |