zeroshade commented on code in PR #3973:
URL: https://github.com/apache/arrow-adbc/pull/3973#discussion_r2854263871
##########
rust/driver_manager/src/lib.rs:
##########
@@ -379,20 +491,118 @@ impl ManagedDatabase {
additional_search_paths: Option<Vec<PathBuf>>,
opts: impl IntoIterator<Item = (<Self as Optionable>::Option,
OptionValue)>,
) -> Result<Self> {
- let (driver, final_uri) = parse_driver_uri(uri)?;
-
- let mut drv = ManagedDriver::load_from_name(
- driver,
+ let profile_provider = FilesystemProfileProvider;
+ Self::from_uri_with_profile_provider(
+ uri,
entrypoint,
version,
load_flags,
additional_search_paths,
- )?;
+ profile_provider,
+ opts,
+ )
+ }
- drv.new_database_with_opts(opts.into_iter().chain(std::iter::once((
- OptionDatabase::Uri,
- OptionValue::String(final_uri.to_string()),
- ))))
+ /// Creates a new database connection from a URI with a custom profile
provider.
+ ///
+ /// This advanced method allows using a custom implementation of
+ /// [`ConnectionProfileProvider`] to load profiles from alternative sources
+ /// (e.g., remote configuration services, encrypted storage, etc.).
+ ///
+ /// # Arguments
+ ///
+ /// * `uri` - The connection URI or profile reference
+ /// * `entrypoint` - Optional driver entrypoint name
+ /// * `version` - ADBC version to use
+ /// * `load_flags` - Flags controlling driver loading behavior
+ /// * `additional_search_paths` - Optional paths to search for drivers or
profiles
+ /// * `profile_provider` - Custom profile provider implementation
+ /// * `opts` - Database options to apply (override profile options)
+ ///
+ /// # Returns
+ ///
+ /// A configured `ManagedDatabase` using the custom profile provider.
+ ///
+ /// # Examples
+ ///
+ /// ```no_run
+ /// use adbc_core::options::{AdbcVersion, OptionDatabase, OptionValue};
+ /// use adbc_driver_manager::ManagedDatabase;
+ /// use
adbc_driver_manager::connection_profiles::FilesystemProfileProvider;
+ /// use adbc_core::LOAD_FLAG_DEFAULT;
+ ///
+ /// let provider = FilesystemProfileProvider;
+ /// let opts = vec![(OptionDatabase::Username,
OptionValue::String("admin".to_string()))];
+ ///
+ /// let db = ManagedDatabase::from_uri_with_profile_provider(
+ /// "profile://my_database",
+ /// None,
+ /// AdbcVersion::V100,
+ /// LOAD_FLAG_DEFAULT,
+ /// None,
+ /// provider,
+ /// opts,
+ /// )?;
+ /// # Ok::<(), adbc_core::error::Error>(())
+ /// ```
+ pub fn from_uri_with_profile_provider(
+ uri: &str,
+ entrypoint: Option<&[u8]>,
+ version: AdbcVersion,
+ load_flags: LoadFlags,
+ additional_search_paths: Option<Vec<PathBuf>>,
+ profile_provider: impl ConnectionProfileProvider,
+ opts: impl IntoIterator<Item = (<Self as Optionable>::Option,
OptionValue)>,
+ ) -> Result<Self> {
+ let mut drv: ManagedDriver;
+ let result = parse_driver_uri(uri)?;
+ match result {
+ SearchResult::DriverUri(driver, final_uri) => {
+ drv = ManagedDriver::load_from_name(
+ driver,
+ entrypoint,
+ version,
+ load_flags,
+ additional_search_paths.clone(),
+ )?;
Review Comment:
that doesn't necessarily work in the case where the profile provides an
`init_fn` though in which case we use `load_static` rather than using a
`SearchHit`. So i'm not sure how your suggestion would work in that case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]