github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/ethdb/table_batch.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:38</date>
    10  //</624450090630647808>
    11  
    12  
    13  package ethdb
    14  
    15  type tableBatch struct {
    16  	batch  Batch
    17  	prefix string
    18  }
    19  
    20  //NewTableBatch返回一个批处理对象,该对象在所有键前面加上一个给定的字符串。
    21  func NewTableBatch(db Database, prefix string) Batch {
    22  	return &tableBatch{db.NewBatch(), prefix}
    23  }
    24  
    25  func (dt *table) NewBatch() Batch {
    26  	return &tableBatch{dt.db.NewBatch(), dt.prefix}
    27  }
    28  
    29  func (tb *tableBatch) Put(key, value []byte) error {
    30  	return tb.batch.Put(append([]byte(tb.prefix), key...), value)
    31  }
    32  
    33  func (tb *tableBatch) Delete(key []byte) error {
    34  	return tb.batch.Delete(append([]byte(tb.prefix), key...))
    35  }
    36  
    37  func (tb *tableBatch) Write() error {
    38  	return tb.batch.Write()
    39  }
    40  
    41  func (tb *tableBatch) ValueSize() int {
    42  	return tb.batch.ValueSize()
    43  }
    44  
    45  func (tb *tableBatch) Reset() {
    46  	tb.batch.Reset()
    47  }
    48