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    /// If set, requests the server to return the structure of the query in the ConceptRow header.
41    pub include_query_structure: Option<bool>,
42}
43
44impl QueryOptions {
45    pub fn new() -> Self {
46        Self::default()
47    }
48
49    /// If set, specifies if types should be included in instance structs returned in ConceptRow answers.
50    /// This option allows reducing the amount of unnecessary data transmitted.
51    pub fn include_instance_types(self, include_instance_types: bool) -> Self {
52        Self { include_instance_types: Some(include_instance_types), ..self }
53    }
54
55    /// If set, specifies the number of extra query responses sent before the client side has to re-request more responses.
56    /// Increasing this may increase performance for queries with a huge number of answers, as it can
57    /// reduce the number of network round-trips at the cost of more resources on the server side.
58    pub fn prefetch_size(self, prefetch_size: u64) -> Self {
59        Self { prefetch_size: Some(prefetch_size), ..self }
60    }
61
62    /// If set, requests the server to return the structure of the query in the ConceptRow header.
63    pub fn include_query_structure(self, include_query_structure: bool) -> Self {
64        Self { include_query_structure: Some(include_query_structure), ..self }
65    }
66}