mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 21:54:36 +00:00
Add individual SQL options
This commit is contained in:
parent
2f0fe8641a
commit
fc9d611ba6
2 changed files with 19 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
using BirthdayBot.Data;
|
using BirthdayBot.Data;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -48,10 +49,23 @@ namespace BirthdayBot
|
||||||
DBotsToken = null;
|
DBotsToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlcs = jc["SqlConnectionString"]?.Value<string>();
|
var sqlhost = jc["SqlHost"]?.Value<string>() ?? "localhost"; // Default to localhost
|
||||||
if (string.IsNullOrWhiteSpace(sqlcs))
|
var sqluser = jc["SqlUsername"]?.Value<string>();
|
||||||
throw new Exception("'SqlConnectionString' must be specified.");
|
var sqlpass = jc["SqlPassword"]?.Value<string>();
|
||||||
Database.DBConnectionString = sqlcs;
|
if (string.IsNullOrWhiteSpace(sqluser) || string.IsNullOrWhiteSpace(sqlpass))
|
||||||
|
throw new Exception("'SqlUsername', 'SqlPassword' must be specified.");
|
||||||
|
var csb = new NpgsqlConnectionStringBuilder()
|
||||||
|
{
|
||||||
|
Host = sqlhost,
|
||||||
|
Username = sqluser,
|
||||||
|
Password = sqlpass,
|
||||||
|
// Note: Npgsql connection pooling settings are defined (hardcoded) here.
|
||||||
|
MinPoolSize = 3,
|
||||||
|
MaxPoolSize = 20
|
||||||
|
};
|
||||||
|
var sqldb = jc["SqlDatabase"]?.Value<string>();
|
||||||
|
if (sqldb != null) csb.Database = sqldb; // Optional database setting
|
||||||
|
Database.DBConnectionString = csb.ToString();
|
||||||
|
|
||||||
int? sc = jc["ShardCount"]?.Value<int>();
|
int? sc = jc["ShardCount"]?.Value<int>();
|
||||||
if (!sc.HasValue) ShardCount = 1;
|
if (!sc.HasValue) ShardCount = 1;
|
||||||
|
|
|
@ -9,12 +9,7 @@ namespace BirthdayBot.Data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class Database
|
internal static class Database
|
||||||
{
|
{
|
||||||
private static string _connString;
|
public static string DBConnectionString { get; set; }
|
||||||
public static string DBConnectionString
|
|
||||||
{
|
|
||||||
get => _connString;
|
|
||||||
set => _connString = "Minimum Pool Size=5;Maximum Pool Size=50;Connection Idle Lifetime=30;" + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<NpgsqlConnection> OpenConnectionAsync()
|
public static async Task<NpgsqlConnection> OpenConnectionAsync()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue