Skip to main content

db_name

Function db_name 

Source
pub fn db_name(url: &str) -> Option<String>
Expand description

Extract the database name from a postgres connection URL.

Format: postgresql://[user[:password]@][host][:port][/dbname][?params].

The query string is stripped before locating the db-name separator: a unix-socket URL carries a filesystem path in ?host=/var/run/postgresql, so a naive rsplit_once('/') would latch onto the last / in that path and return garbage such as postgresql&port=5433 instead of the real db name.

Returns None when the URL carries no path segment (e.g. postgresql://user@host), so callers can fall back to a default database.