Skip to content

Commit

Permalink
add size_of to TxPartition
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Nov 15, 2024
1 parent d1c05c5 commit ed91e86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/tx/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,33 @@ impl TransactionalPartitionHandle {
self.inner.get(key)
}

/// Retrieves the size of an item from the partition.
///
/// The operation will run wrapped in a read snapshot.
///
/// # Examples
///
/// ```
/// # use fjall::{Config, Keyspace, PartitionCreateOptions};
/// #
/// # let folder = tempfile::tempdir()?;
/// # let keyspace = Config::new(folder).open_transactional()?;
/// # let partition = keyspace.open_partition("default", PartitionCreateOptions::default())?;
/// partition.insert("a", "my_value")?;
///
/// let len = partition.size_of("a")?.unwrap_or_default();
/// assert_eq!("my_value".len() as u32, len);
/// #
/// # Ok::<(), fjall::Error>(())
/// ```
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn size_of<K: AsRef<[u8]>>(&self, key: K) -> crate::Result<Option<u32>> {
self.inner.size_of(key)
}

/// Returns `true` if the partition contains the specified key.
///
/// The operation will run wrapped in a read snapshot.
Expand Down
2 changes: 1 addition & 1 deletion src/tx/write/ssi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl WriteTransaction {
Ok(res)
}

/// Retrieves an item from the transaction's state.
/// Retrieves the size of an item from the transaction's state.
///
/// The transaction allows reading your own writes (RYOW).
///
Expand Down

0 comments on commit ed91e86

Please sign in to comment.