ExprExt

Trait ExprExt 

Source
pub trait ExprExt {
    // Required methods
    fn with_alias(self, alias: &str) -> Expr;
    fn or_default(self, default: impl Into<Expr>) -> Expr;
    fn json(self, key: &str) -> JsonBuilder;
    fn path(self, dotted_path: &str) -> JsonBuilder;
    fn cast(self, target_type: &str) -> Expr;
    fn upper(self) -> Expr;
    fn lower(self) -> Expr;
    fn trim(self) -> Expr;
    fn length(self) -> Expr;
    fn abs(self) -> Expr;
}
Expand description

Extension trait to add fluent methods to Expr

Required Methods§

Source

fn with_alias(self, alias: &str) -> Expr

Add an alias to this expression.

§Example
col("name").with_alias("user_name")
Source

fn or_default(self, default: impl Into<Expr>) -> Expr

COALESCE with a default value.

§Example
col("name").or_default("Unknown")  // COALESCE(name, 'Unknown')
Source

fn json(self, key: &str) -> JsonBuilder

JSON text extraction (column->>‘key’).

§Example
col("contact_info").json("phone")  // contact_info->>'phone'
Source

fn path(self, dotted_path: &str) -> JsonBuilder

JSON path extraction with dot notation.

§Example
col("metadata").path("vessel.0.port")  // metadata->'vessel'->0->>'port'
Source

fn cast(self, target_type: &str) -> Expr

Cast to a type: CAST(expr AS type)

§Example
col("value").cast("int")  // CAST(value AS int)
Source

fn upper(self) -> Expr

UPPER(expr)

Source

fn lower(self) -> Expr

LOWER(expr)

Source

fn trim(self) -> Expr

TRIM(expr)

Source

fn length(self) -> Expr

LENGTH(expr)

Source

fn abs(self) -> Expr

ABS(expr)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ExprExt for &str

Source§

fn with_alias(self, alias: &str) -> Expr

Source§

fn or_default(self, default: impl Into<Expr>) -> Expr

Source§

fn json(self, key: &str) -> JsonBuilder

Source§

fn path(self, dotted_path: &str) -> JsonBuilder

Source§

fn cast(self, target_type: &str) -> Expr

Source§

fn upper(self) -> Expr

Source§

fn lower(self) -> Expr

Source§

fn trim(self) -> Expr

Source§

fn length(self) -> Expr

Source§

fn abs(self) -> Expr

Implementors§