Skip to main content

winterbaume_sqlengine_duckdb/
lib.rs

1mod athena;
2mod exec;
3mod redshift;
4
5use std::sync::{Arc, Mutex};
6
7pub use athena::DuckDbAthenaQueryBackend;
8pub use duckdb::{Connection, Error as DuckDbError, Result as DuckDbResult};
9pub use redshift::DuckDbRedshiftQueryBackend;
10
11/// Open a DuckDB database and wrap it in the `Arc<Mutex<Connection>>` shape
12/// that [`DuckDbAthenaQueryBackend`] and [`DuckDbRedshiftQueryBackend`] both
13/// take, so callers can share a single database between the two services.
14///
15/// `path` is either `:memory:` (or empty) for an in-memory database, or a
16/// filesystem path to a DuckDB file (created if missing).
17pub fn open_database(path: &str) -> DuckDbResult<Arc<Mutex<Connection>>> {
18    let conn = if path.is_empty() || path == ":memory:" {
19        Connection::open_in_memory()?
20    } else {
21        Connection::open(path)?
22    };
23    Ok(Arc::new(Mutex::new(conn)))
24}