pub struct Expr(pub Expression);Expand description
A thin wrapper around Expression that provides fluent operator methods.
Expr is the primary value type flowing through the builder API. It wraps a single
AST Expression node and adds convenience methods for comparisons (.eq(),
.gt(), etc.), logical connectives (.and(), .or(), .not()), arithmetic
(.add(), .sub(), .mul(), .div()), pattern matching (.like(), .ilike(),
.rlike()), and other SQL operations (.in_list(), .between(), .is_null(),
.alias(), .cast(), .asc(), .desc()).
The inner Expression is publicly accessible via the .0 field or
Expr::into_inner().
§Examples
use polyglot_sql::builder::*;
let condition = col("age").gte(lit(18)).and(col("active").eq(boolean(true)));
assert_eq!(condition.to_sql(), "age >= 18 AND active = TRUE");Tuple Fields§
§0: ExpressionImplementations§
Source§impl Expr
impl Expr
Sourcepub fn into_inner(self) -> Expression
pub fn into_inner(self) -> Expression
Consume this wrapper and return the inner Expression node.
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Generate a SQL string from this expression using the default (generic) dialect.
Returns an empty string if generation fails.
Sourcepub fn gte(self, other: Expr) -> Expr
pub fn gte(self, other: Expr) -> Expr
Produce a self >= other greater-than-or-equal comparison.
Sourcepub fn is_not_null(self) -> Expr
pub fn is_not_null(self) -> Expr
Produce a self IS NOT NULL predicate (implemented as NOT (self IS NULL)).
Sourcepub fn in_list(self, values: impl IntoIterator<Item = Expr>) -> Expr
pub fn in_list(self, values: impl IntoIterator<Item = Expr>) -> Expr
Produce a self IN (values...) membership test.
Each element of values becomes an item in the parenthesized list.
Sourcepub fn between(self, low: Expr, high: Expr) -> Expr
pub fn between(self, low: Expr, high: Expr) -> Expr
Produce a self BETWEEN low AND high range test.
Sourcepub fn like(self, pattern: Expr) -> Expr
pub fn like(self, pattern: Expr) -> Expr
Produce a self LIKE pattern case-sensitive pattern match.
Sourcepub fn cast(self, to: &str) -> Expr
pub fn cast(self, to: &str) -> Expr
Produce a CAST(self AS type) type conversion.
The to parameter is parsed as a data type name; see cast() for details.
Sourcepub fn asc(self) -> Expr
pub fn asc(self) -> Expr
Wrap this expression with ascending sort order (self ASC).
Used in ORDER BY clauses. Expressions without an explicit .asc() or .desc()
call default to ascending order when passed to SelectBuilder::order_by().
Sourcepub fn desc(self) -> Expr
pub fn desc(self) -> Expr
Wrap this expression with descending sort order (self DESC).
Used in ORDER BY clauses.
Sourcepub fn ilike(self, pattern: Expr) -> Expr
pub fn ilike(self, pattern: Expr) -> Expr
Produce a self ILIKE pattern case-insensitive pattern match.
Supported by PostgreSQL, Snowflake, and other dialects. Dialects that do not
support ILIKE natively may need transpilation.
Sourcepub fn rlike(self, pattern: Expr) -> Expr
pub fn rlike(self, pattern: Expr) -> Expr
Produce a REGEXP_LIKE(self, pattern) regular expression match.
The generated SQL uses the REGEXP_LIKE function form. Different dialects may
render this as RLIKE, REGEXP, or REGEXP_LIKE after transpilation.
Sourcepub fn not_in(self, values: impl IntoIterator<Item = Expr>) -> Expr
pub fn not_in(self, values: impl IntoIterator<Item = Expr>) -> Expr
Produce a self NOT IN (values...) negated membership test.
Each element of values becomes an item in the parenthesized list.