mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-13 11:35:52 +01:00
44 lines
805 B
Go
44 lines
805 B
Go
package pebbledb
|
|
|
|
import (
|
|
"github.com/btcsuite/btcd/database/engine"
|
|
"github.com/cockroachdb/pebble"
|
|
)
|
|
|
|
func NewTransaction(batch *pebble.Batch) engine.Transaction {
|
|
return &Transaction{Batch: batch}
|
|
}
|
|
|
|
type Transaction struct {
|
|
*pebble.Batch
|
|
released bool
|
|
}
|
|
|
|
func (t *Transaction) Put(key, value []byte) error {
|
|
if t.released {
|
|
return ErrTxClosed
|
|
}
|
|
return t.Batch.Set(key, value, pebble.NoSync)
|
|
}
|
|
|
|
func (t *Transaction) Delete(key []byte) error {
|
|
if t.released {
|
|
return ErrTxClosed
|
|
}
|
|
|
|
return t.Batch.Delete(key, pebble.NoSync)
|
|
}
|
|
|
|
func (t *Transaction) Discard() {
|
|
if !t.released {
|
|
t.released = true
|
|
t.Batch.Close()
|
|
}
|
|
}
|
|
|
|
func (t *Transaction) Commit() error {
|
|
if t.released {
|
|
return ErrTxClosed
|
|
}
|
|
return t.Batch.Commit(pebble.Sync)
|
|
}
|