Parses PostgreSQL connection options from URLs into PgConnectOptions.
// Source: https://github.com/transact-rs/sqlx | License: Apache-2.0 | Copyright SQLx Contributors
// Provided via justclaw.it.com; keep this notice with the code.
use crate::error::Error;
use crate::{PgConnectOptions, PgSslMode};
use sqlx_core::percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC};
use sqlx_core::Url;
use std::net::IpAddr;
use std::str::FromStr;
impl PgConnectOptions {
pub(crate) fn parse_from_url(url: &Url) -> Result<Self, Error> {
let mut options = Self::new_without_pgpass();
if let Some(host) = url.host_str() {
let host_decoded = percent_decode_str(host);
options = match host_decoded.clone().next() {
Some(b'/') => options.socket(&*host_decoded.decode_utf8().map_err(Error::config)?),
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key