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
kay.one fc641baab3 got basic relationships working
added support for embedded documents.
2013-03-25 23:20:18 -07:00

43 lines
1.2 KiB
C#

using System;
using System.Data;
using System.Data.SQLite;
using Marr.Data;
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)
{
SqlMode = SqlModes.Text,
};
return new Database(dataMapper);
}
private string GetConnectionString(string dbPath)
{
return String.Format("Data Source={0};Version=3;", dbPath);
}
}
}