/better-duck-skills:better-duck-dieselfrom better-duck-skills
Provides a Diesel 2.3 ORM backend for DuckDB, enabling typed queries, schema mapping, and DuckDB-specific SQL functions (ILIKE, JSON, spatial, UDFs) through Rust.
Ships in better-duck-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
better-duck-diesel is a third-party Diesel 2.3 backend for DuckDB. It plugs the
better-duck-core driver into Diesel's typed query builder, so you connect,
map a schema with table!, and build INSERT/SELECT/UPDATE/DELETE queries as Rust — while still
reaching the DuckDB-specific SQL (operators, scalar functions, aggregates, types) that stock Diesel has
no equivalent for.
Sibling skills: better-duck (the crate map / router), better-duck-core (the raw Rust driver
API), better-duck-macros (the #[duckdb_*] UDF and FromRow/DuckEnum derive macros), and
duckdb (SQL dialect + engine behavior). Reach for better-duck-core whenever you need something
below the ORM (the appender, columnar chunks, async, raw parameter binding).
DuckDB is compiled and embedded through core — no system install. This crate's default feature set is
["decimal"] only; note that chrono is NOT on by default here (unlike core), so turn it on for
date/time column support.
[dependencies]
better-duck-diesel = "0.1.0-beta.8"
diesel = "2.3"
use better_duck_diesel::DuckDbConnection;
use diesel::prelude::*;
diesel::table! {
products (id) {
id -> Integer,
name -> Text,
price -> Double,
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// `:memory:` or a file path; a leading `duckdb://` is stripped.
let mut conn = DuckDbConnection::establish(":memory:")?;
conn.batch_execute(
"CREATE TABLE products (id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, price DOUBLE NOT NULL)",
)?;
diesel::insert_into(products::table)
.values((products::id.eq(1), products::name.eq("widget"), products::price.eq(9.99)))
.execute(&mut conn)?;
let rows: Vec<(i32, String, f64)> = products::table
.filter(products::price.lt(20.0))
.order(products::name.asc())
.load(&mut conn)?;
assert_eq!(rows, [(1, "widget".to_string(), 9.99)]);
Ok(())
}
DuckDbConnection is a full Diesel Connection + LoadConnection: .transaction(|c| …), prepared-
statement caching, instrumentation, r2d2, and diesel migration (it implements MigrationConnection)
all work. .inner() / .inner_mut() expose the underlying core Connection (for registering UDFs,
loading extensions, etc.).
| You want to… | Go to |
|---|---|
Add the crate, open a DuckDbConnection, write a table! schema | references/setup-crud.md |
INSERT / SELECT / UPDATE / DELETE, RETURNING, ON CONFLICT, transactions, migrations | references/setup-crud.md |
DuckDB-only operators (.ilike(), .glob(), .is_distinct_from(), …) | references/sql-dsl.md |
DuckDB scalar functions / aggregates the DSL exposes (sqrt, levenshtein, string_agg, approx_quantile, …) | references/sql-dsl.md |
Call your #[duckdb_scalar] / #[duckdb_aggregate] UDF through the DSL (feature = "udf") | references/sql-dsl.md |
Spatial ST_* functions + ensure_loaded (feature = "spatial") | references/sql-dsl.md |
Rust ↔ DuckDB type mapping, sql_types::Duck*, the values::* newtypes | references/types-and-pooling.md |
Connection pooling (r2d2, SharedDuckDbConnectionManager, on_connect) | references/types-and-pooling.md |
ORM-emitting data derives — DuckEnum/DuckStruct through Diesel (feature = "derive") | references/types-and-pooling.md |
Diesel core already gives you the portable surface: =/</>, LIKE, count/sum/avg/min/max,
.filter/.order/.limit, joins, insert_into/update/delete, RETURNING, ON CONFLICT. Use it
as-is — those work on DuckDbConnection with no extra imports.
The DuckDB-only surface lives behind one import:
use better_duck_diesel::dsl::*; // alongside `use diesel::prelude::*;`
That prelude brings in two operator extension traits (DuckExpressionMethods,
DuckTextExpressionMethods) plus a large library of free functions and aggregates — all typed, all
emitting real DuckDB SQL, none requiring sql_query. See references/sql-dsl.md for the verified
inventory. (Spatial ST_* functions are not in this prelude — import them from
better_duck_diesel::spatial::* under feature = "spatial".)
Verified against crates/better-duck-diesel/Cargo.toml.
| Feature | Default | Enables |
|---|---|---|
decimal | ✓ | Diesel Numeric ↔ rust_decimal::Decimal (forwards to core decimal) |
chrono | — | Diesel date/time impls (DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL, TIME_TZ, TIME_NS) |
r2d2 | — | r2d2 pooling: diesel::r2d2 support + pool::SharedDuckDbConnectionManager |
udf | — | expose the core connection for registering #[duckdb_*] UDFs, callable in the DSL |
spatial | — | the spatial module: ST_* DSL functions + ensure_loaded |
json | — | bundle DuckDB's JSON extension so the JSON DSL works offline (forwards to core json) |
derive | — | re-export FromRow/ToRow/DuckEnum/DuckStruct with Diesel FromSql/ToSql emission on |
Notes:
bundled feature on this crate (the README's feature table lists one, but
Cargo.toml does not define it). DuckDB is embedded through core regardless.spatial carries no extra Rust deps — it only gates the module; the ST_* functions are plain SQL,
and ensure_loaded installs/loads the extension at runtime (needs network unless already present).better-duck-core — those are
not part of the Diesel surface.better-duck-diesel = "0.1.0-beta.8".diesel::prelude::*; add use better_duck_diesel::dsl::*; only when you need the
DuckDB-specific SQL.better_duck_diesel::sql_types::* (used inside table!).u64, i128, UUID, BIT, BIGNUM, …) bind/load through the
better_duck_diesel::values::* newtypes — bare i128/u64 cannot implement AsExpression at a
foreign SQL type from a third-party crate (coherence)..transaction still works via BEGIN/COMMIT/ROLLBACK
at the top level. See the duckdb skill for engine-level transaction details.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
diesel-orm, duckdb-orm, rust-database, typed-queries, better-duck-diesel
Other plugins' skills for the same job
npx claudepluginhub nimdeveloper/better-duck --plugin better-duck-skills6 skills in this plugin
/better-duckOverview and task router for the better-duck DuckDB driver for Rust. Use when working with the better-duck / better-duck-core / better-duck-macros / better-duck-diesel / better-duck-tauri crates, when choosing a Cargo feature flag, or when deciding which API or crate fits a task (opening a connection, querying, parameter binding, bulk insert, columnar access, user-defined functions, Diesel ORM, or a Tauri plugin). Routes to the per-crate skills for depth./better-duck-coreRust API guide for the better-duck-core crate (the embedded DuckDB driver published as better-duck): opening connections, executing SQL, iterating rows and values, parameter binding, bulk insert, columnar chunks, transactions, pooling, async, and Arrow/Polars interop. Use when writing Rust against better-duck-core — Connection, execute, execute_with, execute_with_named, DuckResult / DuckValue, Appender, fetch_chunk, TableDescription, Database — or when choosing a Cargo flag feature = "chrono|decimal|arrow|polars|columnar|udf|async|pool|time|uuid" (plus json / parquet / icu for bundled extensions, and derive). For DuckDB SQL and engine behavior use the duckdb skill; for the UDF and data-derive macros use better-duck-macros./better-duck-macrosProc-macro surface of the better-duck-macros crate — DuckDB user-defined functions and data derives — consumed through better-duck-core's `feature = "udf"` and `feature = "derive"` (and better-duck-diesel's `derive`), never by depending on better-duck-macros directly. Use when writing or registering a UDF with `#[duckdb_scalar]`, `#[duckdb_table_function]`, `#[duckdb_aggregate]`, `#[duckdb_cast]`, or `#[duckdb_entrypoint]`; when mapping Rust types with `#[derive(FromRow|ToRow|DuckEnum|DuckStruct)]`; when reaching for the `transaction!` / `params!` helper macros; or when choosing/debugging their attribute options (`name`, `columns`, `named_params`, `projection_pushdown`, `state`, `volatile`, `rename_all`)./better-duck-tauriThe better-duck-tauri crate: a Tauri v2 plugin that exposes better-duck (embedded DuckDB) to the webview as a local analytics engine. Use when registering the plugin in `tauri::Builder`, choosing a backend Cargo feature (`feature = "backend-core"` default, `feature = "backend-diesel"`, or `feature = "arrow"`), calling the webview commands (`load`/`close`/`select`/`execute`, plus import/export/append/stream/checkpoint/revert) from JS/TS via `@better-duck/tauri`, wiring Tauri capabilities/permissions and the scope + policy security model, defining startup migrations, or configuring WAL checkpoint strategies. Triggers: "Tauri", "webview", the crate name, the command names, or the backend/arrow feature flags./duckdbDuckDB engine knowledge for driving it from Rust through better-duck: the SQL dialect, the DuckDB type system and how each type maps to driver values, extensions (json, parquet, icu, spatial), and runtime behaviors (transactions, appender semantics, named/positional parameters, replacement scans). Use when writing SQL for DuckDB, choosing or reasoning about a DuckDB column type, loading an extension, or diagnosing DuckDB-specific behavior seen through the better-duck driver.