Skip to content

Commit

Permalink
add version function (#133)
Browse files Browse the repository at this point in the history
Change-Id: Iddb66c3bfb3f4f2948ce51fed4586ac24160aad5
  • Loading branch information
wangfenjin authored Mar 10, 2023
1 parent 3bc8567 commit b8e6bb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ members = ["libduckdb-sys"]
[features]
default = []
bundled = ["libduckdb-sys/bundled"]
httpfs = ["libduckdb-sys/httpfs"]
json = ["libduckdb-sys/json"]
parquet = ["libduckdb-sys/parquet"]
httpfs = ["libduckdb-sys/httpfs", "bundled"]
json = ["libduckdb-sys/json", "bundled"]
parquet = ["libduckdb-sys/parquet", "bundled"]
extensions-full = ["httpfs", "json", "parquet"]

buildtime_bindgen = ["libduckdb-sys/buildtime_bindgen"]
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ impl Connection {
path: self.path.clone(),
})
}

/// Returns the version of the DuckDB library
pub fn version(&self) -> Result<String> {
self.query_row("PRAGMA version", [], |row| row.get(0))
}
}

impl fmt::Debug for Connection {
Expand Down Expand Up @@ -1266,4 +1271,14 @@ mod test {
assert_eq!(DatabaseName::Attached("abc").to_string(), "abc");
Ok(())
}

#[cfg(feature = "bundled")]
#[test]
fn test_version() -> Result<()> {
let db = checked_memory_handle();
const VERSION: &str = env!("CARGO_PKG_VERSION");
let version = db.version()?;
assert_eq!(version, VERSION);
Ok(())
}
}

0 comments on commit b8e6bb1

Please sign in to comment.