github.com/codingfuture/orig-energi3@v0.8.4/ethdb/table_batch.go (about) 1 // Copyright 2018 The Energi Core Authors 2 // Copyright 2018 The go-ethereum Authors 3 // This file is part of the Energi Core library. 4 // 5 // The Energi Core library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The Energi Core library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>. 17 18 package ethdb 19 20 type tableBatch struct { 21 batch Batch 22 prefix string 23 } 24 25 // NewTableBatch returns a Batch object which prefixes all keys with a given string. 26 func NewTableBatch(db Database, prefix string) Batch { 27 return &tableBatch{db.NewBatch(), prefix} 28 } 29 30 func (dt *table) NewBatch() Batch { 31 return &tableBatch{dt.db.NewBatch(), dt.prefix} 32 } 33 34 func (tb *tableBatch) Put(key, value []byte) error { 35 return tb.batch.Put(append([]byte(tb.prefix), key...), value) 36 } 37 38 func (tb *tableBatch) Delete(key []byte) error { 39 return tb.batch.Delete(append([]byte(tb.prefix), key...)) 40 } 41 42 func (tb *tableBatch) Write() error { 43 return tb.batch.Write() 44 } 45 46 func (tb *tableBatch) ValueSize() int { 47 return tb.batch.ValueSize() 48 } 49 50 func (tb *tableBatch) Reset() { 51 tb.batch.Reset() 52 }