PgEndpoint.parse constructor
PgEndpoint.parse(
- dynamic url
Parses the most common connection URL formats:
- postgresql://user:password@host:port/dbname
- postgresql://host:port/dbname?username=user&password=pwd
Set ?sslmode=require to force secure SSL connection.
Implementation
factory PgEndpoint.parse(url) {
final uri = url is Uri ? url : Uri.parse(url as String);
final userInfoParts = uri.userInfo.split(':');
final username = userInfoParts.length == 2 ? userInfoParts[0] : null;
final password = userInfoParts.length == 2 ? userInfoParts[1] : null;
return PgEndpoint(
host: uri.host,
port: uri.port,
database: uri.path.substring(1),
username: username ?? uri.queryParameters['username'],
password: password ?? uri.queryParameters['password'],
requireSsl: uri.queryParameters['sslmode'] == 'require',
);
}