typedb_driver/common/
transaction_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/// `TransactionOptions` object can be used to override the default server behaviour for opened
24/// transactions.
25///
26/// # Examples
27///
28/// ```rust
29/// let options = TransactionOptions::new().transaction_timeout(Duration::from_secs(60));
30/// ```
31#[derive(Clone, Copy, Debug, Default)]
32pub struct TransactionOptions {
33    /// If set, specifies a timeout for killing transactions automatically, preventing memory leaks in unclosed transactions.
34    pub transaction_timeout: Option<Duration>,
35    /// If set, specifies how long the driver should wait if opening a transaction is blocked by an exclusive schema write lock.
36    pub schema_lock_acquire_timeout: Option<Duration>,
37}
38
39impl TransactionOptions {
40    pub fn new() -> Self {
41        Self::default()
42    }
43
44    /// If set, specifies a timeout for killing transactions automatically, preventing memory leaks in unclosed transactions.
45    pub fn transaction_timeout(self, timeout: Duration) -> Self {
46        Self { transaction_timeout: Some(timeout), ..self }
47    }
48
49    /// If set, specifies how long the driver should wait if opening a transaction is blocked by an exclusive schema write lock.
50    pub fn schema_lock_acquire_timeout(self, timeout: Duration) -> Self {
51        Self { schema_lock_acquire_timeout: Some(timeout), ..self }
52    }
53}