1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/NzbDrone.Core/Datastore/DbFactory.cs
2013-03-25 23:19:52 -07:00

41 lines
1.0 KiB
C#

using System;
using System.Data;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.Sqlite;
namespace NzbDrone.Core.Datastore
{
public interface IDbFactory
{
IDbConnection Create(string dbPath = null);
}
public class DbFactory : IDbFactory
{
private const string MemoryConnectionString = "Data Source=:memory:;Version=3;New=True;";
static DbFactory()
{
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
}
public IDbConnection Create(string dbPath = null)
{
var connectionString = MemoryConnectionString;
if (!string.IsNullOrWhiteSpace(dbPath))
{
connectionString = GetConnectionString(dbPath);
}
var dbFactory = new OrmLiteConnectionFactory(connectionString);
return dbFactory.Open();
}
private string GetConnectionString(string dbPath)
{
return String.Format("Data Source={0};Version=3;", dbPath);
}
}
}