duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
428 stars 87 forks source link

Cannot use `duckdb_interrupt` due to private `InnerConnection` #342

Open neilyio opened 2 weeks ago

neilyio commented 2 weeks ago

The Connection hides away the raw duckdb connection object in private fields:

/// A connection to a DuckDB database.
pub struct Connection {
    db: RefCell<InnerConnection>,
    cache: StatementCache,
    path: Option<PathBuf>,
}

InnerConnection contains a ffi::duckdb_connection...

pub struct InnerConnection {
    pub db: ffi::duckdb_database,
    pub con: ffi::duckdb_connection,
    owned: bool,
}

...which is required to call ffi::duckdb_interrupt:

extern "C" {
    #[doc = "Interrupt running query\n\n connection: The connection to interrupt"]
    pub fn duckdb_interrupt(connection: duckdb_connection);
}

There's no way to call duckdb_interrupt (and other ffi functions like it) with a Connection, as we can't access its fields. Exposing a Connection::interrupt() method would be one way around this.

I'm happy to make the contribution if the maintainers can advise on how you would like this implemented.