use crate::{Deserialize, Key, Store, ValueKey}; impl Store { pub async fn get_value(&self, key: ValueKey) -> crate::Result> where U: Deserialize + 'static, { #[cfg(feature = "is_async")] { self.read_transaction().await?.get_value(key).await } #[cfg(feature = "is_sync")] { let trx = self.read_transaction()?; self.spawn_worker(move || trx.get_value(key)).await } } pub async fn get_values(&self, key: Vec) -> crate::Result>> where U: Deserialize + 'static, { #[cfg(feature = "is_async")] { let mut trx = self.read_transaction().await?; let mut results = Vec::with_capacity(key.len()); for key in key { trx.refresh_if_old().await?; results.push(trx.get_value(key).await?); } Ok(results) } #[cfg(feature = "is_sync")] { let trx = self.read_transaction()?; self.spawn_worker(move || { let mut results = Vec::with_capacity(key.len()); for key in key { results.push(trx.get_value(key)?); } Ok(results) }) .await } } pub async fn iterate( &self, acc: T, begin: impl Key, end: impl Key, first: bool, ascending: bool, cb: impl Fn(&mut T, &[u8], &[u8]) -> crate::Result + Sync + Send + 'static, ) -> crate::Result { #[cfg(feature = "is_async")] { self.read_transaction() .await? .iterate(acc, begin, end, first, ascending, cb) .await } #[cfg(feature = "is_sync")] { let trx = self.read_transaction()?; self.spawn_worker(move || trx.iterate(acc, begin, end, first, ascending, cb)) .await } } }