Skip to main content
With this crate’s derive feature on, better-duck-core’s data derives are re-exported from better_duck_diesel with Diesel FromSql/ToSql emission enabled. The same Rust type that maps to a DuckDB ENUM or STRUCT in core then also binds and loads through a DuckDbConnection at its sql_types::DuckEnum / sql_types::DuckStruct column type.

What the feature does

The core derives (DuckEnum, DuckStruct, FromRow, ToRow) always exist in core. Turning on better-duck-diesel/derive makes DuckEnum and DuckStruct additionally emit Diesel ToSql / FromSql impls against better_duck_diesel::sql_types::DuckEnum / DuckStruct. Mechanically this flips on core’s derive-diesel feature, whose generated code resolves ::better_duck_diesel in your crate — so core itself never gains a Diesel dependency. See core feature flags.
The ORM path for these DuckDB-specific types is sql_query + QueryableByName (not the plain Queryable builder), because the Duck* SQL types have no Queryable blanket impl — see Type mapping.

Mapping an enum to ENUM

Mapping a struct to STRUCT

#[derive(DuckStruct)] works the same way at sql_types::DuckStruct — bind with .bind::<DuckStructSql, _>(value) and read via a QueryableByName field typed #[diesel(sql_type = DuckStructSql)].

Renaming

Field/variant renaming honors #[duck(rename = "…")] / #[duck(rename_all = "…")] (and the #[duck_enum(...)] forms for enums), identical to the core derives. The full casing list and resolution order are on the data derives page.

Re-exports

Available from better_duck_diesel under the derive feature: FromRow, ToRow, DuckEnum, DuckStruct.
FromRow / ToRow are the core driver’s row traits, not Diesel’s Queryable/Insertable. For ordinary standard-typed tables use Diesel’s own derives (see Schema); use DuckEnum / DuckStruct here specifically for the DuckDB ENUM / STRUCT column types. Without the derive feature, the derives still exist in core but don’t emit the Diesel FromSql/ToSql impls.

See also

Data derives (core)

Authoring DuckEnum / DuckStruct and renaming rules.

Type mapping

The DuckEnum / DuckStruct SQL types.

Schema

Declaring the columns these types back.

Feature flags

How derive relates to core’s derive-diesel.