pub fn validate_connection_string(url: &str) -> Result<()>Expand description
Validate a PostgreSQL connection string
Checks that the connection string has proper format and required components:
- Starts with “postgres://” or “postgresql://”
- Contains user credentials (@ symbol)
- Contains database name (/ separator with at least 3 occurrences)
§Arguments
url- Connection string to validate
§Returns
Returns Ok(()) if the connection string is valid.
§Errors
Returns an error with helpful message if the connection string is:
- Empty or whitespace only
- Missing proper scheme (postgres:// or postgresql://)
- Missing user credentials (@ symbol)
- Missing database name
§Examples
// Valid connection strings
validate_connection_string("postgresql://user:pass@localhost:5432/mydb")?;
validate_connection_string("postgres://user@host/db")?;
// Invalid - will return error
assert!(validate_connection_string("").is_err());
assert!(validate_connection_string("mysql://localhost/db").is_err());