feat(db): implement extra dup methods (#20964)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Julian Meyer
2026-01-16 13:31:52 -08:00
committed by GitHub
parent 13707faf1a
commit f6dbf2d82d
3 changed files with 32 additions and 0 deletions

View File

@@ -62,9 +62,15 @@ pub trait DbCursorRO<T: Table> {
/// A read-only cursor over the dup table `T`.
pub trait DbDupCursorRO<T: DupSort> {
/// Positions the cursor at the prev KV pair of the table, returning it.
fn prev_dup(&mut self) -> PairResult<T>;
/// Positions the cursor at the next KV pair of the table, returning it.
fn next_dup(&mut self) -> PairResult<T>;
/// Positions the cursor at the last duplicate value of the current key.
fn last_dup(&mut self) -> ValueOnlyResult<T>;
/// Positions the cursor at the next KV pair of the table, skipping duplicates.
fn next_no_dup(&mut self) -> PairResult<T>;

View File

@@ -296,6 +296,18 @@ impl<T: DupSort> DbDupCursorRO<T> for CursorMock {
Ok(None)
}
/// Moves to the previous duplicate entry.
/// **Mock behavior**: Always returns `None`.
fn prev_dup(&mut self) -> PairResult<T> {
Ok(None)
}
/// Moves to the last duplicate entry.
/// **Mock behavior**: Always returns `None`.
fn last_dup(&mut self) -> ValueOnlyResult<T> {
Ok(None)
}
/// Moves to the next entry with a different key.
/// **Mock behavior**: Always returns `None`.
fn next_no_dup(&mut self) -> PairResult<T> {

View File

@@ -158,11 +158,25 @@ impl<K: TransactionKind, T: Table> DbCursorRO<T> for Cursor<K, T> {
}
impl<K: TransactionKind, T: DupSort> DbDupCursorRO<T> for Cursor<K, T> {
/// Returns the previous `(key, value)` pair of a DUPSORT table.
fn prev_dup(&mut self) -> PairResult<T> {
decode::<T>(self.inner.prev_dup())
}
/// Returns the next `(key, value)` pair of a DUPSORT table.
fn next_dup(&mut self) -> PairResult<T> {
decode::<T>(self.inner.next_dup())
}
/// Returns the last `value` of the current duplicate `key`.
fn last_dup(&mut self) -> ValueOnlyResult<T> {
self.inner
.last_dup()
.map_err(|e| DatabaseError::Read(e.into()))?
.map(decode_one::<T>)
.transpose()
}
/// Returns the next `(key, value)` pair skipping the duplicates.
fn next_no_dup(&mut self) -> PairResult<T> {
decode::<T>(self.inner.next_nodup())