diff options
author | Julio Capote <jcapote@gmail.com> | 2022-12-31 02:20:02 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-12-31 02:20:02 +0000 |
commit | c500a2be38afcbb5688537d97c7c3ee30a57dba4 (patch) | |
tree | 79cf1884ca7529299646b567b7705378bdf08fd3 /models/persister.go | |
parent | 74ffcfe6b2c80b7cf459798dc42bd278075ccb50 (diff) | |
download | communique-c500a2be38afcbb5688537d97c7c3ee30a57dba4.tar.gz |
parse and persist feeds from handlers
Diffstat (limited to 'models/persister.go')
-rw-r--r-- | models/persister.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/models/persister.go b/models/persister.go index 3729c81..a639fc7 100644 --- a/models/persister.go +++ b/models/persister.go @@ -10,6 +10,11 @@ type Persister struct { db *badger.DB } +type PersisterResult struct { + Value []byte + Key []byte +} + func NewPersister(log *zap.SugaredLogger, db *badger.DB) *Persister { aso := &Persister{log: log, db: db} return aso @@ -36,8 +41,8 @@ func (p *Persister) Count(model model) (int, error) { return count, err } -func (p *Persister) Collect(model model) ([]string, error) { - var result []string +func (p *Persister) Collect(model model) ([]PersisterResult, error) { + var result []PersisterResult err := p.db.View(func(txn *badger.Txn) error { opts := badger.DefaultIteratorOptions opts.PrefetchValues = false // TODO Maybe we want true here @@ -47,7 +52,8 @@ func (p *Persister) Collect(model model) ([]string, error) { for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() { item := it.Item() item.Value(func(v []byte) error { - result = append(result, string(v)) + pr := PersisterResult{Key: it.Item().Key(), Value: v} + result = append(result, pr) return nil }) } |