sea_orm::entity::prelude

Struct Expr

Source
pub struct Expr { /* private fields */ }
Expand description

Helper to build a SimpleExpr.

Implementationsยง

Sourceยง

impl Expr

Source

pub fn asterisk() -> Expr

๐Ÿ‘ŽDeprecated since 0.29.0: Please use the [Asterisk]
Source

pub fn col<T>(n: T) -> Expr
where T: IntoColumnRef,

Express the target column without table prefix.

ยง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))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` = 1"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" = 1"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" = 1"#
);
use sea_query::{tests_cfg::*, *};

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

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

pub fn tuple<I>(n: I) -> Expr
where I: IntoIterator<Item = SimpleExpr>,

Wraps tuple of SimpleExpr, can be used for tuple comparison

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(
        Expr::tuple([Expr::col(Char::SizeW).into(), Expr::value(100)])
            .lt(Expr::tuple([Expr::value(500), Expr::value(100)])))
    .to_owned();

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

pub fn table_asterisk<T>(t: T) -> Expr
where T: IntoIden,

๐Ÿ‘ŽDeprecated since 0.29.0: Please use the [Asterisk]
Source

pub fn val<V>(v: V) -> Expr
where V: Into<Value>,

Express a Value, returning a Expr.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::val(1).into())
    .and_where(Expr::val(2.5).into())
    .and_where(Expr::val("3").into())
    .to_owned();

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

pub fn expr<T>(expr: T) -> Expr
where T: Into<SimpleExpr>,

Wrap a SimpleExpr and perform some operation on it.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::expr(Expr::col(Char::SizeW).if_null(0)).gt(2))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE IFNULL(`size_w`, 0) > 2"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE COALESCE("size_w", 0) > 2"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE IFNULL("size_w", 0) > 2"#
);
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .column(Char::Character)
    .from(Char::Table)
    .and_where(Expr::expr(Func::lower(Expr::col(Char::Character))).is_in(["a", "b"]))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character` FROM `character` WHERE LOWER(`character`) IN ('a', 'b')"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE LOWER("character") IN ('a', 'b')"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character" FROM "character" WHERE LOWER("character") IN ('a', 'b')"#
);
Source

pub fn value<V>(v: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Express a Value, returning a SimpleExpr.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::value(1))
    .and_where(Expr::value(2.5))
    .and_where(Expr::value("3"))
    .to_owned();

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

pub fn cust<T>(s: T) -> SimpleExpr
where T: Into<String>,

Express any custom expression in &str.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::cust("1 = 1"))
    .to_owned();

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

pub fn cust_with_values<T, V, I>(s: T, v: I) -> SimpleExpr
where T: Into<String>, V: Into<Value>, I: IntoIterator<Item = V>,

Express any custom expression with Value. Use this if your expression needs variables.

ยง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::Id).eq(1))
    .and_where(Expr::cust_with_values("6 = ? * ?", [2, 3]))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `id` = 1 AND (6 = 2 * 3)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "id" = 1 AND (6 = 2 * 3)"#
);
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::col(Char::Id).eq(1))
    .and_where(Expr::cust_with_values("6 = $2 * $1", [3, 2]))
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "id" = 1 AND (6 = 2 * 3)"#
);
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::cust_with_values("6 = ? * ?", [2, 3]))
    .to_owned();

assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT 6 = 2 * 3"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT 6 = 2 * 3"#);

Postgres only: use $$ to escape $

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

let query = Query::select()
    .expr(Expr::cust_with_values("$1 $$ $2", ["a", "b"]))
    .to_owned();

assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT 'a' $ 'b'"#);
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::cust_with_values("data @? ($1::JSONPATH)", ["hello"]))
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT data @? ('hello'::JSONPATH)"#
);
Source

pub fn cust_with_expr<T, E>(s: T, expr: E) -> SimpleExpr
where T: Into<String>, E: Into<SimpleExpr>,

Express any custom expression with SimpleExpr. Use this if your expression needs other expression.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::val(1).add(2))
    .expr(Expr::cust_with_expr("data @? ($1::JSONPATH)", "hello"))
    .to_owned();
let (sql, values) = query.build(PostgresQueryBuilder);

assert_eq!(sql, r#"SELECT $1 + $2, data @? ($3::JSONPATH)"#);
assert_eq!(
    values,
    Values(vec![1i32.into(), 2i32.into(), "hello".into()])
);
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::cust_with_expr(
        "json_agg(DISTINCT $1)",
        Expr::col(Char::Character),
    ))
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT json_agg(DISTINCT "character")"#
);
Source

pub fn cust_with_exprs<T, I>(s: T, v: I) -> SimpleExpr
where T: Into<String>, I: IntoIterator<Item = SimpleExpr>,

Express any custom expression with SimpleExpr. Use this if your expression needs other expressions.

Source

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

Express an equal (=) expression.

This is equivalent to a newer ExprTrait::eq and may require more some wrapping beforehand.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::val("What!").eq("Nothing"))
    .and_where(Expr::col(Char::Id).eq(1))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 'What!' = 'Nothing' AND `id` = 1"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'What!' = 'Nothing' AND "id" = 1"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'What!' = 'Nothing' AND "id" = 1"#
);
Source

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

Express a not equal (<>) expression.

This is equivalent to a newer ExprTrait::ne and may require more some wrapping beforehand.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::val("Morning").ne("Good"))
    .and_where(Expr::col(Char::Id).ne(1))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 'Morning' <> 'Good' AND `id` <> 1"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'Morning' <> 'Good' AND "id" <> 1"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'Morning' <> 'Good' AND "id" <> 1"#
);
Source

pub fn equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef,

Express a equal expression between two table columns, you will mainly use this to relate identical value between two table columns.

This is equivalent to a newer ExprTrait::equals and may require more some wrapping beforehand.

ยง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::Table, Char::FontId)).equals((Font::Table, Font::Id)))
    .to_owned();

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

pub fn not_equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef,

Express a not equal expression between two table columns, you will mainly use this to relate identical value between two table columns.

This is equivalent to a newer ExprTrait::not_equals and may require more some wrapping beforehand.

ยง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::Table, Char::FontId)).not_equals((Font::Table, Font::Id)))
    .to_owned();

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

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

Express a greater than (>) expression.

This is equivalent to a newer ExprTrait::gt and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).gt(2))
    .to_owned();

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

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

Express a greater than or equal (>=) expression.

This is equivalent to a newer ExprTrait::gte and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).gte(2))
    .to_owned();

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

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

Express a less than (<) expression.

This is equivalent to a newer ExprTrait::lt and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).lt(2))
    .to_owned();

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

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

Express a less than or equal (<=) expression.

This is equivalent to a newer ExprTrait::lte and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).lte(2))
    .to_owned();

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

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

Express an arithmetic addition operation.

This is equivalent to a newer ExprTrait::add and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express an arithmetic subtraction operation.

This is equivalent to a newer ExprTrait::sub and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express an arithmetic multiplication operation.

This is equivalent to a newer ExprTrait::mul and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express an arithmetic division operation.

This is equivalent to a newer ExprTrait::div and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express an arithmetic modulo operation.

This is equivalent to a newer ExprTrait::modulo and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express a bitwise left shift.

This is equivalent to a newer ExprTrait::left_shift and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express a bitwise right shift.

This is equivalent to a newer ExprTrait::right_shift and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

pub fn between<V>(self, a: V, b: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Express a BETWEEN expression.

This is equivalent to a newer ExprTrait::between and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).between(1, 10))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` BETWEEN 1 AND 10"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" BETWEEN 1 AND 10"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" BETWEEN 1 AND 10"#
);
Source

pub fn not_between<V>(self, a: V, b: V) -> SimpleExpr
where V: Into<SimpleExpr>,

Express a NOT BETWEEN expression.

This is equivalent to a newer ExprTrait::not_between and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).not_between(1, 10))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` NOT BETWEEN 1 AND 10"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" NOT BETWEEN 1 AND 10"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" NOT BETWEEN 1 AND 10"#
);
Source

pub fn like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a LIKE expression.

This is equivalent to a newer ExprTrait::like and may require more some wrapping beforehand.

ยง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::Table, Char::Character)).like("Ours'%"))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`character` LIKE 'Ours\'%'"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE E'Ours\'%'"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE 'Ours''%'"#
);

Like with ESCAPE

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

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::col((Char::Table, Char::Character)).like(LikeExpr::new(r"|_Our|_").escape('|')))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`character` LIKE '|_Our|_' ESCAPE '|'"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE '|_Our|_' ESCAPE '|'"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE '|_Our|_' ESCAPE '|'"#
);
Source

pub fn not_like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a NOT LIKE expression.

This is equivalent to a newer ExprTrait::not_like and may require more some wrapping beforehand.

Source

pub fn is_null(self) -> SimpleExpr

Express a IS NULL expression.

This is equivalent to a newer ExprTrait::is_null and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).is_null())
    .to_owned();

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

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

Express a IS expression.

This is equivalent to a newer ExprTrait::is and may require more some wrapping beforehand.

ยง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::Table, Char::Ascii)).is(true))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`ascii` IS TRUE"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS TRUE"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS TRUE"#
);
Source

pub fn is_not_null(self) -> SimpleExpr

Express a IS NOT NULL expression.

This is equivalent to a newer ExprTrait::is_not_null and may require more some wrapping beforehand.

ยง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::Table, Char::SizeW)).is_not_null())
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` IS NOT NULL"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NOT NULL"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NOT NULL"#
);
Source

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

Express a IS NOT expression.

This is equivalent to a newer ExprTrait::is_not and may require more some wrapping beforehand.

ยง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::Table, Char::Ascii)).is_not(true))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`ascii` IS NOT TRUE"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS NOT TRUE"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS NOT TRUE"#
);
Source

pub fn binary<O, T>(self, op: O, right: T) -> SimpleExpr
where O: Into<BinOper>, T: Into<SimpleExpr>,

Create any binary operation

This is equivalent to a newer ExprTrait::binary and may require more some wrapping beforehand.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .cond_where(all![
        Expr::col(Char::SizeW).binary(BinOper::SmallerThan, 10),
        Expr::col(Char::SizeW).binary(BinOper::GreaterThan, Expr::col(Char::SizeH))
    ])
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` < 10 AND `size_w` > `size_h`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" < 10 AND "size_w" > "size_h""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" < 10 AND "size_w" > "size_h""#
);
Source

pub fn not(self) -> SimpleExpr

Negates an expression with NOT.

This is equivalent to a newer ExprTrait::not and may require more some wrapping beforehand.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::SizeW, Char::SizeH])
    .from(Char::Table)
    .and_where(Expr::expr(Expr::col((Char::Table, Char::SizeW)).is_null()).not())
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE NOT `character`.`size_w` IS NULL"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE NOT "character"."size_w" IS NULL"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE NOT "character"."size_w" IS NULL"#
);
Source

pub fn max(self) -> SimpleExpr

Express a MAX function.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

pub fn min(self) -> SimpleExpr

Express a MIN function.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

pub fn sum(self) -> SimpleExpr

Express a SUM function.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

pub fn count(self) -> SimpleExpr

Express a COUNT function.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

pub fn count_distinct(self) -> SimpleExpr

Express a COUNT function with the DISTINCT modifier.

ยงExamples
use sea_query::{tests_cfg::*, *};

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

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

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

Express a IF NULL function.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::col((Char::Table, Char::SizeW)).if_null(0))
    .from(Char::Table)
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT IFNULL(`character`.`size_w`, 0) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COALESCE("character"."size_w", 0) FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT IFNULL("character"."size_w", 0) FROM "character""#
);
Source

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

Express a IN expression.

This is equivalent to a newer ExprTrait::is_in and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Id])
    .from(Char::Table)
    .and_where(Expr::col((Char::Table, Char::SizeW)).is_in([1, 2, 3]))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE `character`.`size_w` IN (1, 2, 3)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "character"."size_w" IN (1, 2, 3)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "character"."size_w" IN (1, 2, 3)"#
);

Empty value list

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

let query = Query::select()
    .columns([Char::Id])
    .from(Char::Table)
    .and_where(Expr::col((Char::Table, Char::SizeW)).is_in(Vec::<u8>::new()))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE 1 = 2"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE 1 = 2"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE 1 = 2"#
);
Source

pub fn in_tuples<V, I>(self, v: I) -> SimpleExpr
where V: IntoValueTuple, I: IntoIterator<Item = V>,

Express a IN sub expression.

This is equivalent to a newer ExprTrait::in_tuples and may require more some wrapping beforehand.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .columns([Char::Character, Char::FontId])
    .from(Char::Table)
    .and_where(
        Expr::tuple([
            Expr::col(Char::Character).into(),
            Expr::col(Char::FontId).into(),
        ])
        .in_tuples([(1, String::from("1")), (2, String::from("2"))])
    )
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `character`, `font_id` FROM `character` WHERE (`character`, `font_id`) IN ((1, '1'), (2, '2'))"#
);

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "character", "font_id" FROM "character" WHERE ("character", "font_id") IN ((1, '1'), (2, '2'))"#
);

assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "character", "font_id" FROM "character" WHERE ("character", "font_id") IN ((1, '1'), (2, '2'))"#
);
Source

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

Express a NOT IN expression.

This is equivalent to a newer ExprTrait::is_not_in and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .columns([Char::Id])
    .from(Char::Table)
    .and_where(Expr::col((Char::Table, Char::SizeW)).is_not_in([1, 2, 3]))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE `character`.`size_w` NOT IN (1, 2, 3)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "character"."size_w" NOT IN (1, 2, 3)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "character"."size_w" NOT IN (1, 2, 3)"#
);

Empty value list

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

let query = Query::select()
    .columns([Char::Id])
    .from(Char::Table)
    .and_where(Expr::col((Char::Table, Char::SizeW)).is_not_in(Vec::<u8>::new()))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE 1 = 1"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE 1 = 1"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE 1 = 1"#
);
Source

pub fn in_subquery(self, sel: SelectStatement) -> SimpleExpr

Express a IN sub-query expression.

This is equivalent to a newer ExprTrait::in_subquery and may require more some wrapping beforehand.

ยง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).in_subquery(
        Query::select()
            .expr(Expr::cust("3 + 2 * 2"))
            .take()
    ))
    .to_owned();

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

pub fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr

Express a NOT IN sub-query expression.

This is equivalent to a newer ExprTrait::not_in_subquery and may require more some wrapping beforehand.

ยง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).not_in_subquery(
        Query::select()
            .expr(Expr::cust("3 + 2 * 2"))
            .take()
    ))
    .to_owned();

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

pub fn exists(sel: SelectStatement) -> SimpleExpr

Express a EXISTS sub-query expression.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .expr_as(Expr::exists(Query::select().column(Char::Id).from(Char::Table).take()), Alias::new("character_exists"))
    .expr_as(Expr::exists(Query::select().column(Glyph::Id).from(Glyph::Table).take()), Alias::new("glyph_exists"))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT EXISTS(SELECT `id` FROM `character`) AS `character_exists`, EXISTS(SELECT `id` FROM `glyph`) AS `glyph_exists`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT EXISTS(SELECT "id" FROM "character") AS "character_exists", EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT EXISTS(SELECT "id" FROM "character") AS "character_exists", EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
);
Source

pub fn any(sel: SelectStatement) -> SimpleExpr

Express a ANY sub-query expression.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .column(Char::Id)
    .from(Char::Table)
    .and_where(Expr::col(Char::Id).eq(Expr::any(
        Query::select().column(Char::Id).from(Char::Table).take(),
    )))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE `id` = ANY(SELECT `id` FROM `character`)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "id" = ANY(SELECT "id" FROM "character")"#
);
Source

pub fn some(sel: SelectStatement) -> SimpleExpr

Express a SOME sub-query expression.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .column(Char::Id)
    .from(Char::Table)
    .and_where(Expr::col(Char::Id).ne(Expr::some(
        Query::select().column(Char::Id).from(Char::Table).take(),
    )))
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `id` FROM `character` WHERE `id` <> SOME(SELECT `id` FROM `character`)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "character" WHERE "id" <> SOME(SELECT "id" FROM "character")"#
);
Source

pub fn all(sel: SelectStatement) -> SimpleExpr

Express a ALL sub-query expression.

Source

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

Express a AS enum expression.

This is equivalent to a newer ExprTrait::as_enum and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::col(Char::FontSize).as_enum(Alias::new("text")))
    .from(Char::Table)
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT `font_size` FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CAST("font_size" AS text) FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "font_size" FROM "character""#
);

let query = Query::insert()
    .into_table(Char::Table)
    .columns([Char::FontSize])
    .values_panic([Expr::val("large").as_enum(Alias::new("FontSizeEnum"))])
    .to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"INSERT INTO `character` (`font_size`) VALUES ('large')"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"INSERT INTO "character" ("font_size") VALUES (CAST('large' AS FontSizeEnum))"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"INSERT INTO "character" ("font_size") VALUES ('large')"#
);
Source

pub fn case<C, T>(cond: C, then: T) -> CaseStatement

Adds new CASE WHEN to existing case statement.

ยงExamples
use sea_query::{*, tests_cfg::*};

let query = Query::select()
    .expr_as(
        Expr::case(
                Expr::col((Glyph::Table, Glyph::Aspect)).is_in([2, 4]),
                true
             )
            .finally(false),
         Alias::new("is_even")
    )
    .from(Glyph::Table)
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT (CASE WHEN ("glyph"."aspect" IN (2, 4)) THEN TRUE ELSE FALSE END) AS "is_even" FROM "glyph""#
);
Source

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

Express a CAST AS expression.

This is equivalent to a newer ExprTrait::cast_as and may require more some wrapping beforehand.

ยงExamples
use sea_query::{tests_cfg::*, *};

let query = Query::select()
    .expr(Expr::val("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)"#
);
Source

pub fn current_date() -> Expr

Keyword CURRENT_DATE.

ยงExamples
use sea_query::*;

let query = Query::select().expr(Expr::current_date()).to_owned();

assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT CURRENT_DATE"#);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CURRENT_DATE"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CURRENT_DATE"#
);
Source

pub fn current_time() -> Expr

Keyword CURRENT_TIMESTAMP.

ยงExamples
use sea_query::*;

let query = Query::select().expr(Expr::current_time()).to_owned();

assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT CURRENT_TIME"#);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CURRENT_TIME"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CURRENT_TIME"#
);
Source

pub fn current_timestamp() -> Expr

Keyword CURRENT_TIMESTAMP.

ยงExamples
use sea_query::{Expr, MysqlQueryBuilder, PostgresQueryBuilder, Query, SqliteQueryBuilder};

let query = Query::select().expr(Expr::current_timestamp()).to_owned();

assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT CURRENT_TIMESTAMP"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CURRENT_TIMESTAMP"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CURRENT_TIMESTAMP"#
);
Source

pub fn custom_keyword<T>(i: T) -> Expr
where T: IntoIden,

Custom keyword.

ยงExamples
use sea_query::*;

let query = Query::select()
    .expr(Expr::custom_keyword(Alias::new("test")))
    .to_owned();

assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT test"#);

Trait Implementationsยง

Sourceยง

impl Clone for Expr

Sourceยง

fn clone(&self) -> Expr

Returns a copy 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<(), Error>

Formats the value using the given formatter. Read more
Sourceยง

impl IntoSimpleExpr for Expr

Sourceยง

fn into_simple_expr(self) -> SimpleExpr

Method to perform the conversion
Sourceยง

impl PgExpr for Expr

Sourceยง

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

Express an postgres concatenate (||) expression. Read more
Sourceยง

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

Sourceยง

fn matches<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Express an postgres fulltext search matches (@@) expression. Read more
Sourceยง

fn contains<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Express an postgres fulltext search contains (@>) expression. Read more
Sourceยง

fn contained<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr>,

Express an postgres fulltext search contained (<@) expression. Read more
Sourceยง

fn ilike<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a ILIKE expression. Read more
Sourceยง

fn not_ilike<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a NOT ILIKE expression
Sourceยง

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

Express a postgres retrieves JSON field as JSON value (->). Read more
Sourceยง

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

Express a postgres retrieves JSON field and casts it to an appropriate SQL type (->>). Read more
Sourceยง

impl SqliteExpr for Expr

Sourceยง

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

Express an sqlite GLOB operator. Read more
Sourceยง

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

Express an sqlite MATCH operator. Read more
Sourceยง

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

Express an sqlite retrieves JSON field as JSON value (->). Read more
Sourceยง

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

Express an sqlite retrieves JSON field and casts it to an appropriate SQL type (->>). Read more

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, dst: *mut T)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Sourceยง

impl<T> ExprTrait for T
where T: Into<SimpleExpr>,

Sourceยง

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

Express a AS enum expression. Read more
Sourceยง

fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
where O: Into<BinOper>, R: Into<SimpleExpr>,

Create any binary operation Read more
Sourceยง

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

Express a CAST AS expression. Read more
Sourceยง

fn unary(self, op: UnOper) -> SimpleExpr

Apply any unary operator to the expression. Read more
Sourceยง

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

Express an arithmetic addition operation. Read more
Sourceยง

fn and<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Sourceยง

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

Express a BETWEEN expression. Read more
Sourceยง

fn div<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express an arithmetic division operation. Read more
Sourceยง

fn eq<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express an equal (=) expression. Read more
Sourceยง

fn equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef,

Express a equal expression between two table columns, you will mainly use this to relate identical value between two table columns. Read more
Sourceยง

fn gt<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a greater than (>) expression. Read more
Sourceยง

fn gte<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a greater than or equal (>=) expression. Read more
Sourceยง

fn in_subquery(self, sel: SelectStatement) -> SimpleExpr

Express a IN sub-query expression. Read more
Sourceยง

fn in_tuples<V, I>(self, v: I) -> SimpleExpr
where V: IntoValueTuple, I: IntoIterator<Item = V>,

Express a IN sub expression. Read more
Sourceยง

fn is<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a IS expression. Read more
Sourceยง

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

Express a IN expression. Read more
Sourceยง

fn is_not<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a IS NOT expression. Read more
Sourceยง

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

Express a NOT IN expression. Read more
Sourceยง

fn is_not_null(self) -> SimpleExpr

Express a IS NOT NULL expression. Read more
Sourceยง

fn is_null(self) -> SimpleExpr

Express a IS NULL expression. Read more
Sourceยง

fn left_shift<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a bitwise left shift. Read more
Sourceยง

fn like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a LIKE expression. Read more
Sourceยง

fn lt<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a less than (<) expression. Read more
Sourceยง

fn lte<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a less than or equal (<=) expression. Read more
Sourceยง

fn modulo<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express an arithmetic modulo operation. Read more
Sourceยง

fn mul<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express an arithmetic multiplication operation. Read more
Sourceยง

fn ne<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a not equal (<>) expression. Read more
Sourceยง

fn not(self) -> SimpleExpr

Negates an expression with NOT. Read more
Sourceยง

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

Express a NOT BETWEEN expression. Read more
Sourceยง

fn not_equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef,

Express a not equal expression between two table columns, you will mainly use this to relate identical value between two table columns. Read more
Sourceยง

fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr

Express a NOT IN sub-query expression. Read more
Sourceยง

fn not_like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr,

Express a NOT LIKE expression. Read more
Sourceยง

fn or<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a logical OR operation. Read more
Sourceยง

fn right_shift<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr>,

Express a bitwise right shift. Read more
Sourceยง

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

Express an arithmetic subtraction operation. 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