mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-27 10:17:47 +00:00
39 lines
1,017 B
C#
39 lines
1,017 B
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using NzbDrone.Common;
|
|
using ServiceStack.OrmLite;
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
{
|
|
public interface IDbFactory
|
|
{
|
|
IDbConnection Create(string dbPath = null);
|
|
}
|
|
|
|
public class DbFactory : IDbFactory
|
|
{
|
|
private readonly EnvironmentProvider _environmentProvider;
|
|
|
|
public DbFactory(EnvironmentProvider environmentProvider)
|
|
{
|
|
_environmentProvider = environmentProvider;
|
|
}
|
|
|
|
public IDbConnection Create(string dbPath = null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dbPath))
|
|
{
|
|
dbPath = _environmentProvider.GetObjectDbFolder();
|
|
}
|
|
|
|
var dbFactory = new OrmLiteConnectionFactory(GetConnectionString(dbPath));
|
|
return dbFactory.OpenDbConnection();
|
|
}
|
|
|
|
private string GetConnectionString(string dbPath)
|
|
{
|
|
return String.Format("Data Source={0};Version=3;", dbPath);
|
|
}
|
|
}
|
|
}
|