Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NODE-3 (WIP) #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion datastore.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dsbbolt

import (
"fmt"
"os"

"bytes"
Expand Down Expand Up @@ -60,6 +61,9 @@ func (d *Datastore) Get(key datastore.Key) ([]byte, error) {
var data []byte
if err := d.db.View(func(tx *bbolt.Tx) error {
data = tx.Bucket(d.bucket).Get(key.Bytes())
if data == nil {
return datastore.ErrNotFound
}
return nil
}); err != nil {
return nil, err
Expand All @@ -86,6 +90,7 @@ func (d *Datastore) GetSize(key datastore.Key) (int, error) {
// https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/examples/fs.go#L96
// https://github.com/etcd-io/bbolt#prefix-scans
func (d *Datastore) Query(q query.Query) (query.Results, error) {
fmt.Printf("%+v\n", q)
var entries []query.Entry
if err := d.db.View(func(tx *bbolt.Tx) error {
cursor := tx.Bucket(d.bucket).Cursor()
Expand All @@ -97,17 +102,19 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
entry.Value = v
}
entries = append(entries, entry)
fmt.Printf("%+v\n", entry)
}
return nil
}
pref := []byte(q.Prefix)
for k, v := cursor.Seek(pref); k != nil && bytes.HasPrefix(k, pref); k, v = cursor.Next() {
var entry query.Entry
entry.Key = string(k)
entry.Key = fmt.Sprintf("%s%s", q.Prefix, string(k))
if !q.KeysOnly {
entry.Value = v
}
entries = append(entries, entry)
fmt.Printf("%+v\n", entry)
}
return nil
}); err != nil {
Expand Down