Skip to content

Instantly share code, notes, and snippets.

@garthk
Created June 27, 2016 01:55
Show Gist options
  • Save garthk/c38702fb73162e409c9ae8f428faf087 to your computer and use it in GitHub Desktop.
Save garthk/c38702fb73162e409c9ae8f428faf087 to your computer and use it in GitHub Desktop.
simplistic PostgreSQL URL parser
function pgConfig(url) {
const config = {};
let { auth, hostname, port, pathname, query } = parse(url);
let { poolSize, poolIdleTimeout } = (query || {});
if (auth) {
let [user, password] = auth.split(':');
config.user = user;
config.password = password;
}
if (hostname) {
config.host = hostname;
}
if (port) {
config.port = parseInt(port, 10);
}
if (pathname) {
config.database = pathname.slice(1);
} else {
config.database = 'wfs';
}
if (poolSize) {
(config as any).poolSize = poolSize;
}
if (poolSize) {
(config as any).poolIdleTimeout = poolIdleTimeout;
}
return config;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment