dgraph_tonic/txn/
best_effort.rs

1use std::collections::hash_map::RandomState;
2use std::collections::HashMap;
3use std::fmt::Debug;
4
5use crate::client::ILazyClient;
6use crate::txn::read_only::ReadOnly;
7use crate::txn::{IState, TxnReadOnlyType, TxnState, TxnVariant};
8use crate::Request;
9
10///
11/// Inner state for best effort transaction
12///
13#[derive(Clone, Debug)]
14pub struct BestEffort<C: ILazyClient> {
15    read_only: ReadOnly<C>,
16}
17
18impl<C: ILazyClient> IState for BestEffort<C> {
19    ///
20    /// Update read only query with best_effort flag
21    ///
22    fn query_request<S: ILazyClient>(
23        &self,
24        state: &TxnState<S>,
25        query: String,
26        vars: HashMap<String, String, RandomState>,
27    ) -> Request {
28        let mut request = self.read_only.query_request(state, query, vars);
29        request.best_effort = true;
30        request
31    }
32}
33
34///
35/// Best effort variant of read only transaction
36///
37pub type TxnBestEffortType<C> = TxnVariant<BestEffort<C>, C>;
38
39impl<C: ILazyClient> TxnReadOnlyType<C> {
40    ///
41    /// Create best effort transaction from read only state
42    ///
43    pub fn best_effort(self) -> TxnBestEffortType<C> {
44        TxnVariant {
45            state: self.state,
46            extra: BestEffort {
47                read_only: self.extra,
48            },
49        }
50    }
51}