mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
ethdb: Add NewTableBatch; rename Table to table
This commit is contained in:
parent
9372be985b
commit
2928bfdfc4
1 changed files with 12 additions and 8 deletions
|
|
@ -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}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue