1
0
mirror of https://github.com/siddontang/go.git synced 2025-04-29 13:49:17 +08:00

36 lines
492 B
Go
Raw Normal View History

2014-04-18 14:50:29 +08: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 14:50:29 +08:00
}
func (wb *WriteBatch) Rollback() {
wb.wb.Clear()
}
func (wb *WriteBatch) Close() {
if wb.wb == nil {
return
}
2014-04-18 14:50:29 +08:00
wb.wb.Close()
wb.wb = nil
}