37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
|
|
using Npgsql;
|
|||
|
|
|
|||
|
|
namespace pgLabII.PgUtils.ConnectionStrings;
|
|||
|
|
|
|||
|
|
public sealed class ConnectionDescriptorBuilder
|
|||
|
|
{
|
|||
|
|
private List<HostEndpoint> Hosts { get; } = [];
|
|||
|
|
public string? Database { get; set; }
|
|||
|
|
public string? Username { get; set; }
|
|||
|
|
public string? Password { get; set; }
|
|||
|
|
public SslMode? SslMode { get; set; }
|
|||
|
|
public string? ApplicationName { get; set; }
|
|||
|
|
public int? TimeoutSeconds { get; set; }
|
|||
|
|
public Dictionary<string, string> Properties { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|||
|
|
|
|||
|
|
public void AddHost(string host, ushort? port)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrWhiteSpace(host)) return;
|
|||
|
|
Hosts.Add(new HostEndpoint { Host = host.Trim(), Port = port });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public ConnectionDescriptor Build()
|
|||
|
|
{
|
|||
|
|
return new ConnectionDescriptor
|
|||
|
|
{
|
|||
|
|
Hosts = Hosts,
|
|||
|
|
Database = Database,
|
|||
|
|
Username = Username,
|
|||
|
|
Password = Password,
|
|||
|
|
SslMode = SslMode,
|
|||
|
|
ApplicationName = ApplicationName,
|
|||
|
|
TimeoutSeconds = TimeoutSeconds,
|
|||
|
|
Properties = Properties
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|