From 0c37952f2990acaa0128988829c48a62f1879813 Mon Sep 17 00:00:00 2001 From: wangfenjin Date: Sat, 30 Sep 2023 16:39:20 +0800 Subject: [PATCH] enable loadable extension --- libduckdb-sys/update_sources.py | 7 ------- src/config.rs | 14 +++++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libduckdb-sys/update_sources.py b/libduckdb-sys/update_sources.py index aeebacff..ffbc7295 100755 --- a/libduckdb-sys/update_sources.py +++ b/libduckdb-sys/update_sources.py @@ -99,10 +99,3 @@ def get_sources(extensions): + '/bindgen_bundled_version.rs" \;', shell=True, ) - -# Remove the extra patch file -os.remove( - os.path.join( - SCRIPT_DIR, "duckdb-sources", "extension", "httpfs", "httpfs_config.py" - ) -) diff --git a/src/config.rs b/src/config.rs index 6e89a734..266963d3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -42,16 +42,28 @@ pub enum DefaultNullOrder { /// duckdb configuration /// Refer to https://github.com/duckdb/duckdb/blob/master/src/main/config.cpp -#[derive(Default)] pub struct Config { config: Option, } +impl Default for Config { + fn default() -> Self { + Config { config: None }.autoloadable_extension(true).unwrap() + } +} + impl Config { pub(crate) fn duckdb_config(&self) -> ffi::duckdb_config { self.config.unwrap_or(std::ptr::null_mut() as ffi::duckdb_config) } + /// enable autoload extensions + pub fn autoloadable_extension(mut self, enabled: bool) -> Result { + self.set("autoinstall_known_extensions", &(enabled as i32).to_string())?; + self.set("autoload_known_extensions", &(enabled as i32).to_string())?; + Ok(self) + } + /// Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE) pub fn access_mode(mut self, mode: AccessMode) -> Result { self.set("access_mode", &mode.to_string())?;