/better-duck-skills:better-duck-corefrom better-duck-skills
Rust API guide for the better-duck-core crate (embedded DuckDB driver): connections, SQL execution, row iteration, parameter binding, bulk insert, columnar chunks, transactions, pooling, async, and Arrow/Polars interop.
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.
The driver crate: a safe Rust wrapper over DuckDB's C API (vendored via better-duck-sys, compiled
in — no system install). It is row-oriented by default, with opt-in features for Arrow, Polars,
columnar chunks, async, pooling, user-defined functions, and derives. On crates.io this crate is
published as better-duck; the library path is always better_duck_core.
This skill is the Rust-API map. For DuckDB's SQL dialect, type system, and engine behavior, use the
duckdb skill; for #[duckdb_scalar] / #[derive(FromRow)] and the other macros, use
better-duck-macros; for the ORM, better-duck-diesel. The top-level better-duck
skill routes between all of these.
better_duck_core::error::Result<T> (alias for
Result<T, better_duck_core::error::Error>). Examples here elide a -> Result<()> wrapper.better_duck_core::types::value::DuckValue — a #[non_exhaustive] enum; match
with a _ arm. Rows come from a DuckResult as DuckRow.&mut [&mut dyn AppendAble] (positional) or &mut [(&str, &mut dyn AppendAble)]
(named). The derive feature's params! macro builds the positional slice.Connection methods that run SQL take &mut self; introspection (table_description, table_names,
client_context) takes &self.use better_duck_core::connection::Connection;
use better_duck_core::types::value::DuckValue;
fn main() -> better_duck_core::error::Result<()> {
// In-memory connection (each `open_in_memory` is its own independent database).
let mut conn = Connection::open_in_memory()?;
// Run DDL / multi-statement batches; results are discarded.
conn.execute_batch(
"CREATE TABLE events (id INTEGER, label VARCHAR, score DOUBLE);
INSERT INTO events VALUES (1, 'alpha', 9.5), (2, 'beta', 3.0);",
)?;
// Positional parameters ($1, $2, …) bound as &mut [&mut dyn AppendAble].
let mut id = 3_i32;
let mut label = String::from("gamma");
let mut score = 7.25_f64;
let changed = conn
.execute_with(
"INSERT INTO events VALUES ($1, $2, $3)",
&mut [&mut id, &mut label, &mut score],
)?
.changes();
assert_eq!(changed, 1);
// Iterate rows: a DuckResult is an Iterator of Result<DuckRow>.
// `execute` runs one statement with no params; use `execute_with` to bind.
for row in conn.execute("SELECT id, label FROM events ORDER BY id")? {
let row = row?;
// Access by name (case-sensitive) or by zero-based index.
let label = row.get_idx(1); // Option<&DuckValue>
match row.get("id") { // Option<&DuckValue>
Some(DuckValue::Int(n)) => println!("id={n} label={label:?}"),
other => println!("unexpected: {other:?}"),
}
}
Ok(())
}
Bulk insert instead of row-by-row INSERT:
use better_duck_core::types::value::DuckValue;
let mut app = conn.appender("events", "main")?; // (table, schema)
app.append(&mut DuckValue::Int(4))?; // one AppendAble per column, per row
// ...append the rest of the columns/rows...
app.save()?; // flush (also auto-flushes on drop)
| You want to… | Use | Reference |
|---|---|---|
| Open in-memory / on-disk; share one DB across connections; set config | Connection::open/open_in_memory/open_with_flags, Database, Config, library_version | connections |
| Run DDL/DML batches | Connection::execute_batch | queries-and-values |
| Run one statement, read rows / changed-row count | Connection::execute → DuckResult | queries-and-values |
| Bind parameters (positional / named / homogeneous) | execute_with, execute_with_named, insert | queries-and-values |
| Iterate / count / peek / materialize rows | DuckResult (next, count, exists, materialize → ResultSet), DuckRow::get/get_idx | queries-and-values |
The full DuckValue variant set + Rust mapping | DuckValue | queries-and-values |
| Inspect a table's columns without a query | Connection::table_description → TableDescription | queries-and-values |
| Bulk-insert rows fast | Connection::appender → Appender | appender |
| Transactions (closure or RAII) | Connection::transaction, begin_transaction → Transaction | transactions |
| Zero-copy columnar read / build-and-insert chunks | DuckResult::fetch_chunk, DataChunkHandle, VectorRef/VectorMut | columnar |
| Async (Tokio), r2d2 pool, Arrow / Polars | AsyncConnection/AsyncDatabase/AsyncPool, pool, query_arrow/query_polars | async-pool-arrow |
| Understand errors; load extensions | error::{Error, Result}, install_extension/ensure_extension | errors-and-extensions |
Map structs/enums, UDFs, transaction!/params! | derives & macros | better-duck-macros skill |
default = ["chrono", "decimal"]. DuckDB is always compiled in. Pin the exact pre-release version
(Cargo's default requirement excludes -beta.N): better-duck-core = "0.1.0-beta.8".
| Feature | Enables |
|---|---|
chrono (default) | chrono ↔ DATE/TIME/TIMESTAMP[_S/_MS/_NS]/TIMESTAMPTZ/TIME_TZ/INTERVAL. Without it, native DuckDate/DuckTime/SystemTime types. |
decimal (default) | rust_decimal::Decimal for DECIMAL |
json, parquet, icu | bundle that DuckDB extension into the static lib (forwarded to better-duck-sys) |
arrow | query_arrow / register_arrow via the Arrow C Data Interface (no added deps) |
polars | query_polars / register_polars (implies arrow; pulls in polars + polars-arrow) |
columnar | DuckResult::fetch_chunk, DataChunkHandle, VectorRef/VectorMut, Appender::append_chunk_handle |
udf | the #[duckdb_*] function macros (also turns on columnar) |
derive | #[derive(FromRow/ToRow/DuckEnum/DuckStruct)] + transaction! / params! |
async | Tokio facade (AsyncConnection, AsyncDatabase, AsyncPool) |
pool | r2d2 pool over a shared Database |
time, uuid | time crate temporals (write path) / uuid::Uuid interop |
columnarandudfshare the same chunk/vector machinery;columnaris the subset without the proc-macro dependency. Enablingudfenablescolumnartoo.AsyncPoolneedsasync+pool.
execute + iterate DuckRow by name/index.Send → DuckResult::materialize() → ResultSet (holds no FFI
handles; Send + Sync + Clone), or an AsyncConnection which materializes for you.Appender, not repeated INSERT.columnar feature's fetch_chunk + VectorRef::as_slice.#[derive(FromRow)] / #[derive(ToRow)] (see better-duck-macros).query_polars / query_arrow.Full rendered API docs: https://docs.rs/better-duck-core.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
duckdb, rust-driver, embedded-database, arrow-interop, polars-interop
Other plugins' skills for the same job
6 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-dieselThe Diesel 2.3 ORM backend for DuckDB, built on better-duck. Use when working with the `better-duck-diesel` crate: establishing a `DuckDbConnection`, defining a `table!` schema, running INSERT/SELECT/UPDATE/DELETE/RETURNING or transactions through Diesel, mapping Rust types to DuckDB column types, or reaching DuckDB-only SQL that Diesel core omits via `use better_duck_diesel::dsl::*;` (ILIKE/SIMILAR TO/GLOB/regex operators; string, numeric, regex, date/time, JSON, list and map functions; general/statistical/approximate/bit aggregates). Also covers calling your `#[duckdb_*]` UDFs through the DSL with no raw SQL (`feature = "udf"`), spatial `ST_*` functions (`feature = "spatial"`), ORM-emitting data derives (`feature = "derive"`), and r2d2 pooling. Triggers: `better-duck-diesel`, Diesel + DuckDB, `DuckDbConnection`, `better_duck_diesel::dsl`, `feature = "udf"|"derive"|"spatial"`./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.npx claudepluginhub nimdeveloper/better-duck --plugin better-duck-skills