Skip to main content

Expr

Struct Expr 

Source
pub struct Expr(pub Expression);
Expand description

A thin wrapper around Expression that provides fluent operator methods.

Expr is the primary value type flowing through the builder API. It wraps a single AST Expression node and adds convenience methods for comparisons (.eq(), .gt(), etc.), logical connectives (.and(), .or(), .not()), arithmetic (.add(), .sub(), .mul(), .div()), pattern matching (.like(), .ilike(), .rlike()), and other SQL operations (.in_list(), .between(), .is_null(), .alias(), .cast(), .asc(), .desc()).

The inner Expression is publicly accessible via the .0 field or Expr::into_inner().

§Examples

use polyglot_sql::builder::*;

let condition = col("age").gte(lit(18)).and(col("active").eq(boolean(true)));
assert_eq!(condition.to_sql(), "age >= 18 AND active = TRUE");

Tuple Fields§

§0: Expression

Implementations§

Source§

impl Expr

Source

pub fn into_inner(self) -> Expression

Consume this wrapper and return the inner Expression node.

Source

pub fn to_sql(&self) -> String

Generate a SQL string from this expression using the default (generic) dialect.

Returns an empty string if generation fails.

Source

pub fn eq(self, other: Expr) -> Expr

Produce a self = other equality comparison.

Source

pub fn neq(self, other: Expr) -> Expr

Produce a self <> other inequality comparison.

Source

pub fn lt(self, other: Expr) -> Expr

Produce a self < other less-than comparison.

Source

pub fn lte(self, other: Expr) -> Expr

Produce a self <= other less-than-or-equal comparison.

Source

pub fn gt(self, other: Expr) -> Expr

Produce a self > other greater-than comparison.

Source

pub fn gte(self, other: Expr) -> Expr

Produce a self >= other greater-than-or-equal comparison.

Source

pub fn and(self, other: Expr) -> Expr

Produce a self AND other logical conjunction.

Source

pub fn or(self, other: Expr) -> Expr

Produce a self OR other logical disjunction.

Source

pub fn not(self) -> Expr

Produce a NOT self logical negation.

Source

pub fn xor(self, other: Expr) -> Expr

Produce a self XOR other logical exclusive-or.

Source

pub fn add(self, other: Expr) -> Expr

Produce a self + other addition expression.

Source

pub fn sub(self, other: Expr) -> Expr

Produce a self - other subtraction expression.

Source

pub fn mul(self, other: Expr) -> Expr

Produce a self * other multiplication expression.

Source

pub fn div(self, other: Expr) -> Expr

Produce a self / other division expression.

Source

pub fn is_null(self) -> Expr

Produce a self IS NULL predicate.

Source

pub fn is_not_null(self) -> Expr

Produce a self IS NOT NULL predicate (implemented as NOT (self IS NULL)).

Source

pub fn in_list(self, values: impl IntoIterator<Item = Expr>) -> Expr

Produce a self IN (values...) membership test.

Each element of values becomes an item in the parenthesized list.

Source

pub fn between(self, low: Expr, high: Expr) -> Expr

Produce a self BETWEEN low AND high range test.

Source

pub fn like(self, pattern: Expr) -> Expr

Produce a self LIKE pattern case-sensitive pattern match.

Source

pub fn alias(self, name: &str) -> Expr

Produce a self AS alias expression alias.

Source

pub fn cast(self, to: &str) -> Expr

Produce a CAST(self AS type) type conversion.

The to parameter is parsed as a data type name; see cast() for details.

Source

pub fn asc(self) -> Expr

Wrap this expression with ascending sort order (self ASC).

Used in ORDER BY clauses. Expressions without an explicit .asc() or .desc() call default to ascending order when passed to SelectBuilder::order_by().

Source

pub fn desc(self) -> Expr

Wrap this expression with descending sort order (self DESC).

Used in ORDER BY clauses.

Source

pub fn ilike(self, pattern: Expr) -> Expr

Produce a self ILIKE pattern case-insensitive pattern match.

Supported by PostgreSQL, Snowflake, and other dialects. Dialects that do not support ILIKE natively may need transpilation.

Source

pub fn rlike(self, pattern: Expr) -> Expr

Produce a REGEXP_LIKE(self, pattern) regular expression match.

The generated SQL uses the REGEXP_LIKE function form. Different dialects may render this as RLIKE, REGEXP, or REGEXP_LIKE after transpilation.

Source

pub fn not_in(self, values: impl IntoIterator<Item = Expr>) -> Expr

Produce a self NOT IN (values...) negated membership test.

Each element of values becomes an item in the parenthesized list.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

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

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

impl IntoExpr for Expr

Source§

fn into_expr(self) -> Expr

Convert this value into an Expr.

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

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, 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> 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.