@ -9,9 +9,9 @@ namespace NzbDrone.Core.Datastore
{
{
public interface IConnectionStringFactory
public interface IConnectionStringFactory
{
{
string MainDbConnectionString { get ; }
DatabaseConnectionInfo MainDbConnection { get ; }
string LogDbConnectionString { get ; }
DatabaseConnectionInfo LogDbConnection { get ; }
string CacheDbConnectionString { get ; }
DatabaseConnectionInfo CacheDbConnection { get ; }
string GetDatabasePath ( string connectionString ) ;
string GetDatabasePath ( string connectionString ) ;
}
}
@ -23,19 +23,19 @@ namespace NzbDrone.Core.Datastore
{
{
_configFileProvider = configFileProvider ;
_configFileProvider = configFileProvider ;
MainDbConnection String = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresMainDb ) :
MainDbConnection = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresMainDb ) :
GetConnectionString ( appFolderInfo . GetDatabase ( ) ) ;
GetConnectionString ( appFolderInfo . GetDatabase ( ) ) ;
LogDbConnection String = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresLogDb ) :
LogDbConnection = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresLogDb ) :
GetConnectionString ( appFolderInfo . GetLogDatabase ( ) ) ;
GetConnectionString ( appFolderInfo . GetLogDatabase ( ) ) ;
CacheDbConnection String = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresCacheDb ) :
CacheDbConnection = _configFileProvider . PostgresHost . IsNotNullOrWhiteSpace ( ) ? GetPostgresConnectionString ( _configFileProvider . PostgresCacheDb ) :
GetConnectionString ( appFolderInfo . GetCacheDatabase ( ) ) ;
GetConnectionString ( appFolderInfo . GetCacheDatabase ( ) ) ;
}
}
public string MainDbConnectionString { get ; private set ; }
public DatabaseConnectionInfo MainDbConnection { get ; private set ; }
public string LogDbConnectionString { get ; private set ; }
public DatabaseConnectionInfo LogDbConnection { get ; private set ; }
public string CacheDbConnectionString { get ; private set ; }
public DatabaseConnectionInfo CacheDbConnection { get ; private set ; }
public string GetDatabasePath ( string connectionString )
public string GetDatabasePath ( string connectionString )
{
{
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Datastore
return connectionBuilder . DataSource ;
return connectionBuilder . DataSource ;
}
}
private static string GetConnectionString ( string dbPath )
private static DatabaseConnectionInfo GetConnectionString ( string dbPath )
{
{
var connectionBuilder = new SQLiteConnectionStringBuilder
var connectionBuilder = new SQLiteConnectionStringBuilder
{
{
@ -62,21 +62,22 @@ namespace NzbDrone.Core.Datastore
connectionBuilder . Add ( "Full FSync" , true ) ;
connectionBuilder . Add ( "Full FSync" , true ) ;
}
}
return connectionBuilder . ConnectionString ;
return new DatabaseConnectionInfo ( DatabaseType . SQLite , connectionBuilder . ConnectionString ) ;
}
}
private string GetPostgresConnectionString ( string dbName )
private DatabaseConnectionInfo GetPostgresConnectionString ( string dbName )
{
{
var connectionBuilder = new NpgsqlConnectionStringBuilder ( ) ;
var connectionBuilder = new NpgsqlConnectionStringBuilder
{
connectionBuilder . Database = dbName ;
Database = dbName ,
connectionBuilder . Host = _configFileProvider . PostgresHost ;
Host = _configFileProvider . PostgresHost ,
connectionBuilder . Username = _configFileProvider . PostgresUser ;
Username = _configFileProvider . PostgresUser ,
connectionBuilder . Password = _configFileProvider . PostgresPassword ;
Password = _configFileProvider . PostgresPassword ,
connectionBuilder . Port = _configFileProvider . PostgresPort ;
Port = _configFileProvider . PostgresPort ,
connectionBuilder . Enlist = false ;
Enlist = false
} ;
return connectionBuilder . ConnectionString ;
return new DatabaseConnectionInfo ( DatabaseType . PostgreSQL , connectionBuilder . ConnectionString ) ;
}
}
}
}
}
}