From 8438c6ebc3a6ccd05e33f7bc1e9648645f3c0831 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Thu, 20 Feb 2014 10:55:04 -0800 Subject: Cursor.Get is now Cursor.Seek, and returns the first possible key. This makes range and prefix queries possible. Closes: #44 --- transaction.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'transaction.go') 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. -- cgit v1.2.3