use derive_new::new;
use log::debug;
use std::marker::PhantomData;
use crate::codec::ApiV1TxnCodec;
use crate::pd::{PdClient, PdRpcClient};
use crate::request::codec::Codec;
use crate::BoundRange;
use crate::Key;
use crate::KvPair;
use crate::Result;
use crate::Transaction;
use crate::Value;
#[derive(new)]
pub struct Snapshot<Cod: Codec = ApiV1TxnCodec, PdC: PdClient<Codec = Cod> = PdRpcClient<Cod>> {
transaction: Transaction<Cod, PdC>,
phantom: PhantomData<Cod>,
}
impl<Cod: Codec, PdC: PdClient<Codec = Cod>> Snapshot<Cod, PdC> {
pub async fn get(&mut self, key: impl Into<Key>) -> Result<Option<Value>> {
debug!("invoking get request on snapshot");
self.transaction.get(key).await
}
pub async fn key_exists(&mut self, key: impl Into<Key>) -> Result<bool> {
debug!("invoking key_exists request on snapshot");
self.transaction.key_exists(key).await
}
pub async fn batch_get(
&mut self,
keys: impl IntoIterator<Item = impl Into<Key>>,
) -> Result<impl Iterator<Item = KvPair>> {
debug!("invoking batch_get request on snapshot");
self.transaction.batch_get(keys).await
}
pub async fn scan(
&mut self,
range: impl Into<BoundRange>,
limit: u32,
) -> Result<impl Iterator<Item = KvPair>> {
debug!("invoking scan request on snapshot");
self.transaction.scan(range, limit).await
}
pub async fn scan_keys(
&mut self,
range: impl Into<BoundRange>,
limit: u32,
) -> Result<impl Iterator<Item = Key>> {
debug!("invoking scan_keys request on snapshot");
self.transaction.scan_keys(range, limit).await
}
pub async fn scan_reverse(
&mut self,
range: impl Into<BoundRange>,
limit: u32,
) -> Result<impl Iterator<Item = KvPair>> {
debug!("invoking scan_reverse request on snapshot");
self.transaction.scan_reverse(range, limit).await
}
pub async fn scan_keys_reverse(
&mut self,
range: impl Into<BoundRange>,
limit: u32,
) -> Result<impl Iterator<Item = Key>> {
debug!("invoking scan_keys_reverse request on snapshot");
self.transaction.scan_keys_reverse(range, limit).await
}
}