mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Marr is almost working.
This commit is contained in:
parent
971053f8a2
commit
ea4f0dbe5f
18 changed files with 300 additions and 126 deletions
|
@ -2,35 +2,35 @@
|
|||
using System.Data;
|
||||
using Marr.Data;
|
||||
using Mono.Data.Sqlite;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public interface IDbFactory
|
||||
{
|
||||
IDatabase Create(string dbPath = null);
|
||||
IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main);
|
||||
}
|
||||
|
||||
public class DbFactory : IDbFactory
|
||||
{
|
||||
private const string MemoryConnectionString = "Data Source=:memory:;Version=3;New=True;";
|
||||
private readonly IMigrationController _migrationController;
|
||||
|
||||
public IDatabase Create(string dbPath = null)
|
||||
public DbFactory(IMigrationController migrationController)
|
||||
{
|
||||
var connectionString = MemoryConnectionString;
|
||||
TableMapping.Map();
|
||||
_migrationController = migrationController;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dbPath))
|
||||
{
|
||||
connectionString = GetConnectionString(dbPath);
|
||||
}
|
||||
public IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main)
|
||||
{
|
||||
var connectionString = GetConnectionString(dbPath);
|
||||
|
||||
MigrationHelper.MigrateToLatest(connectionString, MigrationType.Main);
|
||||
_migrationController.MigrateToLatest(connectionString, migrationType);
|
||||
var dataMapper = new DataMapper(SqliteFactory.Instance, connectionString);
|
||||
return new Database(dataMapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private string GetConnectionString(string dbPath)
|
||||
{
|
||||
return String.Format("Data Source={0};Version=3;", dbPath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue