diff options
-rw-r--r-- | src/dedo.go | 56 |
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. |