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.
()
| 138 | // Delete removes the current key/value under the cursor from the bucket. |
| 139 | // Delete fails if current key/value is a bucket or if the transaction is not writable. |
| 140 | func (c *Cursor) Delete() error { |
| 141 | if c.bucket.tx.db == nil { |
| 142 | return errors.ErrTxClosed |
| 143 | } else if !c.bucket.Writable() { |
| 144 | return errors.ErrTxNotWritable |
| 145 | } |
| 146 | |
| 147 | key, _, flags := c.keyValue() |
| 148 | // Return an error if current value is a bucket. |
| 149 | if (flags & common.BucketLeafFlag) != 0 { |
| 150 | return errors.ErrIncompatibleValue |
| 151 | } |
| 152 | c.node().del(key) |
| 153 | |
| 154 | return nil |
| 155 | } |
| 156 | |
| 157 | // seek moves the cursor to a given key and returns it. |
| 158 | // If the key does not exist then the next key is used. |