mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Remove DB and Directory settings out of the BTCPayServerOptions (#2168)
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BTCPayServer.Abstractions.Models
|
||||
{
|
||||
public class DatabaseOptions
|
||||
{
|
||||
public DatabaseOptions(DatabaseType type, string connString)
|
||||
public DatabaseOptions(IConfiguration conf, string dataDir)
|
||||
{
|
||||
DatabaseType = type;
|
||||
ConnectionString = connString;
|
||||
var postgresConnectionString = conf["postgres"];
|
||||
var mySQLConnectionString = conf["mysql"];
|
||||
var sqliteFileName = conf["sqlitefile"];
|
||||
|
||||
if (!string.IsNullOrEmpty(postgresConnectionString))
|
||||
{
|
||||
DatabaseType = DatabaseType.Postgres;
|
||||
ConnectionString = postgresConnectionString;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(mySQLConnectionString))
|
||||
{
|
||||
DatabaseType = DatabaseType.MySQL;
|
||||
ConnectionString = mySQLConnectionString;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(sqliteFileName))
|
||||
{
|
||||
var connStr = "Data Source=" + (Path.IsPathRooted(sqliteFileName)
|
||||
? sqliteFileName
|
||||
: Path.Combine(dataDir, sqliteFileName));
|
||||
|
||||
DatabaseType = DatabaseType.Sqlite;
|
||||
ConnectionString = sqliteFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("No database option was configured.");
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseType DatabaseType { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user