ethdb: Add NewTableBatch; rename Table to table

This commit is contained in:
Nick Johnson 2017-01-11 09:32:41 +00:00
parent 9372be985b
commit 2928bfdfc4

View file

@ -306,31 +306,31 @@ func (b *ldbBatch) Write() error {
return b.db.Write(b.b, nil) return b.db.Write(b.b, nil)
} }
type Table struct { type table struct {
db Database db Database
prefix string prefix string
} }
func NewTable(db Database, prefix string) *Table { func NewTable(db Database, prefix string) *table {
return &Table{ return &table{
db: db, db: db,
prefix: prefix, prefix: prefix,
} }
} }
func (dt *Table) Put(key []byte, value []byte) error { func (dt *table) Put(key []byte, value []byte) error {
return dt.db.Put(append([]byte(dt.prefix), key...), value) return dt.db.Put(append([]byte(dt.prefix), key...), value)
} }
func (dt *Table) Get(key []byte) ([]byte, error) { func (dt *table) Get(key []byte) ([]byte, error) {
return dt.db.Get(append([]byte(dt.prefix), key...)) return dt.db.Get(append([]byte(dt.prefix), key...))
} }
func (dt *Table) Delete(key []byte) error { func (dt *table) Delete(key []byte) error {
return dt.db.Delete(append([]byte(dt.prefix), key...)) return dt.db.Delete(append([]byte(dt.prefix), key...))
} }
func (dt *Table) Close() { func (dt *table) Close() {
// Do nothing; don't close the underlying DB. // Do nothing; don't close the underlying DB.
} }
@ -339,7 +339,11 @@ type tableBatch struct {
prefix string prefix string
} }
func (dt *Table) NewBatch() Batch { func NewTableBatch(db Database, prefix string) *tableBatch {
return &tableBatch{db.NewBatch(), prefix}
}
func (dt *table) NewBatch() Batch {
return &tableBatch{dt.db.NewBatch(), dt.prefix} return &tableBatch{dt.db.NewBatch(), dt.prefix}
} }