aboutsummaryrefslogtreecommitdiff
path: root/src/dedo.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-02-07 18:08:44 -0300
committerEuAndreh <eu@euandre.org>2025-02-07 18:08:44 -0300
commita303cbaf3d85bdcbd6851a09ac0b39675cb7914f (patch)
tree22b511d710ac3d743739279078abe065c62d36e3 /src/dedo.go
parentsrc/dedo.go: Rename IDedo -> DedoI, ITx -> TxI (diff)
downloaddedo-a303cbaf3d85bdcbd6851a09ac0b39675cb7914f.tar.gz
dedo-a303cbaf3d85bdcbd6851a09ac0b39675cb7914f.tar.xz
src/dedo.go: Rename TxI -> TransactionI
Diffstat (limited to 'src/dedo.go')
-rw-r--r--src/dedo.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/dedo.go b/src/dedo.go
index d8ce80e..1f76083 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -115,7 +115,7 @@ type InMemory struct{
*pds.Map[[]byte, *Bucket]
}
-type TxI interface{
+type TransactionI interface{
CreateBucket ([]byte) (*Bucket, error)
CreateBucketIfNotExists([]byte) (*Bucket, error)
Bucket([]byte) *Bucket
@@ -123,6 +123,7 @@ type TxI interface{
Cursor() *Cursor
ForEach(func([]byte, *Bucket) error) error
+ Check() <-chan error
OnCommit(func())
@@ -132,6 +133,7 @@ type TxI interface{
type SnapshotI interface{
Bucket([]byte) *Bucket
+ Cursor() *Cursor
WriteTo(io.Writer) (int64, error)
ForEach(func([]byte, *Bucket) error) error
@@ -140,8 +142,8 @@ type SnapshotI interface{
type DedoI interface{
Close() error
- View (func(tx SnapshotI) error) error
- Update(func(tx TxI) error) error
+ View (func(tx SnapshotI) error) error
+ Update(func(tx TransactionI) error) error
Path() string
}
@@ -201,7 +203,7 @@ type OpenOptionsT struct{
}
type call struct {
- fn func(TxI) error
+ fn func(TransactionI) error
err chan<- error
}
@@ -1734,7 +1736,7 @@ func (m *InMemory) Path() string {
return ""
}
-func (m *InMemory) Update(fn func(TxI) error) error {
+func (m *InMemory) Update(fn func(TransactionI) error) error {
tx := &inMemoryTx{
db: m,
commitHandlers: []func(){},
@@ -2087,7 +2089,7 @@ func (db *DB) removeTx(tx *Tx) {
///
/// Attempting to manually commit or rollback within the function will cause a
/// panic.
-func (db *DB) Update(fn func(TxI) error) error {
+func (db *DB) Update(fn func(TransactionI) error) error {
t, err := db.begin(true)
if err != nil {
return err
@@ -2164,7 +2166,7 @@ func needsNewBatch(batch *batch, max int) bool {
/// DB.MaxBatchDelay, respectively.
///
/// DB.Batch() is only useful when there are multiple goroutines calling it.
-func (db *DB) Batch(fn func(TxI) error) error {
+func (db *DB) Batch(fn func(TransactionI) error) error {
errCh := make(chan error, 1)
db.batchMu.Lock()
@@ -2213,7 +2215,7 @@ func (b *batch) run() {
retry:
for len(b.calls) > 0 {
failIdx := -1
- err := b.db.Update(func(tx TxI) error {
+ err := b.db.Update(func(tx TransactionI) error {
for i, c := range b.calls {
err := safelyCall(c.fn, tx)
if err != nil {
@@ -2254,7 +2256,7 @@ func (p panicked) Error() string {
return fmt.Sprintf("panic: %v", p.reason)
}
-func safelyCall(fn func(TxI) error, tx TxI) (err error) {
+func safelyCall(fn func(TransactionI) error, tx TransactionI) (err error) {
defer func() {
p := recover()
if p != nil {
@@ -4001,7 +4003,7 @@ func getExec(args argsT, db DedoI, r io.Reader, w io.Writer) error {
}
func setExec(args argsT, db DedoI, r io.Reader, w io.Writer) error {
- return db.Update(func(tx TxI) error {
+ return db.Update(func(tx TransactionI) error {
bucket, err := tx.CreateBucketIfNotExists(args.bucket)
if err != nil {
return err
@@ -4012,7 +4014,7 @@ func setExec(args argsT, db DedoI, r io.Reader, w io.Writer) error {
}
func rmExec(args argsT, db DedoI, r io.Reader, w io.Writer) error {
- return db.Update(func(tx TxI) error {
+ return db.Update(func(tx TransactionI) error {
bucket := tx.Bucket(args.bucket)
if bucket == nil {
return ErrBucketNotFound