mirror of https://github.com/siddontang/go.git
35 lines
496 B
Go
35 lines
496 B
Go
|
package leveldb
|
||
|
|
||
|
import (
|
||
|
"github.com/jmhodges/levigo"
|
||
|
)
|
||
|
|
||
|
type WriteBatch struct {
|
||
|
db *DB
|
||
|
wb *levigo.WriteBatch
|
||
|
}
|
||
|
|
||
|
func (wb *WriteBatch) Put(key, value []byte) {
|
||
|
wb.wb.Put(key, value)
|
||
|
}
|
||
|
|
||
|
func (wb *WriteBatch) Delete(key []byte) {
|
||
|
wb.wb.Delete(key)
|
||
|
}
|
||
|
|
||
|
func (wb *WriteBatch) Commit() error {
|
||
|
err := wb.db.db.Write(wb.db.writeOpts, wb.wb)
|
||
|
wb.close()
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (wb *WriteBatch) Rollback() {
|
||
|
wb.wb.Clear()
|
||
|
wb.close()
|
||
|
}
|
||
|
|
||
|
func (wb *WriteBatch) close() {
|
||
|
wb.wb.Close()
|
||
|
wb.wb = nil
|
||
|
}
|