Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 31 variants Column { table: Option<String>, name: String, }, Literal(Value), Placeholder(usize), Binary { left: Box<Expr>, op: BinaryOp, right: Box<Expr>, }, Unary { op: UnaryOp, expr: Box<Expr>, }, Function { name: String, args: Vec<Expr>, }, Case { when_clauses: Vec<(Expr, Expr)>, else_clause: Option<Box<Expr>>, }, In { expr: Box<Expr>, values: Vec<Expr>, negated: bool, }, Between { expr: Box<Expr>, low: Box<Expr>, high: Box<Expr>, negated: bool, }, IsNull { expr: Box<Expr>, negated: bool, }, IsDistinctFrom { left: Box<Expr>, right: Box<Expr>, negated: bool, }, Cast { expr: Box<Expr>, type_name: String, }, Like { expr: Box<Expr>, pattern: String, negated: bool, case_insensitive: bool, }, Subquery(String), Exists { subquery: String, params: Vec<Value>, negated: bool, }, ExistsQuery { subquery: Box<SelectQuery>, negated: bool, }, Raw(String), Paren(Box<Expr>), CountStar, Window { function: Box<Expr>, partition_by: Vec<Expr>, order_by: Vec<OrderBy>, frame: Option<WindowFrame>, }, JsonExtract { expr: Box<Expr>, path: JsonPath, }, JsonExtractText { expr: Box<Expr>, path: JsonPath, }, JsonExtractPath { expr: Box<Expr>, path: Vec<String>, }, JsonExtractPathText { expr: Box<Expr>, path: Vec<String>, }, JsonContains { expr: Box<Expr>, other: Box<Expr>, }, JsonContainedBy { expr: Box<Expr>, other: Box<Expr>, }, JsonHasKey { expr: Box<Expr>, key: String, }, JsonHasAnyKey { expr: Box<Expr>, keys: Vec<String>, }, JsonHasAllKeys { expr: Box<Expr>, keys: Vec<String>, }, JsonArrayLength { expr: Box<Expr>, }, JsonTypeof { expr: Box<Expr>, },
}
Expand description

A SQL expression that can be used in WHERE, HAVING, etc.

Variants§

§

Column

Column reference with optional table qualifier

Fields

§table: Option<String>

Optional table name or alias

§name: String

Column name

§

Literal(Value)

Literal value

§

Placeholder(usize)

Explicit placeholder for bound parameters

§

Binary

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

Fields

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

Unary

Unary operation (e.g., NOT a, -a)

Fields

§expr: Box<Expr>
§

Function

Function call (e.g., COUNT(*), UPPER(name))

Fields

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

Case

CASE WHEN … THEN … ELSE … END

Fields

§when_clauses: Vec<(Expr, Expr)>

List of (condition, result) pairs

§else_clause: Option<Box<Expr>>

Optional ELSE clause

§

In

IN expression

Fields

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

Between

BETWEEN expression

Fields

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

IsNull

IS NULL / IS NOT NULL

Fields

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

IsDistinctFrom

IS DISTINCT FROM / IS NOT DISTINCT FROM (NULL-safe comparison)

Fields

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

Cast

CAST(expr AS type)

Fields

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

Like

LIKE / NOT LIKE pattern

Fields

§expr: Box<Expr>
§pattern: String
§negated: bool
§case_insensitive: bool
§

Subquery(String)

Subquery (stores the SQL string)

§

Exists

EXISTS (subquery) / NOT EXISTS (subquery)

Used for subquery existence checks in WHERE clauses.

Fields

§subquery: String

The subquery SQL string

§params: Vec<Value>

Parameters for the subquery

§negated: bool

Whether this is NOT EXISTS

§

ExistsQuery

EXISTS (subquery) / NOT EXISTS (subquery) built from a query builder.

Used to defer SQL generation until a specific dialect is known.

Fields

§subquery: Box<SelectQuery>

The subquery builder

§negated: bool

Whether this is NOT EXISTS

§

Raw(String)

Raw SQL fragment (escape hatch)

§

Paren(Box<Expr>)

Parenthesized expression

§

CountStar

Special aggregate: COUNT(*)

§

Window

Window function with OVER clause

Fields

§function: Box<Expr>

The function expression (aggregate or window function)

§partition_by: Vec<Expr>

PARTITION BY expressions

§order_by: Vec<OrderBy>

ORDER BY clauses within the window

§frame: Option<WindowFrame>

Frame specification (ROWS or RANGE)

§

JsonExtract

JSON path extraction (returns JSON value)

  • PostgreSQL: expr -> 'path' or expr -> path_expr
  • MySQL: JSON_EXTRACT(expr, '$.path')
  • SQLite: json_extract(expr, '$.path')

Fields

§expr: Box<Expr>

The JSON expression to extract from

§path: JsonPath

The path to extract (can be a key name or array index)

§

JsonExtractText

JSON path extraction as text (returns text/string)

  • PostgreSQL: expr ->> 'path'
  • MySQL: JSON_UNQUOTE(JSON_EXTRACT(expr, '$.path'))
  • SQLite: json_extract(expr, '$.path') (SQLite returns text by default)

Fields

§expr: Box<Expr>

The JSON expression to extract from

§path: JsonPath

The path to extract

§

JsonExtractPath

JSON path extraction with nested path (returns JSON)

  • PostgreSQL: expr #> '{path, to, value}'
  • MySQL/SQLite: JSON_EXTRACT(expr, '$.path.to.value')

Fields

§expr: Box<Expr>

The JSON expression

§path: Vec<String>

Nested path segments

§

JsonExtractPathText

JSON path extraction with nested path as text

  • PostgreSQL: expr #>> '{path, to, value}'
  • MySQL: JSON_UNQUOTE(JSON_EXTRACT(expr, '$.path.to.value'))
  • SQLite: json_extract(expr, '$.path.to.value')

Fields

§expr: Box<Expr>

The JSON expression

§path: Vec<String>

Nested path segments

§

JsonContains

JSON containment check (left contains right)

  • PostgreSQL: expr @> other (JSONB only)
  • MySQL: JSON_CONTAINS(expr, other)
  • SQLite: Not directly supported (requires json_each workaround)

Fields

§expr: Box<Expr>

The JSON expression to check

§other: Box<Expr>

The JSON value to check for

§

JsonContainedBy

JSON contained-by check (left is contained by right)

  • PostgreSQL: expr <@ other (JSONB only)
  • MySQL: JSON_CONTAINS(other, expr)
  • SQLite: Not directly supported

Fields

§expr: Box<Expr>

The JSON expression to check

§other: Box<Expr>

The containing JSON value

§

JsonHasKey

JSON key existence check

  • PostgreSQL: expr ? 'key' (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'one', '$.key')
  • SQLite: json_type(expr, '$.key') IS NOT NULL

Fields

§expr: Box<Expr>

The JSON expression

§key: String

The key to check for

§

JsonHasAnyKey

JSON any key existence (has any of the keys)

  • PostgreSQL: expr ?| array['key1', 'key2'] (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'one', '$.key1', '$.key2')
  • SQLite: Requires OR of json_type checks

Fields

§expr: Box<Expr>

The JSON expression

§keys: Vec<String>

The keys to check for

§

JsonHasAllKeys

JSON all keys existence (has all of the keys)

  • PostgreSQL: expr ?& array['key1', 'key2'] (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'all', '$.key1', '$.key2')
  • SQLite: Requires AND of json_type checks

Fields

§expr: Box<Expr>

The JSON expression

§keys: Vec<String>

The keys to check for

§

JsonArrayLength

JSON array length

  • PostgreSQL: jsonb_array_length(expr)
  • MySQL: JSON_LENGTH(expr)
  • SQLite: json_array_length(expr)

Fields

§expr: Box<Expr>

The JSON array expression

§

JsonTypeof

JSON typeof (returns the type of the JSON value)

  • PostgreSQL: jsonb_typeof(expr)
  • MySQL: JSON_TYPE(expr)
  • SQLite: json_type(expr)

Fields

§expr: Box<Expr>

The JSON expression

Implementations§

Source§

impl Expr

Source

pub fn col(name: impl Into<String>) -> Expr

Create a column reference expression.

Source

pub fn qualified(table: impl Into<String>, column: impl Into<String>) -> Expr

Create a qualified column reference (table.column).

Source

pub fn lit(value: impl Into<Value>) -> Expr

Create a literal value expression.

Source

pub fn null() -> Expr

Create a NULL literal.

Source

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

Create a raw SQL expression (escape hatch).

Source

pub fn placeholder(index: usize) -> Expr

Create a placeholder for bound parameters.

Source

pub fn eq(self, other: impl Into<Expr>) -> Expr

Equal to (=)

Source

pub fn ne(self, other: impl Into<Expr>) -> Expr

Not equal to (<>)

Source

pub fn lt(self, other: impl Into<Expr>) -> Expr

Less than (<)

Source

pub fn le(self, other: impl Into<Expr>) -> Expr

Less than or equal to (<=)

Source

pub fn gt(self, other: impl Into<Expr>) -> Expr

Greater than (>)

Source

pub fn ge(self, other: impl Into<Expr>) -> Expr

Greater than or equal to (>=)

Source

pub fn and(self, other: impl Into<Expr>) -> Expr

Logical AND

Source

pub fn or(self, other: impl Into<Expr>) -> Expr

Logical OR

Source

pub fn not(self) -> Expr

Logical NOT

Source

pub fn is_null(self) -> Expr

IS NULL

Source

pub fn is_not_null(self) -> Expr

IS NOT NULL

Source

pub fn is_distinct_from(self, other: impl Into<Expr>) -> Expr

IS DISTINCT FROM (NULL-safe comparison: returns TRUE/FALSE, never NULL)

Unlike !=, this returns TRUE when comparing NULL to a non-NULL value, and FALSE when comparing NULL to NULL.

Source

pub fn is_not_distinct_from(self, other: impl Into<Expr>) -> Expr

IS NOT DISTINCT FROM (NULL-safe equality: returns TRUE/FALSE, never NULL)

Unlike =, this returns TRUE when comparing NULL to NULL, and FALSE when comparing NULL to a non-NULL value.

Source

pub fn cast(self, type_name: impl Into<String>) -> Expr

CAST expression to a specific SQL type.

§Example
Expr::col("price").cast("DECIMAL(10, 2)")
// Generates: CAST("price" AS DECIMAL(10, 2))
Source

pub fn like(self, pattern: impl Into<String>) -> Expr

LIKE pattern match

Source

pub fn not_like(self, pattern: impl Into<String>) -> Expr

NOT LIKE pattern match

Source

pub fn ilike(self, pattern: impl Into<String>) -> Expr

ILIKE (case-insensitive) pattern match (PostgreSQL)

Source

pub fn not_ilike(self, pattern: impl Into<String>) -> Expr

NOT ILIKE pattern match (PostgreSQL)

Source

pub fn contains(self, pattern: impl AsRef<str>) -> Expr

Check if column contains the given substring (LIKE ‘%pattern%’).

§Example
Expr::col("name").contains("man")
// Generates: "name" LIKE '%man%'
Source

pub fn starts_with(self, pattern: impl AsRef<str>) -> Expr

Check if column starts with the given prefix (LIKE ‘pattern%’).

§Example
Expr::col("name").starts_with("Spider")
// Generates: "name" LIKE 'Spider%'
Source

pub fn ends_with(self, pattern: impl AsRef<str>) -> Expr

Check if column ends with the given suffix (LIKE ‘%pattern’).

§Example
Expr::col("name").ends_with("man")
// Generates: "name" LIKE '%man'
Source

pub fn icontains(self, pattern: impl AsRef<str>) -> Expr

Case-insensitive contains (ILIKE ‘%pattern%’ or LOWER fallback).

Source

pub fn istarts_with(self, pattern: impl AsRef<str>) -> Expr

Case-insensitive starts_with (ILIKE ‘pattern%’ or LOWER fallback).

Source

pub fn iends_with(self, pattern: impl AsRef<str>) -> Expr

Case-insensitive ends_with (ILIKE ‘%pattern’ or LOWER fallback).

Source

pub fn in_list(self, values: Vec<impl Into<Expr>>) -> Expr

IN list of values

Source

pub fn not_in_list(self, values: Vec<impl Into<Expr>>) -> Expr

NOT IN list of values

Source

pub fn between(self, low: impl Into<Expr>, high: impl Into<Expr>) -> Expr

BETWEEN low AND high

Source

pub fn not_between(self, low: impl Into<Expr>, high: impl Into<Expr>) -> Expr

NOT BETWEEN low AND high

Source

pub fn add(self, other: impl Into<Expr>) -> Expr

Addition (+)

Source

pub fn sub(self, other: impl Into<Expr>) -> Expr

Subtraction (-)

Source

pub fn mul(self, other: impl Into<Expr>) -> Expr

Multiplication (*)

Source

pub fn div(self, other: impl Into<Expr>) -> Expr

Division (/)

Source

pub fn modulo(self, other: impl Into<Expr>) -> Expr

Modulo (%)

Source

pub fn neg(self) -> Expr

Negation (unary -)

Source

pub fn concat(self, other: impl Into<Expr>) -> Expr

String concatenation (||)

Source

pub fn array_contains(self, other: impl Into<Expr>) -> Expr

Array contains (@>). Tests if this array contains all elements of other.

Source

pub fn array_contained_by(self, other: impl Into<Expr>) -> Expr

Array contained by (<@). Tests if this array is contained by other.

Source

pub fn array_overlap(self, other: impl Into<Expr>) -> Expr

Array overlap (&&). Tests if this array has any elements in common with other.

Source

pub fn array_any_eq(self, value: impl Into<Expr>) -> Expr

ANY(array) = value. Tests if any element of the array equals the value.

Generates: value = ANY(array_column)

Source

pub fn bit_and(self, other: impl Into<Expr>) -> Expr

Bitwise AND (&)

Source

pub fn bit_or(self, other: impl Into<Expr>) -> Expr

Bitwise OR (|)

Source

pub fn bit_xor(self, other: impl Into<Expr>) -> Expr

Bitwise XOR (^)

Source

pub fn bit_not(self) -> Expr

Bitwise NOT (~)

Source

pub fn case() -> CaseBuilder

Start building a CASE expression.

§Example
Expr::case()
    .when(Expr::col("status").eq("active"), "Yes")
    .when(Expr::col("status").eq("pending"), "Maybe")
    .otherwise("No")
Source

pub fn count_star() -> Expr

COUNT(*) aggregate function.

Source

pub fn count(self) -> Expr

COUNT(expr) aggregate function.

Source

pub fn sum(self) -> Expr

SUM(expr) aggregate function.

Source

pub fn avg(self) -> Expr

AVG(expr) aggregate function.

Source

pub fn min(self) -> Expr

MIN(expr) aggregate function.

Source

pub fn max(self) -> Expr

MAX(expr) aggregate function.

Source

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

Create a generic function call.

Source

pub fn row_number() -> Expr

ROW_NUMBER() window function. Returns the sequential number of a row within a partition.

Source

pub fn rank() -> Expr

RANK() window function. Returns the rank of the current row with gaps.

Source

pub fn dense_rank() -> Expr

DENSE_RANK() window function. Returns the rank of the current row without gaps.

Source

pub fn percent_rank() -> Expr

PERCENT_RANK() window function. Returns the relative rank of the current row.

Source

pub fn cume_dist() -> Expr

CUME_DIST() window function. Returns the cumulative distribution of a value.

Source

pub fn ntile(n: i64) -> Expr

NTILE(n) window function. Divides rows into n groups and returns the group number.

Source

pub fn lag(self) -> Expr

LAG(expr) window function with default offset of 1. Returns the value of expr from the row that precedes the current row.

Source

pub fn lag_offset(self, offset: i64) -> Expr

LAG(expr, offset) window function. Returns the value of expr from the row at the given offset before current row.

Source

pub fn lag_with_default(self, offset: i64, default: impl Into<Expr>) -> Expr

LAG(expr, offset, default) window function. Returns the value of expr or default if the offset row doesn’t exist.

Source

pub fn lead(self) -> Expr

LEAD(expr) window function with default offset of 1. Returns the value of expr from the row that follows the current row.

Source

pub fn lead_offset(self, offset: i64) -> Expr

LEAD(expr, offset) window function. Returns the value of expr from the row at the given offset after current row.

Source

pub fn lead_with_default(self, offset: i64, default: impl Into<Expr>) -> Expr

LEAD(expr, offset, default) window function. Returns the value of expr or default if the offset row doesn’t exist.

Source

pub fn first_value(self) -> Expr

FIRST_VALUE(expr) window function. Returns the first value within the window frame.

Source

pub fn last_value(self) -> Expr

LAST_VALUE(expr) window function. Returns the last value within the window frame.

Source

pub fn nth_value(self, n: i64) -> Expr

NTH_VALUE(expr, n) window function. Returns the nth value within the window frame.

Source

pub fn over(self) -> WindowBuilder

Start building a window function with OVER clause.

§Example
// ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC)
Expr::row_number()
    .over()
    .partition_by(Expr::col("department"))
    .order_by(Expr::col("salary").desc())
    .build()

// SUM(amount) OVER (PARTITION BY customer_id)
Expr::col("amount").sum()
    .over()
    .partition_by(Expr::col("customer_id"))
    .build()
Source

pub fn coalesce(args: Vec<impl Into<Expr>>) -> Expr

COALESCE function: returns the first non-NULL argument.

§Example
Expr::coalesce(vec![Expr::col("nickname"), Expr::col("name"), Expr::lit("Anonymous")])
// Generates: COALESCE("nickname", "name", 'Anonymous')
Source

pub fn nullif(expr1: impl Into<Expr>, expr2: impl Into<Expr>) -> Expr

NULLIF function: returns NULL if both arguments are equal, otherwise returns the first.

§Example
Expr::nullif(Expr::col("value"), Expr::lit(0))
// Generates: NULLIF("value", 0)
Source

pub fn ifnull(expr1: impl Into<Expr>, expr2: impl Into<Expr>) -> Expr

IFNULL/NVL function (dialect-specific): returns expr2 if expr1 is NULL.

This generates IFNULL for SQLite/MySQL or COALESCE for PostgreSQL.

Source

pub fn upper(self) -> Expr

UPPER function: converts string to uppercase.

Source

pub fn lower(self) -> Expr

LOWER function: converts string to lowercase.

Source

pub fn length(self) -> Expr

LENGTH function: returns the length of a string.

Source

pub fn trim(self) -> Expr

TRIM function: removes leading and trailing whitespace.

Source

pub fn ltrim(self) -> Expr

LTRIM function: removes leading whitespace.

Source

pub fn rtrim(self) -> Expr

RTRIM function: removes trailing whitespace.

Source

pub fn substr( self, start: impl Into<Expr>, length: Option<impl Into<Expr>>, ) -> Expr

SUBSTR/SUBSTRING function: extracts a substring.

§Arguments
  • start - 1-based start position
  • length - Optional length of substring
Source

pub fn replace(self, from: impl Into<Expr>, to: impl Into<Expr>) -> Expr

REPLACE function: replaces occurrences of a substring.

Source

pub fn abs(self) -> Expr

ABS function: returns absolute value.

Source

pub fn round(self, decimals: impl Into<Expr>) -> Expr

ROUND function: rounds to specified decimal places.

Source

pub fn floor(self) -> Expr

FLOOR function: rounds down to nearest integer.

Source

pub fn ceil(self) -> Expr

CEIL/CEILING function: rounds up to nearest integer.

Source

pub fn asc(self) -> OrderBy

Create an ascending ORDER BY expression.

Source

pub fn desc(self) -> OrderBy

Create a descending ORDER BY expression.

Source

pub fn paren(self) -> Expr

Wrap expression in parentheses.

Source

pub fn subquery(sql: impl Into<String>) -> Expr

Create a subquery expression.

Source

pub fn exists(subquery_sql: impl Into<String>, params: Vec<Value>) -> Expr

Create an EXISTS subquery expression.

§Arguments
  • subquery_sql - The SELECT subquery SQL (without outer parentheses)
  • params - Parameters for the subquery
§Example
// EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.id)
Expr::exists(
    "SELECT 1 FROM orders WHERE orders.customer_id = customers.id",
    vec![]
)
Source

pub fn not_exists(subquery_sql: impl Into<String>, params: Vec<Value>) -> Expr

Create a NOT EXISTS subquery expression.

§Arguments
  • subquery_sql - The SELECT subquery SQL (without outer parentheses)
  • params - Parameters for the subquery
§Example
// NOT EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.id)
Expr::not_exists(
    "SELECT 1 FROM orders WHERE orders.customer_id = customers.id",
    vec![]
)
Source

pub fn exists_query(subquery: SelectQuery) -> Expr

Create an EXISTS subquery expression from a query builder.

Source

pub fn not_exists_query(subquery: SelectQuery) -> Expr

Create a NOT EXISTS subquery expression from a query builder.

Source

pub fn json_get(self, key: impl Into<String>) -> Expr

Extract a JSON value by key (returns JSON).

Generates dialect-specific SQL:

  • PostgreSQL: expr -> 'key'
  • MySQL: JSON_EXTRACT(expr, '$.key')
  • SQLite: json_extract(expr, '$.key')
§Example
Expr::col("data").json_get("name")
// PostgreSQL: "data" -> 'name'
// MySQL: JSON_EXTRACT("data", '$.name')
Source

pub fn json_get_index(self, index: i64) -> Expr

Extract a JSON value by array index (returns JSON).

Generates dialect-specific SQL:

  • PostgreSQL: expr -> 0
  • MySQL: JSON_EXTRACT(expr, '$[0]')
  • SQLite: json_extract(expr, '$[0]')
§Example
Expr::col("items").json_get_index(0)
// PostgreSQL: "items" -> 0
Source

pub fn json_get_text(self, key: impl Into<String>) -> Expr

Extract a JSON value as text by key.

Generates dialect-specific SQL:

  • PostgreSQL: expr ->> 'key'
  • MySQL: JSON_UNQUOTE(JSON_EXTRACT(expr, '$.key'))
  • SQLite: json_extract(expr, '$.key') (returns text)
§Example
Expr::col("data").json_get_text("name")
// PostgreSQL: "data" ->> 'name'
Source

pub fn json_get_text_index(self, index: i64) -> Expr

Extract a JSON value as text by array index.

§Example
Expr::col("items").json_get_text_index(0)
// PostgreSQL: "items" ->> 0
Source

pub fn json_path(self, path: &[&str]) -> Expr

Extract a nested JSON value by path (returns JSON).

Generates dialect-specific SQL:

  • PostgreSQL: expr #> '{path, to, value}'
  • MySQL: JSON_EXTRACT(expr, '$.path.to.value')
  • SQLite: json_extract(expr, '$.path.to.value')
§Example
Expr::col("data").json_path(&["address", "city"])
// PostgreSQL: "data" #> '{address, city}'
Source

pub fn json_path_text(self, path: &[&str]) -> Expr

Extract a nested JSON value by path as text.

Generates dialect-specific SQL:

  • PostgreSQL: expr #>> '{path, to, value}'
  • MySQL: JSON_UNQUOTE(JSON_EXTRACT(expr, '$.path.to.value'))
  • SQLite: json_extract(expr, '$.path.to.value')
§Example
Expr::col("data").json_path_text(&["address", "city"])
// PostgreSQL: "data" #>> '{address, city}'
Source

pub fn json_contains(self, other: impl Into<Expr>) -> Expr

Check if JSON contains another JSON value.

Generates dialect-specific SQL:

  • PostgreSQL: expr @> other (JSONB only)
  • MySQL: JSON_CONTAINS(expr, other)
§Example
Expr::col("tags").json_contains(Expr::lit(r#"["rust"]"#))
// PostgreSQL: "tags" @> '["rust"]'
Source

pub fn json_contained_by(self, other: impl Into<Expr>) -> Expr

Check if JSON is contained by another JSON value.

Generates dialect-specific SQL:

  • PostgreSQL: expr <@ other (JSONB only)
  • MySQL: JSON_CONTAINS(other, expr)
§Example
Expr::col("tags").json_contained_by(Expr::lit(r#"["rust", "python", "go"]"#))
Source

pub fn json_has_key(self, key: impl Into<String>) -> Expr

Check if JSON object has a specific key.

Generates dialect-specific SQL:

  • PostgreSQL: expr ? 'key' (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'one', '$.key')
  • SQLite: json_type(expr, '$.key') IS NOT NULL
§Example
Expr::col("data").json_has_key("email")
// PostgreSQL: "data" ? 'email'
Source

pub fn json_has_any_key(self, keys: &[&str]) -> Expr

Check if JSON object has any of the specified keys.

Generates dialect-specific SQL:

  • PostgreSQL: expr ?| array['key1', 'key2'] (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'one', '$.key1', '$.key2')
§Example
Expr::col("data").json_has_any_key(&["email", "phone"])
// PostgreSQL: "data" ?| array['email', 'phone']
Source

pub fn json_has_all_keys(self, keys: &[&str]) -> Expr

Check if JSON object has all of the specified keys.

Generates dialect-specific SQL:

  • PostgreSQL: expr ?& array['key1', 'key2'] (JSONB only)
  • MySQL: JSON_CONTAINS_PATH(expr, 'all', '$.key1', '$.key2')
§Example
Expr::col("data").json_has_all_keys(&["email", "phone"])
// PostgreSQL: "data" ?& array['email', 'phone']
Source

pub fn json_array_length(self) -> Expr

Get the length of a JSON array.

Generates dialect-specific SQL:

  • PostgreSQL: jsonb_array_length(expr)
  • MySQL: JSON_LENGTH(expr)
  • SQLite: json_array_length(expr)
§Example
Expr::col("items").json_array_length()
Source

pub fn json_typeof(self) -> Expr

Get the type of a JSON value.

Generates dialect-specific SQL:

  • PostgreSQL: jsonb_typeof(expr)
  • MySQL: JSON_TYPE(expr)
  • SQLite: json_type(expr)
§Example
Expr::col("data").json_typeof()
Source

pub fn build(&self, params: &mut Vec<Value>, offset: usize) -> String

Build SQL string and collect parameters (default PostgreSQL dialect).

Source

pub fn build_with_dialect( &self, dialect: Dialect, params: &mut Vec<Value>, offset: usize, ) -> String

Build SQL string with specific dialect.

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

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

impl From<&str> for Expr

Source§

fn from(s: &str) -> Expr

Converts to this type from the input type.
Source§

impl From<String> for Expr

Source§

fn from(s: String) -> Expr

Converts to this type from the input type.
Source§

impl From<Value> for Expr

Source§

fn from(v: Value) -> Expr

Converts to this type from the input type.
Source§

impl From<bool> for Expr

Source§

fn from(b: bool) -> Expr

Converts to this type from the input type.
Source§

impl From<f32> for Expr

Source§

fn from(n: f32) -> Expr

Converts to this type from the input type.
Source§

impl From<f64> for Expr

Source§

fn from(n: f64) -> Expr

Converts to this type from the input type.
Source§

impl From<i32> for Expr

Source§

fn from(n: i32) -> Expr

Converts to this type from the input type.
Source§

impl From<i64> for Expr

Source§

fn from(n: i64) -> Expr

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> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> 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<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