diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-20 13:24:55 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-20 13:24:55 -0700 |
commit | b9ec84552bf97db7d55180af513dce26f4539b22 (patch) | |
tree | 0b0c2119fbcf0296631f996c68e2e86b86df60e5 /transaction.go | |
parent | Merge pull request #43 from benbjohnson/cursor-godoc-fix (diff) | |
parent | Cursor.Get is now Cursor.Seek, and returns the first possible key. (diff) | |
download | dedo-b9ec84552bf97db7d55180af513dce26f4539b22.tar.gz dedo-b9ec84552bf97db7d55180af513dce26f4539b22.tar.xz |
Merge pull request #45 from benbjohnson/seek
Cursor.Get is now Cursor.Seek, and returns the first possible key.
Diffstat (limited to 'transaction.go')
-rw-r--r-- | transaction.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/transaction.go b/transaction.go index 54aae8c..3951cd8 100644 --- a/transaction.go +++ b/transaction.go @@ -1,5 +1,9 @@ package bolt +import ( + "bytes" +) + // Transaction represents a read-only transaction on the database. // It can be used for retrieving values for keys as well as creating cursors for // iterating over the data. @@ -90,7 +94,12 @@ func (t *Transaction) Get(name string, key []byte) (value []byte, err error) { if err != nil { return nil, err } - return c.Get(key), nil + k, v := c.Seek(key) + // If our target node isn't the same key as what's passed in then return nil. + if !bytes.Equal(key, k) { + return nil, nil + } + return v, nil } // ForEach executes a function for each key/value pair in a bucket. |