Enum SimpleExpr

Source
pub enum SimpleExpr {
Show 14 variants Column(ColumnRef), Tuple(Vec<SimpleExpr>), Unary(UnOper, Box<SimpleExpr>), FunctionCall(Function, Vec<SimpleExpr>), Binary(Box<SimpleExpr>, BinOper, Box<SimpleExpr>), SubQuery(Option<SubQueryOper>, Box<SubQueryStatement>), Value(Value), Values(Vec<Value>), Custom(String), CustomWithValues(String, Vec<Value>), Keyword(Keyword), AsEnum(Arc<dyn Iden>, Box<SimpleExpr>), Case(Box<CaseStatement>), Constant(Value),
}
Expand description

Represents a Simple Expression in SQL.

SimpleExpr is a node in the expression tree and can represent identifiers, function calls, various operators and sub-queries.

Variants§

§

Column(ColumnRef)

§

Tuple(Vec<SimpleExpr>)

§

Unary(UnOper, Box<SimpleExpr>)

§

FunctionCall(Function, Vec<SimpleExpr>)

§

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

§

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

§

Value(Value)

§

Values(Vec<Value>)

§

Custom(String)

§

CustomWithValues(String, Vec<Value>)

§

Keyword(Keyword)

§

AsEnum(Arc<dyn Iden>, Box<SimpleExpr>)

§

Case(Box<CaseStatement>)

§

Constant(Value)

Implementations§

Source§

impl SimpleExpr

Source

pub fn and(self, right: SimpleExpr) -> SimpleExpr

Express a logical AND operation.

§Examples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .cond_where(any![
        Expr::col(Char::SizeW).eq(1).and(Expr::col(Char::SizeH).eq(2)),
        Expr::col(Char::SizeW).eq(3).and(Expr::col(Char::SizeH).eq(4)),
    ])
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE ((`size_w` = 1) AND (`size_h` = 2)) OR ((`size_w` = 3) AND (`size_h` = 4))"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE (("size_w" = 1) AND ("size_h" = 2)) OR (("size_w" = 3) AND ("size_h" = 4))"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE (("size_w" = 1) AND ("size_h" = 2)) OR (("size_w" = 3) AND ("size_h" = 4))"#
);
Source

pub fn or(self, right: SimpleExpr) -> SimpleExpr

Express a logical OR operation.

§Examples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::col(Char::SizeW).eq(1).or(Expr::col(Char::SizeH).eq(2)))
    .and_where(Expr::col(Char::SizeW).eq(3).or(Expr::col(Char::SizeH).eq(4)))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE ((`size_w` = 1) OR (`size_h` = 2)) AND ((`size_w` = 3) OR (`size_h` = 4))"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE (("size_w" = 1) OR ("size_h" = 2)) AND (("size_w" = 3) OR ("size_h" = 4))"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE (("size_w" = 1) OR ("size_h" = 2)) AND (("size_w" = 3) OR ("size_h" = 4))"#
);
Source

pub fn equals<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Compares with another SimpleExpr for equality.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .column(Char::Character)
    .from(Char::Table)
    .and_where(
        Expr::col(Char::SizeW)
            .mul(2)
            .equals(Expr::col(Char::SizeH).mul(3)),
    )
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character` FROM `character` WHERE `size_w` * 2 = `size_h` * 3"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE "size_w" * 2 = "size_h" * 3"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE "size_w" * 2 = "size_h" * 3"#
);
Source

pub fn not_equals<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Compares with another SimpleExpr for inequality.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .column(Char::Character)
    .from(Char::Table)
    .and_where(
        Expr::col(Char::SizeW)
            .mul(2)
            .not_equals(Expr::col(Char::SizeH)),
    )
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character` FROM `character` WHERE `size_w` * 2 <> `size_h`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE "size_w" * 2 <> "size_h""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE "size_w" * 2 <> "size_h""#
);
Source

pub fn add<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Perform addition with another SimpleExpr.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(
        Expr::col(Char::SizeW)
            .max()
            .add(Expr::col(Char::SizeH).max()),
    )
    .from(Char::Table)
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MAX(`size_w`) + MAX(`size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MAX("size_w") + MAX("size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MAX("size_w") + MAX("size_h") FROM "character""#
);
Source

pub fn sub<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Perform subtraction with another SimpleExpr.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(
        Expr::col(Char::SizeW)
            .max()
            .sub(Expr::col(Char::SizeW).min()),
    )
    .from(Char::Table)
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MAX(`size_w`) - MIN(`size_w`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MAX("size_w") - MIN("size_w") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MAX("size_w") - MIN("size_w") FROM "character""#
);
Source

pub fn concatenate<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Express an postgres concatenate (||) expression.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Font::Name, Font::Variant, Font::Language])
    .from(Font::Table)
    .and_where(
        Expr::val("a")
            .concatenate(Expr::val("b"))
            .concat(Expr::val("c"))
            .concat(Expr::val("d")),
    )
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a' || 'b' || 'c' || 'd'"#
);
Source

pub fn concat<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Source

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

Express a CAST AS expression.

§Examples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::value("1").cast_as(Alias::new("integer")))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT CAST('1' AS integer)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CAST('1' AS integer)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CAST('1' AS integer)"#
);

Trait Implementations§

Source§

impl Clone for SimpleExpr

Source§

fn clone(&self) -> SimpleExpr

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

const 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<(), Error>

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

impl From<Expr> for SimpleExpr

Source§

fn from(src: Expr) -> SimpleExpr

Convert into SimpleExpr. Will panic if this Expr is missing an operand

Source§

impl From<SimpleExpr> for ConditionExpression

Source§

fn from(condition: SimpleExpr) -> ConditionExpression

Converts to this type from the input type.
Source§

impl<T> From<T> for SimpleExpr
where T: Into<Value>,

Source§

fn from(v: T) -> SimpleExpr

Converts to this type from the input type.
Source§

impl Into<SelectExpr> for SimpleExpr

Source§

fn into(self) -> SelectExpr

Converts this type into the (usually inferred) input type.
Source§

impl Into<SimpleExpr> for CaseStatement

Source§

fn into(self) -> SimpleExpr

Converts this type into the (usually inferred) input type.
Source§

impl IntoCondition for SimpleExpr

Source§

impl IntoSimpleExpr for SimpleExpr

Source§

fn into_simple_expr(self) -> SimpleExpr

Method to perform the conversion

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> 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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,