Lidarr/NzbDrone.Core/Datastore/DbFactory.cs

39 lines
986 B
C#
Raw Normal View History

2013-03-24 00:08:23 +00:00
using System;
using System.Data;
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));
2013-03-24 04:16:00 +00:00
return dbFactory.Open();
2013-03-24 00:08:23 +00:00
}
private string GetConnectionString(string dbPath)
{
return String.Format("Data Source={0};Version=3;", dbPath);
}
}
}