Browse Source

Exposed the LevelDB iterator in the DB struct.

pull/1842/head
Paul W. Homer 8 years ago
parent
commit
bb8104b624
3 changed files with 27 additions and 0 deletions
  1. +8
    -0
      db.go
  2. +9
    -0
      go_level_db.go
  3. +10
    -0
      mem_db.go

+ 8
- 0
db.go View File

@ -12,6 +12,8 @@ type DB interface {
NewBatch() Batch
// For debugging
Iterator() Iterator
Next(Iterator) (key []byte, value []byte)
Print()
}
@ -21,6 +23,12 @@ type Batch interface {
Write()
}
type Iterator interface {
Next() bool
Key() []byte
Value() []byte
}
//-----------------------------------------------------------------------------
const (


+ 9
- 0
go_level_db.go View File

@ -90,6 +90,15 @@ func (db *GoLevelDB) Print() {
}
}
func (db *GoLevelDB) Iterator() Iterator {
return db.db.NewIterator(nil, nil)
}
func (db *GoLevelDB) Next(iter Iterator) ([]byte, []byte) {
iter.Next()
return iter.Key(), iter.Value()
}
func (db *GoLevelDB) NewBatch() Batch {
batch := new(leveldb.Batch)
return &goLevelDBBatch{db, batch}


+ 10
- 0
mem_db.go View File

@ -65,6 +65,16 @@ func (db *MemDB) Print() {
}
}
// TODO: needs to be wired to range db.db
func (db *MemDB) Iterator() Iterator {
return nil
}
// TODO: needs to be wired to range db.db
func (db *MemDB) Next(iter Iterator) (key []byte, value []byte) {
return nil, nil
}
func (db *MemDB) NewBatch() Batch {
return &memDBBatch{db, nil}
}


Loading…
Cancel
Save