feat(DbTx): add get_by_encoded_key (#13171)

This commit is contained in:
Hai | RISE
2024-12-06 20:58:17 +07:00
committed by GitHub
parent 634db30b6b
commit fdff4f18f2
6 changed files with 88 additions and 7 deletions

View File

@@ -283,8 +283,15 @@ impl<K: TransactionKind> DbTx for Tx<K> {
type DupCursor<T: DupSort> = Cursor<K, T>;
fn get<T: Table>(&self, key: T::Key) -> Result<Option<<T as Table>::Value>, DatabaseError> {
self.get_by_encoded_key::<T>(&key.encode())
}
fn get_by_encoded_key<T: Table>(
&self,
key: &<T::Key as Encode>::Encoded,
) -> Result<Option<T::Value>, DatabaseError> {
self.execute_with_operation_metric::<T, _>(Operation::Get, None, |tx| {
tx.get(self.get_dbi::<T>()?, key.encode().as_ref())
tx.get(self.get_dbi::<T>()?, key.as_ref())
.map_err(|e| DatabaseError::Read(e.into()))?
.map(decode_one::<T>)
.transpose()