typedb_driver/common/
query_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
20/// TypeDB query options.
21/// `QueryOptions` object can be used to override the default server behaviour for executed queries.
22///
23/// # Examples
24///
25/// ```rust
26/// let options = QueryOptions::new().include_instance_types(true);
27/// ```
28#[derive(Clone, Copy, Debug, Default)]
29pub struct QueryOptions {
30    /// If set, specifies if types should be included in instance structs returned in ConceptRow answers.
31    /// This option allows reducing the amount of unnecessary data transmitted.
32    pub include_instance_types: Option<bool>,
33
34    /// If set, specifies the number of extra query responses sent before the client side has to re-request more responses.
35    /// Increasing this may increase performance for queries with a huge number of answers, as it can
36    /// reduce the number of network round-trips at the cost of more resources on the server side.
37    /// Minimal value: 1.
38    pub prefetch_size: Option<u64>,
39}
40
41impl QueryOptions {
42    pub fn new() -> Self {
43        Self::default()
44    }
45
46    /// If set, specifies if types should be included in instance structs returned in ConceptRow answers.
47    /// This option allows reducing the amount of unnecessary data transmitted.
48    pub fn include_instance_types(self, include_instance_types: bool) -> Self {
49        Self { include_instance_types: Some(include_instance_types), ..self }
50    }
51
52    /// If set, specifies the number of extra query responses sent before the client side has to re-request more responses.
53    /// Increasing this may increase performance for queries with a huge number of answers, as it can
54    /// reduce the number of network round-trips at the cost of more resources on the server side.
55    pub fn prefetch_size(self, prefetch_size: u64) -> Self {
56        Self { prefetch_size: Some(prefetch_size), ..self }
57    }
58}