Skip to main content

Predicate

Enum Predicate 

Source
pub enum Predicate<D: Dialect> {
    Binary {
        col: String,
        op: &'static str,
        val: Value,
    },
    In {
        col: String,
        neg: bool,
        vals: Vec<Value>,
    },
    Null {
        col: String,
        neg: bool,
    },
    Between {
        col: String,
        lo: Value,
        hi: Value,
    },
    ILike {
        col: String,
        val: Value,
    },
    JsonContains {
        col: String,
        val: Value,
    },
    Raw {
        sql: String,
        binds: Vec<Value>,
    },
    Group {
        outer_conj: Conj,
        preds: Vec<Predicate<D>>,
    },
    Column {
        lhs: String,
        op: &'static str,
        rhs: String,
    },
    Exists {
        neg: bool,
        sub: Box<QueryBuilder<D>>,
    },
    InSubquery {
        col: String,
        neg: bool,
        sub: Box<QueryBuilder<D>>,
    },
}
Expand description

A single WHERE-clause predicate.

Generic over the Dialect marker D because subquery-bearing variants (Predicate::Exists / Predicate::InSubquery) embed a QueryBuilder<D>; the recursion is broken with a Box.

Variants§

§

Binary

col op value, e.g. "age" > $1.

Fields

§col: String

Raw identifier; escaped in compile.rs.

§op: &'static str

SQL operator token (=, !=, LIKE, …).

§val: Value

Bound value.

§

In

col [NOT ]IN (...).

Fields

§col: String

Raw identifier; escaped in compile.rs.

§neg: bool

Whether this is a NOT IN.

§vals: Vec<Value>

Bound values; empty yields a constant true/false predicate.

§

Null

col IS [NOT ]NULL.

Fields

§col: String

Raw identifier; escaped in compile.rs.

§neg: bool

Whether this is IS NOT NULL.

§

Between

col BETWEEN lo AND hi.

Fields

§col: String

Raw identifier; escaped in compile.rs.

§lo: Value

Lower bound.

§hi: Value

Upper bound.

§

ILike

col ILIKE val — dialect-aware case-insensitive match.

Postgres emits native {col} ILIKE {ph}; MySQL/SQLite emit LOWER({col}) LIKE LOWER({ph}). Dispatched in compile::write_pred.

Fields

§col: String

Raw identifier; escaped in compile.rs.

§val: Value

Bound value.

§

JsonContains

col @> val — JSONB containment (Postgres-oriented; @> emitted verbatim for all dialects).

Fields

§col: String

Raw identifier; escaped in compile.rs.

§val: Value

Bound value (JSON text or Value::Json).

§

Raw

Raw SQL fragment with its own binds, emitted verbatim.

Fields

§sql: String

Verbatim SQL.

§binds: Vec<Value>

Bound values appended in order.

§

Group

A parenthesized group of predicates.

outer_conj controls how the group attaches to the preceding clause (AND (...) vs OR (...)). Inner predicates are joined with AND, except that a nested Group carries its own outer_conj (so or_where inside a group emits OR (...)) — groups nest arbitrarily.

Fields

§outer_conj: Conj

How this group attaches to the preceding clause (outer separator).

§preds: Vec<Predicate<D>>

Inner predicates; rendered like the top level, so nested groups with outer_conj: Or introduce OR within this group.

§

Column

lhs op rhs — both sides are column identifiers (escaped at compile time), no bind. Backs where_column.

Fields

§lhs: String

Raw left identifier; escaped in compile.rs.

§op: &'static str

SQL operator token (=, !=, …).

§rhs: String

Raw right identifier; escaped in compile.rs.

§

Exists

[NOT ]EXISTS (subquery).

Fields

§neg: bool

Whether this is NOT EXISTS.

§sub: Box<QueryBuilder<D>>

The embedded sub-query, compiled with placeholder continuity.

§

InSubquery

col [NOT ]IN (subquery).

Fields

§col: String

Raw identifier; escaped in compile.rs.

§neg: bool

Whether this is NOT IN.

§sub: Box<QueryBuilder<D>>

The embedded sub-query, compiled with placeholder continuity.

Trait Implementations§

Source§

impl<D: Clone + Dialect> Clone for Predicate<D>

Source§

fn clone(&self) -> Predicate<D>

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<D: Debug + Dialect> Debug for Predicate<D>

Source§

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

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

impl<D: PartialEq + Dialect> PartialEq for Predicate<D>

Source§

fn eq(&self, other: &Predicate<D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Dialect> StructuralPartialEq for Predicate<D>

Auto Trait Implementations§

§

impl<D> Freeze for Predicate<D>

§

impl<D> RefUnwindSafe for Predicate<D>
where D: RefUnwindSafe,

§

impl<D> Send for Predicate<D>

§

impl<D> Sync for Predicate<D>

§

impl<D> Unpin for Predicate<D>

§

impl<D> UnsafeUnpin for Predicate<D>

§

impl<D> UnwindSafe for Predicate<D>
where D: UnwindSafe,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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