ledisdb/store/mdb/batch.go

33 lines
478 B
Go
Raw Normal View History

2014-07-25 13:58:00 +04:00
package mdb
type Write struct {
Key []byte
Value []byte
}
type WriteBatch struct {
2014-07-25 15:41:04 +04:00
db *MDB
2014-07-25 13:58:00 +04:00
wb []Write
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Close() error {
2014-07-25 13:58:00 +04:00
return nil
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Put(key, value []byte) {
2014-07-25 13:58:00 +04:00
w.wb = append(w.wb, Write{key, value})
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Delete(key []byte) {
2014-07-25 13:58:00 +04:00
w.wb = append(w.wb, Write{key, nil})
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Commit() error {
2014-07-25 13:58:00 +04:00
return w.db.BatchPut(w.wb)
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Rollback() error {
2014-07-25 13:58:00 +04:00
w.wb = []Write{}
return nil
}