pub struct Connection {
pub cache: RefCell<CacheManager>,
/* private fields */
}Expand description
Wraps a DuckDB connection and registers parquet files as views.
Uses schema introspection to adapt views dynamically:
- CSV VARCHAR columns are auto-detected and converted to arrays
- Wide-format legalities are auto-UNPIVOTed to (uuid, format, status) rows
Fields§
§cache: RefCell<CacheManager>The cache manager used to download/locate data files.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(cache: CacheManager) -> Result<Self>
pub fn new(cache: CacheManager) -> Result<Self>
Create a connection backed by the given cache.
Opens an in-memory DuckDB database.
Sourcepub fn ensure_views(&self, views: &[&str]) -> Result<()>
pub fn ensure_views(&self, views: &[&str]) -> Result<()>
Ensure one or more views are registered, downloading data if needed.
Sourcepub fn execute(
&self,
sql: &str,
params: &[String],
) -> Result<Vec<HashMap<String, Value>>>
pub fn execute( &self, sql: &str, params: &[String], ) -> Result<Vec<HashMap<String, Value>>>
Execute SQL and return results as a Vec of HashMaps.
Each row is represented as a HashMap<String, serde_json::Value>.
Automatically converts DuckDB types to serde_json::Value.
Sourcepub fn execute_into<T: DeserializeOwned>(
&self,
sql: &str,
params: &[String],
) -> Result<Vec<T>>
pub fn execute_into<T: DeserializeOwned>( &self, sql: &str, params: &[String], ) -> Result<Vec<T>>
Execute SQL and deserialize each row into type T.
First executes the query as HashMap rows, then deserializes each
row using serde_json.
Sourcepub fn execute_scalar(
&self,
sql: &str,
params: &[String],
) -> Result<Option<Value>>
pub fn execute_scalar( &self, sql: &str, params: &[String], ) -> Result<Option<Value>>
Execute SQL and return the first column of the first row.
Returns None if the result set is empty.
Sourcepub fn register_table_from_ndjson(
&self,
table_name: &str,
ndjson_path: &str,
) -> Result<()>
pub fn register_table_from_ndjson( &self, table_name: &str, ndjson_path: &str, ) -> Result<()>
Create a DuckDB table from a newline-delimited JSON file.
More memory-efficient than loading data into a Rust structure first, since data is streamed from disk by DuckDB.
Sourcepub fn reset_views(&self)
pub fn reset_views(&self)
Clear all registered views so they will be re-created on next access.
Sourcepub fn raw(&self) -> &DuckDbConnection
pub fn raw(&self) -> &DuckDbConnection
Access the underlying DuckDB connection for advanced usage.