aboutsummaryrefslogtreecommitdiff
path: root/src/dedo.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-02-10 14:31:12 -0300
committerEuAndreh <eu@euandre.org>2025-02-10 14:31:12 -0300
commit8559308b63d962ee8fe63d2f91f413ac750ae1a5 (patch)
tree649fdd32312c6a06bf50b679d3d34da2bdc2d08e /src/dedo.go
parentsrc/dedo.go: Move implementation of Cursor public methods into private functions (diff)
downloaddedo-8559308b63d962ee8fe63d2f91f413ac750ae1a5.tar.gz
dedo-8559308b63d962ee8fe63d2f91f413ac750ae1a5.tar.xz
src/dedo.go: Move implementation of Tx public methods into private functions
Diffstat (limited to 'src/dedo.go')
-rw-r--r--src/dedo.go56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/dedo.go b/src/dedo.go
index f009279..2afcc01 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -3526,58 +3526,86 @@ func (tx *transactionT) init(db *databaseT) {
}
/// transactionT.ID() returns the transaction id.
-func (tx *transactionT) ID() int {
+func txID(tx *transactionT) int {
return int(tx.meta.txid)
}
+func (tx *transactionT) ID() int {
+ return txID(tx)
+}
+
/// transactionT.Size() returns current database size in bytes as seen by this
/// transaction.
-func (tx *transactionT) Size() int64 {
+func txSize(tx *transactionT) int64 {
return int64(tx.meta.pgid) * int64(tx.db.pageSize)
}
+func (tx *transactionT) Size() int64 {
+ return txSize(tx)
+}
+
/// transactionT.Cursor() creates a cursor associated with the root bucket. All items in
/// the cursor will return a nil value because all root bucket keys point to
/// buckets. The cursor is only valid as long as the transaction is open. Do
/// not use a cursor after the transaction is closed.
-func (tx *transactionT) Cursor() *cursorT {
+func txCursor(tx *transactionT) *cursorT {
return tx.root.Cursor()
}
+func (tx *transactionT) Cursor() *cursorT {
+ return txCursor(tx)
+}
+
/// transactionT.Bucket() retrieves a bucket by name. Returns nil if the bucket does not
/// exist. The bucket instance is only valid for the lifetime of the
/// transaction.
-func (tx *transactionT) Bucket(name []byte) *bucketT {
+func txBucket(tx *transactionT, name []byte) *bucketT {
return tx.root.Bucket(name)
}
+func (tx *transactionT) Bucket(name []byte) *bucketT {
+ return txBucket(tx, name)
+}
+
/// transactionT.CreateBucket() creates a new bucket. Returns an error if the bucket
/// already exists, if the bucket name is blank, or if the bucket name is too
/// long. The bucket instance is only valid for the lifetime of the
/// transaction.
-func (tx *transactionT) CreateBucket(name []byte) (*bucketT, error) {
+func txCreateBucket(tx *transactionT, name []byte) (*bucketT, error) {
return tx.root.CreateBucket(name)
}
+func (tx *transactionT) CreateBucket(name []byte) (*bucketT, error) {
+ return txCreateBucket(tx, name)
+}
+
/// transactionT.CreateBucketIfNotExists() creates a new bucket if it doesn't already
/// exist. Returns an error if the bucket name is blank, or if the bucket name
/// is too long. The bucket instance is only valid for the lifetime of the
/// transaction.
-func (tx *transactionT) CreateBucketIfNotExists(name []byte) (*bucketT, error) {
+func txCreateBucketIfNotExists(tx *transactionT, name []byte) (*bucketT, error) {
return tx.root.CreateBucketIfNotExists(name)
}
+func (tx *transactionT) CreateBucketIfNotExists(name []byte) (*bucketT, error) {
+ return txCreateBucketIfNotExists(tx, name)
+}
+
/// transactionT.DeleteBucket() deletes a bucket. Returns an error if the bucket cannot
/// be found or if the key represents a non-bucket value.
-func (tx *transactionT) DeleteBucket(name []byte) error {
+func txDeleteBucket(tx *transactionT, name []byte) error {
return tx.root.DeleteBucket(name)
}
+func (tx *transactionT) DeleteBucket(name []byte) error {
+ return txDeleteBucket(tx, name)
+}
+
/// transactionT.ForEach() executes a function for each bucket in the root. If the
/// provided function returns an error then the iteration is stopped and the
/// error is returned to the caller.
-func (tx *transactionT) ForEach(fn func(name []byte, b *bucketT) error) error {
- return tx.root.ForEach(func(k, v []byte) error {
+func txForEach(tx *transactionT, fn func([]byte, *bucketT) error) error {
+ return tx.root.ForEach(func(k []byte, v []byte) error {
err := fn(k, tx.root.Bucket(k))
if err != nil {
return err
@@ -3586,12 +3614,20 @@ func (tx *transactionT) ForEach(fn func(name []byte, b *bucketT) error) error {
})
}
+func (tx *transactionT) ForEach(fn func([]byte, *bucketT) error) error {
+ return txForEach(tx, fn)
+}
+
/// transactionT.OnCommit() adds a handler function to be executed after the transaction
/// successfully commits.
-func (tx *transactionT) OnCommit(fn func()) {
+func txOnCommit(tx *transactionT, fn func()) {
tx.commitHandlers = append(tx.commitHandlers, fn)
}
+func (tx *transactionT) OnCommit(fn func()) {
+ txOnCommit(tx, fn)
+}
+
/// transactionT.commit() writes all changes to disk and updates the meta page. Returns
/// an error if a disk write error occurs, or if transactionT.commiti() is called on a
/// read-only transaction.