duckdb-rs

Build Status dependency status codecov

duckdb-rs is an ergonomic wrapper for using duckdb from Rust. It attempts to expose an interface similar to rusqlite. Acctually the initial code and even this README is forked from rusqlite as duckdb also tries to expose a sqlite3 compatible API.

```rust use duckdb::{params, Connection, Result};

[derive(Debug)]

struct Person { id: i32, name: String, data: Option>, }

fn main() -> Result<()> { let conn = Connection::openinmemory()?;

conn.execute_batch(
    r"CREATE SEQUENCE seq;
      CREATE TABLE person (
              id              INTEGER PRIMARY KEY DEFAULT NEXTVAL('seq'),
              name            TEXT NOT NULL,
              data            BLOB
              );
    ")?;

let me = Person {
    id: 0,
    name: "Steven".to_string(),
    data: None,
};
conn.execute(
    "INSERT INTO person (name, data) VALUES (?, ?)",
    params![me.name, me.data],
)?;

let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
let person_iter = stmt.query_map([], |row| {
    Ok(Person {
        id: row.get(0)?,
        name: row.get(1)?,
        data: row.get(2)?,
    })
})?;

for person in person_iter {
    println!("Found person {:?}", person.unwrap());
}
Ok(())

} ```

Notes on building duckdb and libduckdb-sys

libduckdb-sys is a separate crate from duckdb-rs that provides the Rust declarations for DuckDB's C API. By default, libduckdb-sys attempts to find a DuckDB library that already exists on your system using pkg-config, or a Vcpkg installation for MSVC ABI builds.

You can adjust this behavior in a number of ways:

Binding generation

We use bindgen to generate the Rust declarations from DuckDB's C header file. bindgen recommends running this as part of the build process of libraries that used this. We tried this briefly (duckdb 0.10.0, specifically), but it had some annoyances:

So we try to avoid running bindgen at build-time by shipping pregenerated bindings for DuckDB.

If you use the bundled features, you will get pregenerated bindings for the bundled version of DuckDB. If you want to run bindgen at buildtime to produce your own bindings, use the buildtime_bindgen Cargo feature.

Contributing

If running bindgen is problematic for you, --features bundled enables bundled and all features which don't require binding generation, and can be used instead.

Checklist

TODOs

License

DuckDB and libduckdb-sys are available under the MIT license. See the LICENSE file for more info.