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 {
|
2014-05-05 13:00:11 +04:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2014-05-05 13:00:11 +04:00
|
|
|
func (wb *WriteBatch) Close() {
|
|
|
|
if wb.wb == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-04-18 10:50:29 +04:00
|
|
|
wb.wb.Close()
|
|
|
|
wb.wb = nil
|
|
|
|
}
|