Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 22 variants Param(ParamName), Column(ColumnRef), String(String), Int(i64), Bool(bool), Null, Now, Default, BinOp { left: Box<Expr>, op: BinOp, right: Box<Expr>, }, IsNull { expr: Box<Expr>, negated: bool, }, Like { expr: Box<Expr>, pattern: Box<Expr>, }, ILike { expr: Box<Expr>, pattern: Box<Expr>, }, Any { expr: Box<Expr>, array: Box<Expr>, }, JsonGet { expr: Box<Expr>, key: Box<Expr>, }, JsonGetText { expr: Box<Expr>, key: Box<Expr>, }, Contains { expr: Box<Expr>, value: Box<Expr>, }, KeyExists { expr: Box<Expr>, key: Box<Expr>, }, Cast { expr: Box<Expr>, pg_type: PgType, }, Excluded(ColumnName), FnCall { name: String, args: Vec<Expr>, }, Count { table: TableName, }, Raw(String),
}
Expand description

A SQL expression.

Variants§

§

Param(ParamName)

A parameter placeholder (e.g., $handle -> $1)

§

Column(ColumnRef)

A column reference

§

String(String)

A string literal

§

Int(i64)

An integer literal

§

Bool(bool)

A boolean literal

§

Null

NULL

§

Now

NOW() function

§

Default

DEFAULT keyword

§

BinOp

Binary operation (e.g., a = b, a AND b)

Fields

§left: Box<Expr>
§right: Box<Expr>
§

IsNull

IS NULL / IS NOT NULL

Fields

§expr: Box<Expr>
§negated: bool
§

Like

LIKE pattern match (case-sensitive)

Fields

§expr: Box<Expr>
§pattern: Box<Expr>
§

ILike

ILIKE pattern match (case-insensitive)

Fields

§expr: Box<Expr>
§pattern: Box<Expr>
§

Any

= ANY(array) for IN checks with array parameter

Fields

§expr: Box<Expr>
§array: Box<Expr>
§

JsonGet

JSONB -> operator (get object field, returns JSONB)

Fields

§expr: Box<Expr>
§key: Box<Expr>
§

JsonGetText

JSONB ->> operator (get object field as text)

Fields

§expr: Box<Expr>
§key: Box<Expr>
§

Contains

@> operator (contains, typically for JSONB)

Fields

§expr: Box<Expr>
§value: Box<Expr>
§

KeyExists

? operator (key exists, typically for JSONB)

Fields

§expr: Box<Expr>
§key: Box<Expr>
§

Cast

Type cast (e.g., $1::text[], value::integer)

Fields

§expr: Box<Expr>
§pg_type: PgType
§

Excluded(ColumnName)

EXCLUDED.column reference for ON CONFLICT DO UPDATE

§

FnCall

Function call

Fields

§name: String
§args: Vec<Expr>
§

Count

COUNT(table.*) for counting related rows

Fields

§

Raw(String)

Raw SQL (escape hatch)

Implementations§

Source§

impl Expr

Source

pub fn param(name: ParamName) -> Self

Source

pub fn column(name: ColumnName) -> Self

Source

pub fn qualified_column(table: TableName, column: ColumnName) -> Self

Source

pub fn string(s: impl Into<String>) -> Self

Source

pub fn int(n: i64) -> Self

Source

pub fn bool(b: bool) -> Self

Source

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

Create an equality expression: self = other

Source

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

Create an AND expression: self AND other

Source

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

Create an OR expression: self OR other

Source

pub fn is_null(self) -> Self

Create IS NULL expression

Source

pub fn is_not_null(self) -> Self

Create IS NOT NULL expression

Source

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

Create LIKE expression (case-sensitive pattern match)

Source

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

Create ILIKE expression (case-insensitive pattern match)

Source

pub fn any(self, array: Expr) -> Self

Create = ANY(array) expression for IN checks

Source

pub fn json_get(self, key: Expr) -> Self

Create JSONB -> expression (get object field, returns JSONB)

Source

pub fn json_get_text(self, key: Expr) -> Self

Create JSONB ->> expression (get object field as text)

Source

pub fn contains(self, value: Expr) -> Self

Create @> expression (contains, typically for JSONB)

Source

pub fn key_exists(self, key: Expr) -> Self

Create ? expression (key exists, typically for JSONB)

Source

pub fn cast(self, pg_type: PgType) -> Self

Create a type cast expression (e.g., $1::text[])

Source

pub fn excluded(column: ColumnName) -> Self

Create an EXCLUDED.column reference for ON CONFLICT DO UPDATE

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Expr

Source§

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

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

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> 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 Render for Expr

Source§

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

Source§

impl StructuralPartialEq for 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 UnsafeUnpin 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.