pub struct FilterClause { /* private fields */ }Expand description
Accumulates AND-joined WHERE fragments and their bound values.
let filter = FilterClause::new()
.filter("is_visible = true")
.gte("release_date", chrono::NaiveDate::from_ymd_opt(2020, 1, 1).unwrap());
assert!(filter.sql().contains("release_date >= :release_date__gte"));
assert_eq!(FilterClause::new().where_sql(), "");Compose into a query with Params; merge with
SetClause for UPDATE … SET … WHERE ….
Implementations§
Source§impl FilterClause
impl FilterClause
pub fn new() -> Self
Sourcepub fn sql(&self) -> String
pub fn sql(&self) -> String
The WHERE body: a = :a AND b >= :b__gte. Empty when nothing
was pushed.
Sourcepub fn where_sql(&self) -> String
pub fn where_sql(&self) -> String
sql with the WHERE keyword, or "" when empty
(no dangling WHERE).
Sourcepub fn into_params(self) -> Params
pub fn into_params(self) -> Params
Consume into Params for query_with_values / execute_with_values.
Sourcepub fn filter(self, fragment: impl Into<String>) -> Self
pub fn filter(self, fragment: impl Into<String>) -> Self
Include a raw fragment as-is. The fragment owns any placeholders it
references — bind them via bind.
Sourcepub fn filter_when(self, cond: bool, fragment: impl Into<String>) -> Self
pub fn filter_when(self, cond: bool, fragment: impl Into<String>) -> Self
filter only when cond holds.
Sourcepub fn apply_if<T>(
self,
option: Option<T>,
f: impl FnOnce(Self, T) -> Self,
) -> Self
pub fn apply_if<T>( self, option: Option<T>, f: impl FnOnce(Self, T) -> Self, ) -> Self
Apply a multi-call step only when option is Some — the
conditional-composition form for fragments that need more than one
builder call (a bind + filter
pair, or an operator chosen at runtime). None passes the clause
through untouched, so a ladder of apply_ifs reads as a
declarative optional-predicate list:
let filter = FilterClause::new()
.apply_if(Some(75), |f, min| {
f.bind("band_min", min).filter("reviews >= :band_min")
})
.apply_if(None::<i32>, |f, max| f.lte("reviews", max));
assert_eq!(filter.sql(), "reviews >= :band_min");
assert!(filter.clone().into_params().0.contains_key("band_min"));Sourcepub fn bind(self, name: &str, value: impl IntoGrpcValue) -> Self
pub fn bind(self, name: &str, value: impl IntoGrpcValue) -> Self
Register a param WITHOUT emitting a fragment — for placeholders referenced elsewhere in the statement.
Sourcepub fn eq(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn eq(self, col: &str, value: impl IntoGrpcValue) -> Self
col = :col.
Sourcepub fn ne(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn ne(self, col: &str, value: impl IntoGrpcValue) -> Self
col <> :col__ne.
Sourcepub fn lt(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn lt(self, col: &str, value: impl IntoGrpcValue) -> Self
col < :col__lt.
Sourcepub fn lte(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn lte(self, col: &str, value: impl IntoGrpcValue) -> Self
col <= :col__lte.
Sourcepub fn gt(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn gt(self, col: &str, value: impl IntoGrpcValue) -> Self
col > :col__gt.
Sourcepub fn gte(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn gte(self, col: &str, value: impl IntoGrpcValue) -> Self
col >= :col__gte.
Sourcepub fn between(
self,
col: &str,
from: impl IntoGrpcValue,
to: impl IntoGrpcValue,
) -> Self
pub fn between( self, col: &str, from: impl IntoGrpcValue, to: impl IntoGrpcValue, ) -> Self
col BETWEEN :col__from AND :col__to.
Sourcepub fn is_not_null(self, col: &str) -> Self
pub fn is_not_null(self, col: &str) -> Self
col IS NOT NULL (no param).
Sourcepub fn in_list<I>(self, col: &str, values: I) -> Self
pub fn in_list<I>(self, col: &str, values: I) -> Self
col IN :col__in with the values bound as ONE list parameter.
Sourcepub fn not_in<I>(self, col: &str, values: I) -> Self
pub fn not_in<I>(self, col: &str, values: I) -> Self
col NOT IN :col__nin. Documented NOT to use the index — pair
with an indexed condition on large types.
History: on an indexed property, releases 26.7.1–26.9.0 served the IN result set here (ArcadeData/arcadedb#6796). Fixed in 26.9.1.
Sourcepub fn contains(self, col: &str, value: impl IntoGrpcValue) -> Self
pub fn contains(self, col: &str, value: impl IntoGrpcValue) -> Self
col CONTAINS :col__has — true when the collection holds the
bound SCALAR value. For multi-element membership use
contains_all /
contains_any.
Sourcepub fn contains_all<I>(self, col: &str, values: I) -> Self
pub fn contains_all<I>(self, col: &str, values: I) -> Self
col CONTAINSALL :col__all — every element of the bound collection
is present in col.
Sourcepub fn contains_any<I>(self, col: &str, values: I) -> Self
pub fn contains_any<I>(self, col: &str, values: I) -> Self
col CONTAINSANY :col__any — at least one element of the bound
collection is present in col.
Sourcepub fn not_contains_any<I>(self, col: &str, values: I) -> Self
pub fn not_contains_any<I>(self, col: &str, values: I) -> Self
NOT (col CONTAINSANY :col__any) — none of the bound elements
may be present.
Sourcepub fn like(self, col: &str, pattern: impl IntoGrpcValue) -> Self
pub fn like(self, col: &str, pattern: impl IntoGrpcValue) -> Self
col LIKE :col__like (case-sensitive, %/? wildcards).
Sourcepub fn ilike(self, col: &str, pattern: impl IntoGrpcValue) -> Self
pub fn ilike(self, col: &str, pattern: impl IntoGrpcValue) -> Self
col ILIKE :col__ilike (case-insensitive LIKE).
Trait Implementations§
Source§impl Clone for FilterClause
impl Clone for FilterClause
Source§impl Debug for FilterClause
impl Debug for FilterClause
Auto Trait Implementations§
impl Freeze for FilterClause
impl RefUnwindSafe for FilterClause
impl Send for FilterClause
impl Sync for FilterClause
impl Unpin for FilterClause
impl UnsafeUnpin for FilterClause
impl UnwindSafe for FilterClause
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request