Bucket retrieves a nested bucket by name. Returns nil if the bucket does not exist. The bucket instance is only valid for the lifetime of the transaction.
(name []byte)
| 86 | // Returns nil if the bucket does not exist. |
| 87 | // The bucket instance is only valid for the lifetime of the transaction. |
| 88 | func (b *Bucket) Bucket(name []byte) *Bucket { |
| 89 | if b.buckets != nil { |
| 90 | if child := b.buckets[string(name)]; child != nil { |
| 91 | return child |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Move cursor to key. |
| 96 | c := b.Cursor() |
| 97 | k, v, flags := c.seek(name) |
| 98 | |
| 99 | // Return nil if the key doesn't exist or it is not a bucket. |
| 100 | if !bytes.Equal(name, k) || (flags&common.BucketLeafFlag) == 0 { |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // Otherwise create a bucket and cache it. |
| 105 | var child = b.openBucket(v) |
| 106 | if b.buckets != nil { |
| 107 | b.buckets[string(name)] = child |
| 108 | } |
| 109 | |
| 110 | return child |
| 111 | } |
| 112 | |
| 113 | // Helper method that re-interprets a sub-bucket value |
| 114 | // from a parent into a Bucket |
no test coverage detected