reddb_server/storage/unified/dsl/builders/
refs.rs1use std::sync::Arc;
6
7use crate::storage::query::unified::ExecutionError;
8
9use super::super::super::entity::{EntityId, RefType};
10use super::super::super::store::UnifiedStore;
11use super::super::execution::execute_ref_query;
12use super::super::filters::{Filter, FilterAcceptor, WhereClause};
13use super::super::types::QueryResult;
14
15#[derive(Debug, Clone)]
17pub struct RefQueryBuilder {
18 pub(crate) source_id: EntityId,
19 pub(crate) ref_type: RefType,
20 pub(crate) max_depth: u32,
21 pub(crate) filters: Vec<Filter>,
22 pub(crate) include_source: bool,
23}
24
25impl RefQueryBuilder {
26 pub fn new(id: EntityId, ref_type: RefType) -> Self {
27 Self {
28 source_id: id,
29 ref_type,
30 max_depth: 3,
31 filters: Vec::new(),
32 include_source: false,
33 }
34 }
35
36 pub fn depth(mut self, depth: u32) -> Self {
38 self.max_depth = depth;
39 self
40 }
41
42 pub fn include_source(mut self) -> Self {
44 self.include_source = true;
45 self
46 }
47
48 pub fn where_(self, field: impl Into<String>) -> WhereClause<Self> {
50 WhereClause::new(self, field.into())
51 }
52
53 pub fn execute(self, store: &Arc<UnifiedStore>) -> Result<QueryResult, ExecutionError> {
55 execute_ref_query(self, store)
56 }
57}
58
59impl FilterAcceptor for RefQueryBuilder {
60 fn add_filter(&mut self, filter: Filter) {
61 self.filters.push(filter);
62 }
63}