Module expr

Module expr 

Source
Expand description

Type-safe SQL expression system.

This module provides a type-safe wrapper around SQL expressions that tracks:

  • The SQL data type of the expression
  • Whether the expression can be NULL
  • Whether the expression is an aggregate or scalar

§Example

use drizzle_core::expr::*;

// Type-safe comparisons
let condition = eq(users.id, 10);  // OK: Int == Int
// let bad = eq(users.id, "hello"); // ERROR: Int != Text

// Type-safe arithmetic
let total = users.price + users.tax;  // OK: both Numeric
// let bad = users.name + users.id;   // ERROR: Text + Int

Structs§

Agg
Marker indicating an aggregate expression (COUNT, SUM, etc.).
NonNull
Marker indicating an expression cannot be NULL.
Null
Marker indicating an expression can be NULL.
SQLExpr
A SQL expression that carries type information.
Scalar
Marker indicating a scalar (non-aggregate) expression.

Traits§

AggregateKind
Marker trait for expression aggregation state.
Expr
An expression in SQL with an associated data type.
ExprExt
Extension trait providing method-based comparisons for any Expr type.
NullOr
Combine nullability: if either input is nullable, output is nullable.
Nullability
Marker trait for nullability state.

Functions§

abs
ABS - returns the absolute value of a number.
age
AGE - calculates the interval between two timestamps (PostgreSQL).
alias
Create an aliased expression.
and
Logical AND of multiple conditions.
and2
Logical AND of two expressions.
avg
AVG(expr) - calculates average of numeric values.
avg_distinct
AVG(DISTINCT expr) - calculates average of distinct numeric values.
between
BETWEEN comparison.
cast
Cast an expression to a different type.
ceil
CEIL / CEILING - rounds a number up to the nearest integer.
coalesce
COALESCE - returns first non-null value.
coalesce_many
COALESCE with multiple values.
concat
Concatenate two string expressions using || operator.
count
COUNT(expr) - counts non-null values.
count_all
COUNT(*) - counts all rows.
count_distinct
COUNT(DISTINCT expr) - counts distinct non-null values.
current_date
CURRENT_DATE - returns the current date.
current_time
CURRENT_TIME - returns the current time.
current_timestamp
CURRENT_TIMESTAMP - returns the current timestamp.
date
DATE - extracts the date part from a temporal expression (SQLite).
date_trunc
DATE_TRUNC - truncates a timestamp to specified precision (PostgreSQL).
datetime
DATETIME - creates a datetime from a temporal expression (SQLite).
distinct
DISTINCT - marks an expression as DISTINCT.
eq
Equality comparison (=).
exists
EXISTS subquery check.
exp
EXP - returns e raised to the power of the argument.
extract
EXTRACT - extracts a component from a temporal expression (PostgreSQL/Standard SQL).
floor
FLOOR - rounds a number down to the nearest integer.
group_concat
GROUP_CONCAT / STRING_AGG - concatenates values into a string.
gt
Greater-than comparison (>).
gte
Greater-than-or-equal comparison (>=).
ifnull
IFNULL - SQLite/MySQL equivalent of COALESCE with two arguments.
in_array
IN array check.
in_subquery
IN subquery check.
instr
INSTR - finds the position of a substring.
is_not_null
IS NOT NULL check.
is_null
IS NULL check.
julianday
JULIANDAY - converts a temporal expression to Julian day number (SQLite).
length
LENGTH - returns the length of a string.
like
LIKE pattern matching.
ln
LN - returns the natural logarithm of a number.
log
LOG - returns the logarithm of a number with a specified base.
log10
LOG10 - returns the base-10 logarithm of a number.
lower
LOWER - converts string to lowercase.
lt
Less-than comparison (<).
lte
Less-than-or-equal comparison (<=).
ltrim
LTRIM - removes leading whitespace.
max
MAX(expr) - finds maximum value.
min
MIN(expr) - finds minimum value.
mod_
MOD - returns the remainder of division (using % operator).
neq
Inequality comparison (<> or !=).
not
Logical NOT.
not_between
NOT BETWEEN comparison.
not_exists
NOT EXISTS subquery check.
not_in_array
NOT IN array check.
not_in_subquery
NOT IN subquery check.
not_like
NOT LIKE pattern matching.
now
NOW - returns the current timestamp with time zone (PostgreSQL).
nullif
NULLIF - returns NULL if arguments are equal, else first argument.
or
Logical OR of multiple conditions.
or2
Logical OR of two expressions.
power
POWER - raises a number to a power.
raw
Create a raw SQL expression with a specified type.
raw_non_null
Create a raw SQL expression with explicit nullability.
replace
REPLACE - replaces occurrences of a substring.
round
ROUND - rounds a number to the nearest integer (or specified precision).
round_to
ROUND with precision - rounds a number to specified decimal places.
rtrim
RTRIM - removes trailing whitespace.
sign
SIGN - returns the sign of a number (-1, 0, or 1).
sqrt
SQRT - returns the square root of a number.
stddev_pop
STDDEV_POP - population standard deviation.
stddev_samp
STDDEV_SAMP / STDDEV - sample standard deviation.
strftime
STRFTIME - formats a temporal expression as text (SQLite).
string_concat
Concatenate two string expressions using || operator.
substr
SUBSTR - extracts a substring from a string.
sum
SUM(expr) - sums numeric values.
sum_distinct
SUM(DISTINCT expr) - sums distinct numeric values.
time
TIME - extracts the time part from a temporal expression (SQLite).
to_char
TO_CHAR - formats a temporal expression as text (PostgreSQL).
to_timestamp
TO_TIMESTAMP - converts a Unix timestamp to a timestamp (PostgreSQL).
trim
TRIM - removes leading and trailing whitespace.
trunc
TRUNC - truncates a number towards zero.
typeof
Alias for typeof_ (uses Rust raw identifier syntax).
typeof_
Get the SQL type of an expression.
unixepoch
UNIXEPOCH - converts a temporal expression to Unix timestamp (SQLite 3.38+).
upper
UPPER - converts string to uppercase.
var_pop
VAR_POP - population variance.
var_samp
VAR_SAMP / VARIANCE - sample variance.

Type Aliases§

AggExpr
An aggregate, non-null expression.
NullableAggExpr
An aggregate, nullable expression.
NullableExpr
A scalar, nullable expression.
ScalarExpr
A scalar, non-null expression.