Skip to main content

FilterClause

Struct FilterClause 

Source
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

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

True when nothing was pushed.

Source

pub fn sql(&self) -> String

The WHERE body: a = :a AND b >= :b__gte. Empty when nothing was pushed.

Source

pub fn where_sql(&self) -> String

sql with the WHERE keyword, or "" when empty (no dangling WHERE).

Source

pub fn into_params(self) -> Params

Consume into Params for query_with_values / execute_with_values.

Source

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.

Source

pub fn filter_when(self, cond: bool, fragment: impl Into<String>) -> Self

filter only when cond holds.

Source

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"));
Source

pub fn bind(self, name: &str, value: impl IntoGrpcValue) -> Self

Register a param WITHOUT emitting a fragment — for placeholders referenced elsewhere in the statement.

Source

pub fn eq(self, col: &str, value: impl IntoGrpcValue) -> Self

col = :col.

Source

pub fn ne(self, col: &str, value: impl IntoGrpcValue) -> Self

col <> :col__ne.

Source

pub fn lt(self, col: &str, value: impl IntoGrpcValue) -> Self

col < :col__lt.

Source

pub fn lte(self, col: &str, value: impl IntoGrpcValue) -> Self

col <= :col__lte.

Source

pub fn gt(self, col: &str, value: impl IntoGrpcValue) -> Self

col > :col__gt.

Source

pub fn gte(self, col: &str, value: impl IntoGrpcValue) -> Self

col >= :col__gte.

Source

pub fn between( self, col: &str, from: impl IntoGrpcValue, to: impl IntoGrpcValue, ) -> Self

col BETWEEN :col__from AND :col__to.

Source

pub fn is_null(self, col: &str) -> Self

col IS NULL (no param).

Source

pub fn is_not_null(self, col: &str) -> Self

col IS NOT NULL (no param).

Source

pub fn in_list<I>(self, col: &str, values: I) -> Self

col IN :col__in with the values bound as ONE list parameter.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn like(self, col: &str, pattern: impl IntoGrpcValue) -> Self

col LIKE :col__like (case-sensitive, %/? wildcards).

Source

pub fn ilike(self, col: &str, pattern: impl IntoGrpcValue) -> Self

col ILIKE :col__ilike (case-insensitive LIKE).

Trait Implementations§

Source§

impl Clone for FilterClause

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterClause

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FilterClause

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more