ledisdb/store/goleveldb/batch.go

40 lines
633 B
Go
Raw Normal View History

2014-07-25 13:58:00 +04:00
package goleveldb
import (
2014-11-20 17:52:29 +03:00
"github.com/syndtr/goleveldb/leveldb"
2014-07-25 13:58:00 +04:00
)
type WriteBatch struct {
db *DB
wbatch *leveldb.Batch
}
func (w *WriteBatch) Put(key, value []byte) {
w.wbatch.Put(key, value)
}
func (w *WriteBatch) Delete(key []byte) {
w.wbatch.Delete(key)
}
func (w *WriteBatch) Commit() error {
return w.db.db.Write(w.wbatch, nil)
}
2014-10-09 09:05:55 +04:00
func (w *WriteBatch) SyncCommit() error {
return w.db.db.Write(w.wbatch, w.db.syncOpts)
}
2014-07-25 13:58:00 +04:00
func (w *WriteBatch) Rollback() error {
w.wbatch.Reset()
return nil
}
2014-11-10 10:31:36 +03:00
func (w *WriteBatch) Close() {
w.wbatch.Reset()
}
func (w *WriteBatch) Data() []byte {
return w.wbatch.Dump()
}