go/leveldb/batch.go

36 lines
492 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 {
return wb.db.db.Write(wb.db.writeOpts, wb.wb)
2014-04-18 10:50:29 +04:00
}
func (wb *WriteBatch) Rollback() {
wb.wb.Clear()
}
func (wb *WriteBatch) Close() {
if wb.wb == nil {
return
}
2014-04-18 10:50:29 +04:00
wb.wb.Close()
wb.wb = nil
}