typedb_driver/common/
options.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20use std::time::Duration;
21
22/// TypeDB transaction options.
23/// `TypeDBOptions` object can be used to override the default server behaviour.
24/// Options are specified using properties assignment.
25///
26/// # Examples
27///
28/// ```rust
29/// let options = Options::new().explain(true);
30/// ```
31#[derive(Clone, Copy, Debug, Default)]
32pub struct Options {
33    /// If set to `True`, the server uses parallel instead of single-threaded execution.
34    pub parallel: Option<bool>,
35    /// If set to `True`, the first batch of answers is streamed to the driver even without an explicit request for it.
36    pub prefetch: Option<bool>,
37    /// If set, specifies a guideline number of answers that the server should send before the driver issues a fresh request.
38    pub prefetch_size: Option<u64>,
39    /// If set, specifies a timeout for killing transactions automatically, preventing memory leaks in unclosed transactions.
40    pub transaction_timeout: Option<Duration>,
41    /// If set, specifies how long the driver should wait if opening a transaction is blocked by an exclusive schema write lock.
42    pub schema_lock_acquire_timeout: Option<Duration>,
43    /// If set to `True`, enables reading data from any replica, potentially boosting read throughput. Only settable in TypeDB Cloud.
44    pub read_any_replica: Option<bool>,
45}
46
47impl Options {
48    pub fn new() -> Self {
49        Self::default()
50    }
51
52    /// If set to `True`, the server uses parallel instead of single-threaded execution.
53    pub fn parallel(self, parallel: bool) -> Self {
54        Self { parallel: Some(parallel), ..self }
55    }
56
57    /// If set to `True`, the first batch of answers is streamed to the driver even without an explicit request for it.
58    pub fn prefetch(self, prefetch: bool) -> Self {
59        Self { prefetch: Some(prefetch), ..self }
60    }
61
62    /// If set, specifies a guideline number of answers that the server should send before the driver issues a fresh request.
63    pub fn prefetch_size(self, prefetch_size: u64) -> Self {
64        Self { prefetch_size: Some(prefetch_size), ..self }
65    }
66
67    /// If set, specifies a timeout for killing transactions automatically, preventing memory leaks in unclosed transactions.
68    pub fn transaction_timeout(self, timeout: Duration) -> Self {
69        Self { transaction_timeout: Some(timeout), ..self }
70    }
71
72    /// If set, specifies how long the driver should wait if opening a transaction is blocked by an exclusive schema write lock.
73    pub fn schema_lock_acquire_timeout(self, timeout: Duration) -> Self {
74        Self { schema_lock_acquire_timeout: Some(timeout), ..self }
75    }
76
77    /// If set to `True`, enables reading data from any replica, potentially boosting read throughput. Only settable in TypeDB Cloud.
78    pub fn read_any_replica(self, read_any_replica: bool) -> Self {
79        Self { read_any_replica: Some(read_any_replica), ..self }
80    }
81}