Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
11 changes: 11 additions & 0 deletions crates/duckdb/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl Config {
Ok(self)
}

/// Metadata from DuckDB callers
pub fn custom_user_agent(mut self, custom_user_agent: &str) -> Result<Config> {
self.set("custom_user_agent", custom_user_agent)?;
Ok(self)
}

/// The order type used when none is specified ([ASC] or DESC)
pub fn default_order(mut self, order: DefaultOrder) -> Result<Config> {
self.set("default_order", &order.to_string())?;
Expand Down Expand Up @@ -190,6 +196,7 @@ mod test {
.enable_object_cache(false)?
.enable_autoload_extension(true)?
.allow_unsigned_extensions()?
.custom_user_agent("test_user_agent")?
.max_memory("2GB")?
.threads(4)?
.with("preserve_insertion_order", "true")?;
Expand All @@ -215,6 +222,10 @@ mod test {
assert!(iter.next().unwrap().is_none());
assert_eq!(iter.next(), None);

let user_agent: Result<String> = db.query_row("PRAGMA USER_AGENT", [], |row| row.get(0));
let user_agent = user_agent.unwrap();
assert!(&user_agent.ends_with("rust test_user_agent"));

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions crates/duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ impl Connection {
}

let c_path = path_to_cstring(path.as_ref())?;
let config = config.with("duckdb_api", "rust").unwrap();
InnerConnection::open_with_flags(&c_path, config).map(|db| Connection {
db: RefCell::new(db),
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
Expand Down