Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nimdeveloper/better-duck/llms.txt
Use this file to discover all available pages before exploring further.
better-duck-core gives you a direct, no-ORM DuckDB connection with a straightforward API: open a database, execute SQL, and iterate typed rows — all in safe Rust with no Arrow dependency and no system library required. This guide walks you through the five essential steps from adding the crate to your project all the way to running a parameterized query, using real working code you can paste straight into main.rs.
Add the dependency to Cargo.toml
Open your project’s If you also want the Diesel ORM backend, add both crates:The first build will compile DuckDB from the vendored source archive inside
Cargo.toml and add better-duck-core under [dependencies]:Cargo’s default SemVer range (e.g.
"0.1") excludes pre-release versions like -beta.4. You must pin the exact pre-release string as shown above, or use the CLI:better-duck-sys. This takes a few minutes on a cold cache; subsequent builds use Cargo’s incremental cache and are fast.Open a connection
Connection is the entry point for all database access. You can open an in-memory database (perfect for tests and one-shot scripts) or a persistent on-disk file:better_duck_core::error::Result<Connection>, so they compose naturally with the ? operator.Create tables and insert data with execute_batch
execute_batch runs one or more semicolon-separated SQL statements and discards any result sets. It is ideal for DDL and multi-statement setup scripts:Execute a SELECT and iterate rows
execute returns a DuckResult, which implements Iterator<Item = Result<DuckRow>>. Call row.get(column_name) on each row to retrieve a DuckValue for any column by name:row.get(name) returns Option<&DuckValue> — None if no column with that name exists, or Some(&value) otherwise. You can match on the inner variant to extract the underlying Rust type:DuckValue is #[non_exhaustive] — always include a _ arm to stay forward-compatible as new DuckDB types are added.Run a parameterized query with execute_with
For queries with runtime values, use This prints only the
execute_with. Parameters are positional ($1, $2, …) and passed as a mutable slice of &mut dyn AppendAble references. Any type that implements AppendAble — including all DuckValue variants and Rust primitives — can be used as a bind parameter:alpha row (score 9.5), since beta (7.2) is below the threshold.