+0
日增长
+4
周增长
994
stars
265
forks
14
watchers
681
prs
285
issues
49
releases
README
duckdb-rs
duckdb-rs is an ergonomic Rust wrapper for DuckDB.
You can use it to:
- Query DuckDB with type-safe bindings and an API inspired by rusqlite.
- Read and write Arrow, Parquet, JSON, and CSV formats natively.
- Create DuckDB extensions in Rust with custom scalar and table functions.
Quickstart
Create a new project and add the duckdb crate:
shell
cargo new quack-in-rust
cd quack-in-rust
cargo add duckdb -F bundled
Update src/main.rs with the following code:
rust
use duckdb::{params, Connection, Result};
struct Duck {
id: i32,
name: String,
}
fn main() - Result {
let conn = Connection::open_in_memory()?;
conn.execute(
"CREATE TABLE ducks (id INTEGER PRIMARY KEY, name TEXT)",
[], // empty list of parameters
)?;
conn.execute_batch(
r"
INSERT INTO ducks (id, name) VALUES (1, 'Donald Duck');
INSERT INTO ducks (id, name) VALUES (2, 'Scrooge McDuck');
",
)?;
conn.execute(
"INSERT INTO ducks (id, name) VALUES (?, ?)",
params![3, "Darkwing Duck"],
)?;
let ducks = conn
.prepare("FROM ducks")?
.query_map([], |row| {
Ok(Duck {
id: row.get(0)?,
name: row.get(1)?,
})
})?
.collect::()?;
for duck in ducks {
println!("{}) {}", duck.id, duck.name);
}
Ok(())
}
Execute the program with cargo run and watch DuckDB in action!
New! duckdb-neo: the v2 C API wrapper (beta)
duckdb-neo is the new crate that targets DuckDB's new v2 C API (duckdb_v2.h) instead of the v1 API used by duckdb. This allows you to do much more - replacement scans, copy, aggregates, all first-class citizens.
Installation is simple:
shell
cargo add duckdb-neo
rust,ignore
use duckdb_neo::{
Parameters,
environment::{Environment, StorageLocation},
};
fn main() - duckdb_neo::Result {
let environment = Environment::new()?;
let instance = environment.open(StorageLocation::InMemory)?;
let connection = instance.connect()?;
let mut result = connection.query("SELECT $1::INTEGER", Parameters::positional(&[&42]))?;
let chunk = result.next_chunk()?.expect("query returned no rows");
let values = chunk.get_vector_at::(0)?.reader()?;
assert_eq!(values.get(0)?, Some(&42));
Ok(())
}
To try it interactively, run the SQL REPL example with cargo run -p duckdb-neo --example repl.
To write DuckDB extensions with duckdb-neo, loadable or statically linked, see crates/duckdb-neo/extensions.md or the extension template.
Examples
The following examples demonstrate various features and use cases of duckdb-rs:
- basic - Basic usage including creating tables, inserting data, and querying with and without Arrow.
- appender - Bulk data insertion using the appender API with transactions.
- arrow_vtab - Querying an in-memory Arrow RecordBatch from DuckDB SQL (requires the vtab-arrow feature).
- parquet - Reading Parquet files directly usiTop issues
#733Internal error when maintaining multiple connections while using RTREE index8 comments · 2026-03-31#533Partial impl<'a> From<&'a Value> for ValueRef<'a> causes panics6 comments · 2025-07-10#251Issue with Mutable Borrow of Statement when Accessing Column Names (Option::unwrap())6 comments · 2024-01-05#401VTab: filter_pushdown support5 comments · 2024-11-16#329`FromSql` is not implemented for `Vec<f64>`4 comments · 2024-06-06#875Support for using the DuckDB C++ API3 comments · 2026-09-25#857macos compile failed2 comments · 2026-09-15#679Detecting HTTP 404 (Not Found) responses2 comments · 2026-02-04
Latest release
v1.20001.0 v1.20001.0 2026-11-20What's Changed Add icu to bundled builds by @okruitho in https://github.com/duckdb/duckdb-rs/pull/952 Added repl for duckdb-neo by @okruitho in https://github.com/duckdb/duckdb-rs/pull/953 duckdb-neo: refactor BindArguments by @okruitho in https://github.com/duckdb/duckdb-rs/pull/954 duckdb-neo: refactor datachunk by @okruitho in https://github.com/duckdb/duckdb-rs/pull/958 duckdb-neo: Jiff support by @okruitho in https://github.com/duckdb/duckdb-rs/pull/959 Prepare 2.0.1 by @okruitho in https://github.com/duckdb/duckdb-rs/pull/960 Release to 2.0.1 by @okruitho in https://github.