diff --git a/leveldb/iterator.go b/leveldb/iterator.go index d3e19bd..599b04e 100644 --- a/leveldb/iterator.go +++ b/leveldb/iterator.go @@ -98,8 +98,12 @@ func newIterator(db *DB, opts *levigo.ReadOptions, r *Range, offset int, limit i } for i := 0; i < offset; i++ { - if it.Valid() { - it.Next() + if it.it.Valid() { + if it.direction == IteratorForward { + it.it.Next() + } else { + it.it.Prev() + } } } diff --git a/leveldb/leveldb_test.go b/leveldb/leveldb_test.go index 4f478f3..9f68781 100644 --- a/leveldb/leveldb_test.go +++ b/leveldb/leveldb_test.go @@ -152,7 +152,7 @@ func TestIterator(t *testing.T) { } it = db.Iterator(k(1), k(5), RangeClose, 1, 3) - if err := checkIterator(it, 2, 3); err != nil { + if err := checkIterator(it, 2, 3, 4); err != nil { t.Fatal(err) } @@ -177,7 +177,7 @@ func TestIterator(t *testing.T) { } it = db.RevIterator(k(1), k(5), RangeClose, 1, 3) - if err := checkIterator(it, 4, 3); err != nil { + if err := checkIterator(it, 4, 3, 2); err != nil { t.Fatal(err) }