aboutsummaryrefslogtreecommitdiff
path: root/bucket.go
diff options
context:
space:
mode:
Diffstat (limited to 'bucket.go')
-rw-r--r--bucket.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/bucket.go b/bucket.go
index c72ddc8..e2bf60c 100644
--- a/bucket.go
+++ b/bucket.go
@@ -55,7 +55,9 @@ func (b *Bucket) Get(key []byte) []byte {
// If the key exist then its previous value will be overwritten.
// Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.
func (b *Bucket) Put(key []byte, value []byte) error {
- if !b.Writable() {
+ if b.tx.db == nil {
+ return ErrTxClosed
+ } else if !b.Writable() {
return ErrBucketNotWritable
}
@@ -82,7 +84,9 @@ func (b *Bucket) Put(key []byte, value []byte) error {
// If the key does not exist then nothing is done and a nil error is returned.
// Returns an error if the bucket was created from a read-only transaction.
func (b *Bucket) Delete(key []byte) error {
- if !b.Writable() {
+ if b.tx.db == nil {
+ return ErrTxClosed
+ } else if !b.Writable() {
return ErrBucketNotWritable
}
@@ -98,7 +102,9 @@ func (b *Bucket) Delete(key []byte) error {
// NextSequence returns an autoincrementing integer for the bucket.
func (b *Bucket) NextSequence() (int, error) {
- if !b.Writable() {
+ if b.tx.db == nil {
+ return 0, ErrTxClosed
+ } else if !b.Writable() {
return 0, ErrBucketNotWritable
}
@@ -118,6 +124,9 @@ func (b *Bucket) NextSequence() (int, error) {
// If the provided function returns an error then the iteration is stopped and
// the error is returned to the caller.
func (b *Bucket) ForEach(fn func(k, v []byte) error) error {
+ if b.tx.db == nil {
+ return ErrTxClosed
+ }
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
if err := fn(k, v); err != nil {