From 12532c96cb168ef3f03b913955572d4870dfbc9f Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 8 Mar 2023 16:11:10 +0700 Subject: [PATCH] FirstDup support (#99) --- mdbx/cursor.go | 2 +- mdbx/cursor_test.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mdbx/cursor.go b/mdbx/cursor.go index 02dcb7e..d3f4181 100644 --- a/mdbx/cursor.go +++ b/mdbx/cursor.go @@ -168,7 +168,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error if op == Set { key = setkey } else { - if op != LastDup { + if op != LastDup && op != FirstDup { key = castToBytes(c.txn.key) } } diff --git a/mdbx/cursor_test.go b/mdbx/cursor_test.go index efeb240..41adf6e 100644 --- a/mdbx/cursor_test.go +++ b/mdbx/cursor_test.go @@ -316,16 +316,29 @@ func TestLastDup(t *testing.T) { return err } i++ + _, v, err := c.Get(nil, nil, LastDup) if err != nil { return err } if i == 1 && string(v) != "value1.3" { - t.Fail() + panic(1) } if i == 2 && string(v) != "value3.3" { - t.Fail() + panic(1) + } + + _, v, err = c.Get(nil, nil, FirstDup) + if err != nil { + return err + } + if i == 1 && string(v) != "value1.1" { + panic(1) } + if i == 2 && string(v) != "value3.1" { + panic(1) + } + } return nil