Basic support for passing postgresql uri on the commandline

This commit is contained in:
eelke 2025-02-17 18:09:19 +01:00
parent 4b4c95e57e
commit 4caccf1000
11 changed files with 453 additions and 192 deletions

View file

@ -0,0 +1,38 @@
#include "PostgresqlUrlParser.h"
#include <ConnectionConfig.h>
#include <QUrl>
#include <QUrlQuery>
//PostgresqlUrlParser::PostgresqlUrlParser() {}
bool TryParsePostgresqlUrl(const QString &urlString, ConnectionConfig &out)
{
const char* shortPrefix = "postgres";
const char* longPrefix = "postgresql";
auto url = QUrl(urlString, QUrl::StrictMode);
if (url.scheme() != shortPrefix && url.scheme() != longPrefix)
return false;
out.setUser(url.userName());
out.setPassword(url.password());
out.setHost(url.host());
out.setDbname(url.fileName());
out.setPort(url.port());
QUrlQuery query(url.query());
for (auto && param : query.queryItems())
{
if (param.first == "ssl" && param.second == "true") {
out.setSslMode(SslMode::require);
}
else
{
out.setParameter(param.first, param.second);
}
}
return true;
}