tikv_client/transaction/
snapshot.rs1use derive_new::new;
4use log::{debug, trace};
5
6use crate::BoundRange;
7use crate::Key;
8use crate::KvPair;
9use crate::Result;
10use crate::Transaction;
11use crate::Value;
12
13#[derive(new)]
21pub struct Snapshot {
22 transaction: Transaction,
23}
24
25impl Snapshot {
26 pub async fn get(&mut self, key: impl Into<Key>) -> Result<Option<Value>> {
28 trace!("invoking get request on snapshot");
29 self.transaction.get(key).await
30 }
31
32 pub async fn key_exists(&mut self, key: impl Into<Key>) -> Result<bool> {
34 debug!("invoking key_exists request on snapshot");
35 self.transaction.key_exists(key).await
36 }
37
38 pub async fn batch_get(
40 &mut self,
41 keys: impl IntoIterator<Item = impl Into<Key>>,
42 ) -> Result<impl Iterator<Item = KvPair>> {
43 debug!("invoking batch_get request on snapshot");
44 self.transaction.batch_get(keys).await
45 }
46
47 pub async fn scan(
49 &mut self,
50 range: impl Into<BoundRange>,
51 limit: u32,
52 ) -> Result<impl Iterator<Item = KvPair>> {
53 debug!("invoking scan request on snapshot");
54 self.transaction.scan(range, limit).await
55 }
56
57 pub async fn scan_keys(
59 &mut self,
60 range: impl Into<BoundRange>,
61 limit: u32,
62 ) -> Result<impl Iterator<Item = Key>> {
63 debug!("invoking scan_keys request on snapshot");
64 self.transaction.scan_keys(range, limit).await
65 }
66
67 pub async fn scan_reverse(
69 &mut self,
70 range: impl Into<BoundRange>,
71 limit: u32,
72 ) -> Result<impl Iterator<Item = KvPair>> {
73 debug!("invoking scan_reverse request on snapshot");
74 self.transaction.scan_reverse(range, limit).await
75 }
76
77 pub async fn scan_keys_reverse(
79 &mut self,
80 range: impl Into<BoundRange>,
81 limit: u32,
82 ) -> Result<impl Iterator<Item = Key>> {
83 debug!("invoking scan_keys_reverse request on snapshot");
84 self.transaction.scan_keys_reverse(range, limit).await
85 }
86}