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-diesel is a full Diesel 2.3 backend for DuckDB. It implements the Diesel Connection trait — including SimpleConnection, LoadConnection, AnsiTransactionManager, and migration support — so your existing table! macro definitions, query DSL chains, and migration files work against DuckDB without modification. Both in-memory and on-disk databases are supported out of the box.
better-duck-diesel is currently in beta. The API is settling and breaking
changes before 1.0 are possible. Pin the exact pre-release version in your
Cargo.toml and check the changelog
before upgrading.Adding the Dependency
Add both crates to yourCargo.toml. Because these are pre-release versions, Cargo’s default
"0.1" shorthand will not resolve them — pin the exact version as shown below.
better-duck-diesel as needed:
Connecting
DuckDbConnection implements diesel::Connection, so you open a connection with the standard
Connection::establish entry-point. Three URL forms are accepted:
Creating Tables
DDL statements are executed through theSimpleConnection::batch_execute method, which accepts
any SQL string — including multi-statement batches separated by semicolons. You must bring the
SimpleConnection trait into scope explicitly.
batch_execute is also the right tool for CREATE TYPE, CREATE SEQUENCE, DROP TABLE, and any
other DDL that does not return rows.
Connection Pooling
Ther2d2 Cargo feature unlocks two complementary pooling strategies. Both use
r2d2::Pool::builder() — they differ in how each pooled connection relates to the underlying
DuckDB database file.
SharedDuckDbConnectionManager can also be backed by a file:
From Core Connection
If you already have abetter_duck_core::connection::Connection — for example, one obtained from a
better_duck_core::database::Database — you can wrap it as a Diesel connection without re-opening
the file:
SharedDuckDbConnectionManager works internally, and it is the only way to make
multiple Diesel connections share a single in-memory database without going through the pool API.