DuckDbConnection. All of this is Diesel’s portable query builder — it works on the
DuckDB backend with no extra imports. For DuckDB-only predicates and scalar functions in .filter /
.select, add the DSL prelude.
Loading rows
.load() materializes a result set into a Vec. The target type is a tuple of the selected columns’
Rust types, or a #[derive(Queryable)] struct:
Selecting specific columns
.select narrows the projection. A single column loads as its scalar type; a tuple loads as a tuple:
Filtering, ordering, limiting
eq, ne, lt, le, gt, ge, like, between, is_null, eq_any, …) and
count/sum/avg/min/max are all Diesel’s own and need no DuckDB imports.
For DuckDB-only predicates —
ILIKE, SIMILAR TO, GLOB, regex operators, IS DISTINCT FROM — add
use better_duck_diesel::dsl::*;. See Operators. DuckDB-only scalar functions
(e.g. lower, date_trunc) can also appear in .filter/.select — see the
DSL overview.Single rows
Counting and aggregating
string_agg, array_agg, …) live in the DSL — see
Aggregates.
Nullable columns
ANullable<T> column binds Some(v)/None and loads as Option<T> — SQL NULL reads back as None.
Selecting a normally-non-null expression .nullable() (e.g. an aggregate over an empty set, or the right
side of a LEFT JOIN) is the other common source of Option:
Joins
Teach Diesel the relationship withjoinable! + allow_tables_to_appear_in_same_query!, then
inner_join / left_join. inner_join keeps only matched rows; left_join keeps every left row and
makes the right side .nullable():
Boxed queries & pagination
.into_boxed() erases the query type so you can apply limit/offset decided at runtime — the usual
pagination pattern:
See also
Operators
ILIKE, GLOB, regex, and null-safe comparison.Aggregates
DuckDB aggregates for grouped selects.
Insert
Write rows back.
Type mapping
Which Rust type each column loads as.