1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00
Sonarr/NzbDrone.Core/Datastore/Connection.cs

59 lines
1.5 KiB
C#
Raw Normal View History

2011-05-24 02:29:14 +03:00
using System;
using System.Data;
2011-06-15 05:31:41 +03:00
using System.Data.SQLite;
2011-05-24 02:29:14 +03:00
using System.IO;
2011-06-14 04:35:44 +03:00
using MvcMiniProfiler.Data;
2011-06-15 05:31:41 +03:00
using PetaPoco;
2011-05-24 02:29:14 +03:00
namespace NzbDrone.Core.Datastore
{
public static class Connection
{
private static readonly DirectoryInfo AppDataPath = new DirectoryInfo(Path.Combine(CentralDispatch.AppPath, "App_Data"));
static Connection()
{
if (!AppDataPath.Exists) AppDataPath.Create();
}
2011-06-04 21:19:22 +03:00
public static string GetConnectionString(string path)
2011-05-24 02:29:14 +03:00
{
2011-06-05 23:01:28 +03:00
return String.Format("Data Source={0};Version=3;Cache Size=30000;", path);
2011-05-24 02:29:14 +03:00
}
2011-06-04 21:19:22 +03:00
public static String MainConnectionString
2011-05-24 02:29:14 +03:00
{
get
{
2011-06-04 21:19:22 +03:00
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.db"));
2011-05-24 02:29:14 +03:00
}
}
2011-06-04 21:19:22 +03:00
public static String LogConnectionString
2011-05-24 02:29:14 +03:00
{
get
{
2011-06-04 21:19:22 +03:00
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.db"));
2011-05-24 02:29:14 +03:00
}
}
2011-06-18 04:46:22 +03:00
2011-06-15 05:31:41 +03:00
public static IDatabase GetPetaPocoDb(string connectionString)
{
MigrationsHelper.Run(connectionString, true);
2011-06-15 05:31:41 +03:00
var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString));
Database.Mapper = new CustomeMapper();
var db = new Database(profileConnection);
if (profileConnection.State != ConnectionState.Open)
profileConnection.Open();
2011-06-15 05:31:41 +03:00
return db;
}
2011-05-24 02:29:14 +03:00
}
}