mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Discussion draft: change DB Writer to take value references (#13672)
This commit is contained in:
@ -104,17 +104,17 @@ pub trait DbDupCursorRO<T: DupSort> {
|
||||
pub trait DbCursorRW<T: Table> {
|
||||
/// Database operation that will update an existing row if a specified value already
|
||||
/// exists in a table, and insert a new row if the specified value doesn't already exist
|
||||
fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn upsert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Database operation that will insert a row at a given key. If the key is already
|
||||
/// present, the operation will result in an error.
|
||||
fn insert(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn insert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Append value to next cursor item.
|
||||
///
|
||||
/// This is efficient for pre-sorted data. If the data is not pre-sorted, use
|
||||
/// [`DbCursorRW::insert`].
|
||||
fn append(&mut self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
|
||||
fn append(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Delete current value that cursor points to
|
||||
fn delete_current(&mut self) -> Result<(), DatabaseError>;
|
||||
|
||||
@ -220,7 +220,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn upsert(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
@ -228,7 +228,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn insert(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
@ -236,7 +236,7 @@ impl<T: Table> DbCursorRW<T> for CursorMock {
|
||||
fn append(
|
||||
&mut self,
|
||||
_key: <T as Table>::Key,
|
||||
_value: <T as Table>::Value,
|
||||
_value: &<T as Table>::Value,
|
||||
) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ impl Compress for IntegerList {
|
||||
self.to_bytes()
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
self.to_mut_bytes(buf)
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,8 +194,8 @@ macro_rules! impl_compression_for_compact {
|
||||
impl$(<$($generic: core::fmt::Debug + Send + Sync + Compact),*>)? Compress for $name$(<$($generic),*>)? {
|
||||
type Compressed = Vec<u8>;
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(&self, buf);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(self, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,8 +253,8 @@ macro_rules! impl_compression_fixed_compact {
|
||||
Some(self.as_ref())
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(&self, buf);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
let _ = Compact::to_compact(self, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ where
|
||||
parity_scale_codec::Encode::encode(&self)
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
|
||||
parity_scale_codec::Encode::encode_to(&self, OutputCompat::wrap_mut(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ pub trait Compress: Send + Sync + Sized + Debug {
|
||||
}
|
||||
|
||||
/// Compresses data to a given buffer.
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B);
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B);
|
||||
}
|
||||
|
||||
/// Trait that will transform the data to be read from the DB.
|
||||
@ -132,7 +132,7 @@ pub trait TableImporter: DbTxMut {
|
||||
|
||||
for kv in source_tx.cursor_read::<T>()?.walk(None)? {
|
||||
let (k, v) = kv?;
|
||||
destination_cursor.append(k, v)?;
|
||||
destination_cursor.append(k, &v)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -157,7 +157,7 @@ pub trait TableImporter: DbTxMut {
|
||||
};
|
||||
for row in source_range? {
|
||||
let (key, value) = row?;
|
||||
destination_cursor.append(key, value)?;
|
||||
destination_cursor.append(key, &value)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user