go/leveldb/batch.go

35 lines
496 B
Go
Raw Normal View History

2014-04-18 10:50:29 +04:00
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
}