Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return duckdb extensions #665

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/duckdb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Read hive partitioned datasets, `Config` structure ([#624](https://github.com/stac-utils/stac-rs/pull/624))
- `Client.search_to_arrow_table` ([#634](https://github.com/stac-utils/stac-rs/pull/634))
- Conditionally disable parsing the WKB ([#635](https://github.com/stac-utils/stac-rs/pull/635))
- `Client.extensions` ([#665](https://github.com/stac-utils/stac-rs/pull/665))

### Removed

Expand Down
66 changes: 66 additions & 0 deletions crates/duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ pub struct Query {
pub params: Vec<Value>,
}

/// A DuckDB extension
// TODO implement aliases ... I don't know how vectors work yet 😢
#[derive(Debug)]
pub struct Extension {
/// The extension name.
pub name: String,

/// Is the extension loaded?
pub loaded: bool,

/// Is the extension installed?
pub installed: bool,

/// The path to the extension.
///
/// This might be `(BUILT-IN)` for the core extensions.
pub install_path: Option<String>,

/// The extension description.
pub description: String,

/// The extension version.
pub version: Option<String>,

/// The install mode.
///
/// We don't bother making this an enum, yet.
pub install_mode: Option<String>,

/// Where the extension was installed from.
pub installed_from: Option<String>,
}

impl Client {
/// Creates a new client with no data sources.
///
Expand Down Expand Up @@ -152,6 +185,39 @@ impl Client {
Ok(Client { connection, config })
}

/// Returns a vector of all extensions.
///
/// # Examples
///
/// ```
/// use stac_duckdb::Client;
///
/// let client = Client::new().unwrap();
/// let extensions = client.extensions().unwrap();
/// let spatial = extensions.into_iter().find(|extension| extension.name == "spatial").unwrap();
/// assert!(spatial.loaded);
/// ```
pub fn extensions(&self) -> Result<Vec<Extension>> {
let mut statement = self.connection.prepare(
"SELECT extension_name, loaded, installed, install_path, description, extension_version, install_mode, installed_from FROM duckdb_extensions();",
)?;
let extensions = statement
.query_map([], |row| {
Ok(Extension {
name: row.get("extension_name")?,
loaded: row.get("loaded")?,
installed: row.get("installed")?,
install_path: row.get("install_path")?,
description: row.get("description")?,
version: row.get("extension_version")?,
install_mode: row.get("install_mode")?,
installed_from: row.get("installed_from")?,
})
})?
.collect::<std::result::Result<Vec<_>, duckdb::Error>>()?;
Ok(extensions)
}

/// Returns one or more [stac::Collection] from the items in the stac-geoparquet file.
pub fn collections(&self, href: &str) -> Result<Vec<Collection>> {
let start_datetime= if self.connection.prepare(&format!(
Expand Down
Loading