1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/Datastore/DbFactory.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2013-03-24 03:08:23 +03:00
using System;
using System.Data.SQLite;
2013-03-25 06:51:32 +03:00
using Marr.Data;
using Marr.Data.Reflection;
2013-03-25 09:13:53 +03:00
using NzbDrone.Core.Datastore.Migration.Framework;
2013-03-25 06:51:32 +03:00
2013-03-24 03:08:23 +03:00
namespace NzbDrone.Core.Datastore
{
public interface IDbFactory
{
2013-03-25 09:13:53 +03:00
IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main);
2013-03-24 03:08:23 +03:00
}
public class DbFactory : IDbFactory
{
2013-03-25 09:13:53 +03:00
private readonly IMigrationController _migrationController;
2013-03-24 03:08:23 +03:00
static DbFactory()
2013-03-24 03:08:23 +03:00
{
2013-03-25 09:13:53 +03:00
TableMapping.Map();
}
public DbFactory(IMigrationController migrationController)
{
2013-03-25 09:13:53 +03:00
_migrationController = migrationController;
}
2013-03-24 07:56:59 +03:00
2013-03-25 09:13:53 +03:00
public IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main)
{
var connectionString = GetConnectionString(dbPath);
2013-03-24 03:08:23 +03:00
2013-03-25 09:13:53 +03:00
_migrationController.MigrateToLatest(connectionString, migrationType);
var dataMapper = new DataMapper(SQLiteFactory.Instance, connectionString)
2013-03-25 10:36:22 +03:00
{
SqlMode = SqlModes.Text,
};
MapRepository.Instance.ReflectionStrategy = new SimpleReflectionStrategy();
2013-03-25 06:51:32 +03:00
return new Database(dataMapper);
}
2013-03-24 03:08:23 +03:00
private string GetConnectionString(string dbPath)
{
return String.Format("Data Source={0};Version=3;", dbPath);
}
}
}