Skip to main content

cratestack_sql/filter/
expr_relations.rs

1//! Relation-subquery constructors for [`FilterExpr`].
2//!
3//! Split from `expr.rs` (200-LoC ceiling): that module owns the enum
4//! itself plus the boolean combinators (`all`/`any`/`not`/`and`/`or`),
5//! this one owns the four `relation*` constructors, which are a
6//! distinct concern — they build a correlated-subquery node rather
7//! than combining existing predicates.
8
9use cratestack_policy::RelationQuantifier;
10
11use super::expr::{FilterExpr, RelationFilter};
12
13impl FilterExpr {
14    pub fn relation(
15        parent_table: &'static str,
16        parent_column: &'static str,
17        related_table: &'static str,
18        related_column: &'static str,
19        filter: FilterExpr,
20    ) -> Self {
21        Self::Relation(RelationFilter::new(
22            RelationQuantifier::ToOne,
23            parent_table,
24            parent_column,
25            related_table,
26            related_column,
27            filter,
28        ))
29    }
30
31    pub fn relation_some(
32        parent_table: &'static str,
33        parent_column: &'static str,
34        related_table: &'static str,
35        related_column: &'static str,
36        filter: FilterExpr,
37    ) -> Self {
38        Self::Relation(RelationFilter::new(
39            RelationQuantifier::Some,
40            parent_table,
41            parent_column,
42            related_table,
43            related_column,
44            filter,
45        ))
46    }
47
48    pub fn relation_every(
49        parent_table: &'static str,
50        parent_column: &'static str,
51        related_table: &'static str,
52        related_column: &'static str,
53        filter: FilterExpr,
54    ) -> Self {
55        Self::Relation(RelationFilter::new(
56            RelationQuantifier::Every,
57            parent_table,
58            parent_column,
59            related_table,
60            related_column,
61            filter,
62        ))
63    }
64
65    pub fn relation_none(
66        parent_table: &'static str,
67        parent_column: &'static str,
68        related_table: &'static str,
69        related_column: &'static str,
70        filter: FilterExpr,
71    ) -> Self {
72        Self::Relation(RelationFilter::new(
73            RelationQuantifier::None,
74            parent_table,
75            parent_column,
76            related_table,
77            related_column,
78            filter,
79        ))
80    }
81}