You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/NzbDrone.Core/Datastore/DbFactory.cs

40 lines
1.1 KiB

using System;
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, MigrationType migrationType = MigrationType.Main);
}
public class DbFactory : IDbFactory
{
private readonly IMigrationController _migrationController;
public DbFactory(IMigrationController migrationController)
{
TableMapping.Map();
_migrationController = migrationController;
}
public IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main)
{
var connectionString = GetConnectionString(dbPath);
_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);
}
}
}