Add redshift (and DigitalOcean Managed DB) compatibility and start using a string building to create the sql connection string

This commit is contained in:
runebaas 2020-06-20 03:05:51 +02:00
parent a4b914d576
commit d9f8e9a80e
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 28 additions and 3 deletions

View file

@ -37,7 +37,8 @@ namespace Geekbot.net.Database
Username = _runParameters.DbUser,
Password = _runParameters.DbPassword,
RequireSsl = _runParameters.DbSsl,
TrustServerCertificate = _runParameters.DbTrustCert
TrustServerCertificate = _runParameters.DbTrustCert,
RedshiftCompatibility = _runParameters.DbRedshiftCompatibility
});
}
}

View file

@ -1,4 +1,6 @@
namespace Geekbot.net.Database
using System.Text;
namespace Geekbot.net.Database
{
public class SqlConnectionString
{
@ -9,11 +11,29 @@
public string Password { get; set; }
public bool RequireSsl { get; set; }
public bool TrustServerCertificate { get; set; }
public bool RedshiftCompatibility { get; set; }
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("Application Name=Geekbot;");
sb.Append($"Host={Host};");
sb.Append($"Port={Port};");
sb.Append($"Database={Database};");
sb.Append($"Username={Username};");
sb.Append($"Password={Password};");
var sslMode = RequireSsl ? "Require" : "Prefer";
return $"ApplicationName=Geekbot;Server={Host};Port={Port};Database={Database};Uid={Username};Pwd={Password};SSLMode={sslMode};TrustServerCertificate={TrustServerCertificate.ToString()};";
sb.Append($"SSL Mode={sslMode};");
sb.Append($"Trust Server Certificate={TrustServerCertificate.ToString()};");
if (RedshiftCompatibility)
{
sb.Append("Server Compatibility Mode=Redshift");
}
return sb.ToString();
}
}
}