Skip to main content

SimpleExpr

Enum SimpleExpr 

Source
pub enum SimpleExpr {
Show 17 variants Column(ColumnRef), TableColumn(DynIden, DynIden), Value(Value), Unary(UnOper, Box<SimpleExpr>), Binary(Box<SimpleExpr>, BinOper, Box<SimpleExpr>), FunctionCall(DynIden, Vec<SimpleExpr>), SubQuery(Option<SubQueryOper>, Box<SelectStatement>), Tuple(Vec<SimpleExpr>), Custom(String), CustomWithExpr(String, Vec<SimpleExpr>), Constant(Keyword), Asterisk, Case(Box<CaseStatement>), AsEnum(DynIden, Box<SimpleExpr>), Cast(Box<SimpleExpr>, DynIden), Window { func: Box<SimpleExpr>, window: WindowStatement, }, WindowNamed { func: Box<SimpleExpr>, name: DynIden, },
}
Expand description

A simple SQL expression.

This enum represents the AST for SQL expressions. Each variant corresponds to a type of SQL expression that can appear in queries.

§Example

use reinhardt_query::SimpleExpr;

// Column reference
let col = SimpleExpr::Column(ColumnRef::column("name"));

// Value literal
let val = SimpleExpr::Value(Value::Int(Some(42)));

// Binary operation (column = 42)
let eq = SimpleExpr::Binary(
    Box::new(col),
    BinOper::Equal,
    Box::new(val),
);

Variants§

§

Column(ColumnRef)

A column reference (e.g., name, users.name, public.users.name)

§

TableColumn(DynIden, DynIden)

A table-qualified column (legacy format)

§

Value(Value)

A literal value (e.g., 42, 'hello', TRUE)

§

Unary(UnOper, Box<SimpleExpr>)

A unary operation (e.g., NOT x)

§

Binary(Box<SimpleExpr>, BinOper, Box<SimpleExpr>)

A binary operation (e.g., x = y, a AND b, x + y)

§

FunctionCall(DynIden, Vec<SimpleExpr>)

A function call (e.g., MAX(x), LOWER(name))

§

SubQuery(Option<SubQueryOper>, Box<SelectStatement>)

A subquery (e.g., (SELECT ...))

The optional operator indicates how the subquery is used:

  • None: Standalone subquery (e.g., in FROM clause or SELECT list)
  • Some(SubQueryOper): Subquery with operator (e.g., IN, EXISTS, ALL)
§

Tuple(Vec<SimpleExpr>)

A tuple of expressions (e.g., (1, 2, 3))

§

Custom(String)

A custom SQL expression (e.g., NOW())

§Security Warning

This variant embeds raw SQL directly into the query. Only use with trusted input or static SQL strings. For dynamic values, use CustomWithExpr instead.

§

CustomWithExpr(String, Vec<SimpleExpr>)

A custom SQL expression with parameter placeholders

§

Constant(Keyword)

A constant (database-specific constant like TRUE, FALSE, NULL)

§

Asterisk

An asterisk (*)

§

Case(Box<CaseStatement>)

A CASE WHEN expression

§

AsEnum(DynIden, Box<SimpleExpr>)

An AS expression with alias (e.g., expr AS alias)

§

Cast(Box<SimpleExpr>, DynIden)

A CAST expression (e.g., CAST(x AS INTEGER))

§

Window

A window function with inline window specification

Represents expressions like:

ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC)

Fields

§func: Box<SimpleExpr>

The function expression

§window: WindowStatement

The window specification

§

WindowNamed

A window function with named window reference

Represents expressions like:

ROW_NUMBER() OVER window_name

where window_name is defined in the WINDOW clause.

Fields

§func: Box<SimpleExpr>

The function expression

§name: DynIden

The window name

Implementations§

Source§

impl SimpleExpr

Source

pub fn binary(self, op: BinOper, right: SimpleExpr) -> Self

Create a binary operation expression.

Trait Implementations§

Source§

impl Clone for SimpleExpr

Source§

fn clone(&self) -> SimpleExpr

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 SimpleExpr

Source§

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

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

impl ExprTrait for SimpleExpr

Source§

fn into_simple_expr(self) -> SimpleExpr

Build the final SimpleExpr.
Source§

fn eq<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Equal (=). Read more
Source§

fn ne<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Not equal (<>).
Source§

fn lt<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Less than (<).
Source§

fn lte<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Less than or equal (<=).
Source§

fn gt<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Greater than (>).
Source§

fn gte<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Greater than or equal (>=).
Source§

fn is_null(self) -> SimpleExpr

IS NULL.
Source§

fn is_not_null(self) -> SimpleExpr

IS NOT NULL.
Source§

fn between<A, B>(self, a: A, b: B) -> SimpleExpr
where A: Into<SimpleExpr>, B: Into<SimpleExpr>,

BETWEEN. Read more
Source§

fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
where A: Into<SimpleExpr>, B: Into<SimpleExpr>,

NOT BETWEEN.
Source§

fn is_in<I, V>(self, values: I) -> SimpleExpr
where I: IntoIterator<Item = V>, V: Into<SimpleExpr>,

Source§

fn is_not_in<I, V>(self, values: I) -> SimpleExpr
where I: IntoIterator<Item = V>, V: Into<SimpleExpr>,

NOT IN.
Source§

fn like<V>(self, pattern: V) -> SimpleExpr
where V: Into<SimpleExpr>,

LIKE. Read more
Source§

fn not_like<V>(self, pattern: V) -> SimpleExpr
where V: Into<SimpleExpr>,

NOT LIKE.
Source§

fn ilike<V>(self, pattern: V) -> SimpleExpr
where V: Into<SimpleExpr>,

ILIKE (case-insensitive LIKE, PostgreSQL).
Source§

fn not_ilike<V>(self, pattern: V) -> SimpleExpr
where V: Into<SimpleExpr>,

NOT ILIKE (PostgreSQL).
Source§

fn starts_with<S>(self, prefix: S) -> SimpleExpr
where S: Into<String>,

Helper for LIKE with prefix wildcard.
Source§

fn ends_with<S>(self, suffix: S) -> SimpleExpr
where S: Into<String>,

Helper for LIKE with suffix wildcard.
Source§

fn contains<S>(self, substring: S) -> SimpleExpr
where S: Into<String>,

Helper for LIKE with both wildcards.
Source§

fn and<E>(self, other: E) -> SimpleExpr
where E: Into<SimpleExpr>,

AND.
Source§

fn or<E>(self, other: E) -> SimpleExpr
where E: Into<SimpleExpr>,

OR.
Source§

fn not(self) -> SimpleExpr

NOT (unary).
Source§

fn add<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Addition (+).
Source§

fn sub<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Subtraction (-).
Source§

fn mul<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Multiplication (*).
Source§

fn div<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Division (/).
Source§

fn modulo<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Modulo (%).
Source§

fn bit_and<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Bitwise AND (&).
Source§

fn bit_or<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Bitwise OR (|).
Source§

fn left_shift<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Left shift (<<).
Source§

fn right_shift<V>(self, v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Right shift (>>).
Source§

fn cast_as<T>(self, type_name: T) -> SimpleExpr
where T: IntoIden,

CAST expression. Read more
Source§

fn as_enum<T>(self, type_name: T) -> SimpleExpr
where T: IntoIden,

AS ENUM expression (PostgreSQL).
Source§

impl From<&str> for SimpleExpr

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<CaseStatement> for SimpleExpr

Source§

fn from(case: CaseStatement) -> Self

Converts to this type from the input type.
Source§

impl From<ColumnRef> for SimpleExpr

Source§

fn from(c: ColumnRef) -> Self

Converts to this type from the input type.
Source§

impl From<Expr> for SimpleExpr

Source§

fn from(e: Expr) -> Self

Converts to this type from the input type.
Source§

impl From<Keyword> for SimpleExpr

Source§

fn from(k: Keyword) -> Self

Converts to this type from the input type.
Source§

impl From<SimpleExpr> for Expr

Source§

fn from(e: SimpleExpr) -> Self

Converts to this type from the input type.
Source§

impl From<String> for SimpleExpr

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for SimpleExpr

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for SimpleExpr

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for SimpleExpr

Source§

fn from(f: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for SimpleExpr

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for SimpleExpr

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for SimpleExpr

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl IntoCondition for SimpleExpr

Source§

fn into_condition_expression(self) -> ConditionExpression

Convert into a ConditionExpression.
Source§

fn into_condition(self) -> Condition
where Self: Sized,

Convert into a Condition (wrapping if necessary).

Auto Trait Implementations§

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.