diff --git a/db.go b/db.go index 8ab1c43be..9cd4e1c21 100644 --- a/db.go +++ b/db.go @@ -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 ( diff --git a/go_level_db.go b/go_level_db.go index a16c5d9e0..35c380ad8 100644 --- a/go_level_db.go +++ b/go_level_db.go @@ -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} diff --git a/mem_db.go b/mem_db.go index eb1e54b56..dcd86e6d5 100644 --- a/mem_db.go +++ b/mem_db.go @@ -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} }