Skip to main content

WhereBuilder

Struct WhereBuilder 

Source
pub struct WhereBuilder<D: Dialect> { /* private fields */ }
Expand description

Accumulator passed to and_where/or_where closures.

It owns its own Vec<Predicate>; the closure consumes it and returns it, and the caller wraps the collected predicates into a Predicate::Group. The PhantomData<D> keeps the dialect in scope without threading the full builder through the closure.

Siblings added directly are AND-joined; call and_where/or_where inside the closure to nest a further parenthesized group (and or_where introduces OR within the group). Nesting is arbitrary-depth.

Implementations§

Source§

impl<D: Dialect> WhereBuilder<D>

Source

pub fn new() -> Self

Create an empty accumulator.

Source

pub fn and_where( self, f: impl FnOnce(WhereBuilder<D>) -> WhereBuilder<D>, ) -> Self

Add a nested parenthesized AND (...) group built by the closure.

Source

pub fn or_where( self, f: impl FnOnce(WhereBuilder<D>) -> WhereBuilder<D>, ) -> Self

Add a nested parenthesized OR (...) group built by the closure.

Source

pub fn where_eq(self, col: &str, val: impl IntoBind) -> Self

col = val.

Source

pub fn where_ne(self, col: &str, val: impl IntoBind) -> Self

col != val.

Source

pub fn where_gt(self, col: &str, val: impl IntoBind) -> Self

col > val.

Source

pub fn where_gte(self, col: &str, val: impl IntoBind) -> Self

col >= val.

Source

pub fn where_lt(self, col: &str, val: impl IntoBind) -> Self

col < val.

Source

pub fn where_lte(self, col: &str, val: impl IntoBind) -> Self

col <= val.

Source

pub fn where_like(self, col: &str, val: impl IntoBind) -> Self

col LIKE val.

Source

pub fn where_ilike(self, col: &str, val: impl IntoBind) -> Self

col ILIKE val — dialect-aware case-insensitive match (see QueryBuilder::where_ilike).

Source

pub fn where_jsonb_contains(self, col: &str, val: impl IntoBind) -> Self

col @> val — JSONB containment (Postgres-oriented; see QueryBuilder::where_jsonb_contains).

Source

pub fn where_in( self, col: &str, vals: impl IntoIterator<Item = impl IntoBind>, ) -> Self

col IN (...).

Source

pub fn where_not_in( self, col: &str, vals: impl IntoIterator<Item = impl IntoBind>, ) -> Self

col NOT IN (...).

Source

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

col IS NULL.

Source

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

col IS NOT NULL.

Source

pub fn where_between( self, col: &str, lo: impl IntoBind, hi: impl IntoBind, ) -> Self

col BETWEEN lo AND hi.

Source

pub fn where_raw(self, sql: &str, binds: Vec<Value>) -> Self

Raw SQL predicate with its own binds — the verbatim escape hatch.

§Warning: positional placeholder contract

sql is emitted verbatim (it is NOT escaped or renumbered) and binds are appended to the running bind list in order. For Postgres, the caller MUST write $N numbers matching the actual bind position — that is, number of binds already accumulated + 1, +2, … For MySQL/SQLite use ?. No renumbering is performed, so a wrong $N produces a malformed query.

Source

pub fn where_column(self, lhs: &str, op: &'static str, rhs: &str) -> Self

lhs op rhs — compare two column identifiers (both escaped at compile time), no bind. See QueryBuilder::where_column.

Trait Implementations§

Source§

impl<D: Dialect> Default for WhereBuilder<D>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<D> Freeze for WhereBuilder<D>

§

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

§

impl<D> Send for WhereBuilder<D>

§

impl<D> Sync for WhereBuilder<D>

§

impl<D> Unpin for WhereBuilder<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for WhereBuilder<D>

§

impl<D> UnwindSafe for WhereBuilder<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> 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, 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