diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-06-11 21:46:19 +0000 |
---|---|---|
committer | Martin Kobetic <mkobetic@gmail.com> | 2014-06-11 21:46:19 +0000 |
commit | a00a88baef376804b9980a4854250d08da2908e5 (patch) | |
tree | d6cdfd42dd4dbed3d7ff15803a38343ddc42be9d /cursor.go | |
parent | Merge pull request #189 from benbjohnson/increase-max-nodes-per-page (diff) | |
download | dedo-a00a88baef376804b9980a4854250d08da2908e5.tar.gz dedo-a00a88baef376804b9980a4854250d08da2908e5.tar.xz |
add Cursor.Delete()
Diffstat (limited to 'cursor.go')
-rw-r--r-- | cursor.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -111,6 +111,25 @@ func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) { return k, v } +// Delete removes the current key/value under the cursor from the bucket. +// Delete fails if current key/value is a bucket or if the transaction is not writable. +func (c *Cursor) Delete() error { + if c.bucket.tx.db == nil { + return ErrTxClosed + } else if !c.bucket.Writable() { + return ErrTxNotWritable + } + + key, _, flags := c.keyValue() + // Return an error if current value is a bucket. + if (flags & bucketLeafFlag) != 0 { + return ErrIncompatibleValue + } + c.node().del(key) + + return nil +} + // seek moves the cursor to a given key and returns it. // If the key does not exist then the next key is used. func (c *Cursor) seek(seek []byte) (key []byte, value []byte, flags uint32) { |