pub fn parse_pg_conn_str(conn_str: &str) -> Result<PgConnParts, OxiSqlError>Expand description
Parse a PostgreSQL connection string into its constituent parts.
Accepts two common formats:
Key-value format (the libpq/tokio-postgres native format):
host=myhost port=5433 dbname=testdb user=admin password=secretUnknown keys are silently ignored. Missing host defaults to
"localhost"; missing port defaults to 5432.
URI format:
postgres://user:password@host:port/dbname
postgresql://host/dbnameThe scheme must be postgres:// or postgresql://.
§Errors
Returns OxiSqlError::Other when:
- A non-empty
portvalue cannot be parsed as au16. - The URI scheme is unrecognised (neither
postgres://norpostgresql://).
§Examples
use oxisql_postgres::parse_pg_conn_str;
let p = parse_pg_conn_str("host=myhost port=5433 dbname=testdb user=admin").unwrap();
assert_eq!(p.host, "myhost");
assert_eq!(p.port, 5433);
assert_eq!(p.dbname, Some("testdb".to_string()));
assert_eq!(p.user, Some("admin".to_string()));