diff --git a/src/reader/connection.rs b/src/reader/connection.rs index b97bd553..2d18d641 100644 --- a/src/reader/connection.rs +++ b/src/reader/connection.rs @@ -27,21 +27,9 @@ pub enum ConnectionInfo { /// # Supported Formats /// /// - `duckdb://memory` - DuckDB in-memory database -/// - `duckdb:///absolute/path/file.db` - DuckDB file (absolute path) -/// - `duckdb://relative/file.db` - DuckDB file (relative path) +/// - `duckdb://...` - DuckDB path /// - `postgres://...` - PostgreSQL connection string /// - `sqlite://...` - SQLite file path -/// -/// # Examples -/// -/// ``` -/// use ggsql::reader::connection::{parse_connection_string, ConnectionInfo}; -/// -/// let info = parse_connection_string("duckdb://memory").unwrap(); -/// assert_eq!(info, ConnectionInfo::DuckDBMemory); -/// -/// let info = parse_connection_string("duckdb://data.db").unwrap(); -/// assert_eq!(info, ConnectionInfo::DuckDBFile("data.db".to_string())); /// ``` pub fn parse_connection_string(uri: &str) -> Result { if uri == "duckdb://memory" { @@ -49,14 +37,12 @@ pub fn parse_connection_string(uri: &str) -> Result { } if let Some(path) = uri.strip_prefix("duckdb://") { - // Remove leading slashes for file paths - let cleaned_path = path.trim_start_matches('/'); - if cleaned_path.is_empty() { + if path.is_empty() { return Err(GgsqlError::ReaderError( "DuckDB file path cannot be empty".to_string(), )); } - return Ok(ConnectionInfo::DuckDBFile(cleaned_path.to_string())); + return Ok(ConnectionInfo::DuckDBFile(path.to_string())); } if uri.starts_with("postgres://") || uri.starts_with("postgresql://") { @@ -64,13 +50,12 @@ pub fn parse_connection_string(uri: &str) -> Result { } if let Some(path) = uri.strip_prefix("sqlite://") { - let cleaned_path = path.trim_start_matches('/'); - if cleaned_path.is_empty() { + if path.is_empty() { return Err(GgsqlError::ReaderError( "SQLite file path cannot be empty".to_string(), )); } - return Ok(ConnectionInfo::SQLite(cleaned_path.to_string())); + return Ok(ConnectionInfo::SQLite(path.to_string())); } if let Some(conn_str) = uri.strip_prefix("odbc://") { @@ -107,7 +92,7 @@ mod tests { #[test] fn test_duckdb_file_absolute() { let info = parse_connection_string("duckdb:///tmp/data.db").unwrap(); - assert_eq!(info, ConnectionInfo::DuckDBFile("tmp/data.db".to_string())); + assert_eq!(info, ConnectionInfo::DuckDBFile("/tmp/data.db".to_string())); } #[test] @@ -139,6 +124,12 @@ mod tests { assert_eq!(info, ConnectionInfo::SQLite("data.db".to_string())); } + #[test] + fn test_sqlite_absolute() { + let info = parse_connection_string("sqlite:///tmp/data.db").unwrap(); + assert_eq!(info, ConnectionInfo::SQLite("/tmp/data.db".to_string())); + } + #[test] fn test_empty_duckdb_path() { let result = parse_connection_string("duckdb://");