Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 14 variants Value(Value), Field(FieldRef), Binary { left: Box<Expr>, op: BinaryOp, right: Box<Expr>, }, Unary { op: UnaryOp, expr: Box<Expr>, }, Func { name: String, args: Vec<Expr>, }, Aggregate(AggregationDef), Cast { expr: Box<Expr>, to_type: String, }, Case(CaseDef), Window(WindowDef), Exists(Box<QueryStmt>), SubQuery(Box<QueryStmt>), ArraySubQuery(Box<QueryStmt>), Raw { sql: String, params: Vec<Value>, }, Custom(Box<dyn CustomExpr>),
}
Expand description

An expression in a SQL statement.

Variants§

§

Value(Value)

Literal value.

§

Field(FieldRef)

Column reference.

§

Binary

Binary operation: left op right.

Fields

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

Unary

Unary operation: -expr, NOT expr.

Fields

§expr: Box<Expr>
§

Func

Function call: name(args...).

Fields

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

Aggregate(AggregationDef)

Aggregate function: COUNT(expr), SUM(DISTINCT expr) FILTER (WHERE ...).

§

Cast

Type cast: expr::type (PG) or CAST(expr AS type).

Fields

§expr: Box<Expr>
§to_type: String
§

Case(CaseDef)

CASE WHEN … THEN … ELSE … END.

§

Window(WindowDef)

Window function: expr OVER (PARTITION BY ... ORDER BY ... frame).

§

Exists(Box<QueryStmt>)

EXISTS (subquery).

§

SubQuery(Box<QueryStmt>)

Scalar subquery.

§

ArraySubQuery(Box<QueryStmt>)

ARRAY(subquery).

§

Raw

Raw SQL with parameters (escape hatch).

Fields

§params: Vec<Value>
§

Custom(Box<dyn CustomExpr>)

User-defined expression (extension point).

Implementations§

Source§

impl Expr

Source

pub fn field(table: &str, name: &str) -> Self

Column reference: table.field.

Source

pub fn value(val: impl Into<Value>) -> Self

Literal value.

Source

pub fn raw(sql: impl Into<String>) -> Self

Raw SQL expression (no parameters).

Source

pub fn func(name: impl Into<String>, args: Vec<Expr>) -> Self

Function call: name(args...).

Source

pub fn cast(expr: Expr, to_type: impl Into<String>) -> Self

Type cast: CAST(expr AS to_type).

Source

pub fn count(expr: Expr) -> Self

COUNT(expr).

Source

pub fn count_all() -> Self

COUNT(*).

Source

pub fn sum(expr: Expr) -> Self

SUM(expr).

Source

pub fn avg(expr: Expr) -> Self

AVG(expr).

Source

pub fn min(expr: Expr) -> Self

MIN(expr).

Source

pub fn max(expr: Expr) -> Self

MAX(expr).

Source

pub fn exists(query: QueryStmt) -> Self

EXISTS (subquery).

Source

pub fn subquery(query: QueryStmt) -> Self

Scalar subquery.

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 From<FieldRef> for Expr

Source§

fn from(f: FieldRef) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Expr

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.

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.