better-duck-diesel exposes DuckDB-specific SQL as a typed Diesel DSL — operators, scalar functions,
and aggregates — so you reach DuckDB features that stock Diesel has no equivalent for without dropping
to sql_query. Everything is verified against crates/better-duck-diesel/src/expressions/**; each
item emits real DuckDB SQL and the Rust name matches the SQL name except where a #[sql_name] override
is noted on its page.
Bringing in the prelude
Import the DSL alongside Diesel’s own prelude:- Two operator extension traits —
DuckTextExpressionMethodsandDuckExpressionMethods— blanket-implemented for every expression, giving.ilike(),.glob(),.is_distinct_from(), and friends. See Operators. - A library of typed free functions — string, numeric, date/time, JSON, list/map, and more.
- DuckDB aggregates defined with
#[aggregate]. See Aggregates.
Spatial
ST_* functions are not in dsl::*. Import them from better_duck_diesel::spatial::* under
feature = "spatial" — see Spatial.Calling scalar functions
The free functions are ordinary Diesel expressions. Use them anywhere an expression is accepted — in.select(...), .filter(...), an UPDATE … SET, or standalone via diesel::select:
Calling aggregates
Aggregates are free functions too; use them in an aggregating or grouped.select:
count/sum/avg/min/max; this
crate adds only what core lacks.
Binding custom-typed values in an expression
Bareu64 / i128 / DuckUuid / … cannot be used directly as a DSL expression at a Duck* SQL type
(a third-party coherence limit). Wrap them in a values::* newtype and .into_sql::<SqlType>():
The DSL pages
Operators
ILIKE / SIMILAR TO / GLOB / regex / null-safe comparison.
String functions
Case, trim, pad, search, similarity, regex, hashing, encoding.
Numeric & utility functions
Math, trig, conditional, UUID generation, version/typeof.
Date & time functions
Extract parts, build dates/times, format.
JSON functions
Validate, extract, and inspect JSON.
List & map functions
LIST and MAP scalar functions.
Aggregates
Statistical, approximate, bitwise, JSON aggregates.
Calling your own UDFs
Register
#[duckdb_*] functions and call them typed.Spatial
ST_* functions behind feature = "spatial".