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 + IntStructs§
- 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§
- Aggregate
Kind - 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
Exprtype. - 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.
- Nullable
AggExpr - An aggregate, nullable expression.
- Nullable
Expr - A scalar, nullable expression.
- Scalar
Expr - A scalar, non-null expression.