table! macro with both standard and DuckDB-specific
column types, mapping rows to Rust structs with Diesel’s derives, and running migrations through the
backend’s MigrationConnection impl.
Declaring a schema with table!
Standard Diesel. A table using only standard column types needs no extra imports:
use better_duck_diesel::sql_types::*; inside the macro so the
Duck* SQL types resolve:
Duck* column types, and how each maps to Rust, is on the
Type mapping page.
Mapping rows to structs
Diesel’s own derives work exactly as they do on any backend:derive
Reads a row positionally into a struct, in field order.
derive
Lets
.select(T::as_select()) pick columns by name, decoupling struct field order from the query.better-duck-core’s own FromRow derive is for the core driver’s row API, not Diesel’s Queryable.
Use Diesel’s Queryable/Selectable here. The derive feature re-exports the core derives for the
DuckDB-specific Duck* column types — see Data derives.Migrations
DuckDbConnection implements diesel::migration::MigrationConnection. Its setup() creates the
__diesel_schema_migrations bookkeeping table (a VARCHAR(50) primary key plus a
TIMESTAMP DEFAULT current_timestamp), so the standard migration machinery works:
diesel migration run/revert/redovia the Diesel CLI.embed_migrations!+MigrationHarnessfor migrations compiled into the binary.
embed_migrations! / MigrationHarness machinery is Diesel’s own; this crate only supplies the
MigrationConnection impl that makes it run against DuckDB.
See also
Type mapping
Every column type and its Rust counterpart.
Select
Load rows into tuples and structs.
Insert
Insertable structs and value tuples.Data derives
ORM-emitting
DuckEnum / DuckStruct for Duck* columns.