1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-01-25 11:13:39 +02:00

67 lines
1.8 KiB
C#
Raw Normal View History

2011-05-23 16:29:14 -07:00
using System;
using System.Data;
using System.Data.Common;
2011-06-22 23:56:17 -07:00
using System.Data.SqlServerCe;
2011-05-23 16:29:14 -07:00
using System.IO;
2011-06-13 18:35:44 -07:00
using MvcMiniProfiler.Data;
2011-06-14 19:31:41 -07:00
using PetaPoco;
2011-05-23 16:29:14 -07: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();
Database.Mapper = new CustomeMapper();
2011-05-23 16:29:14 -07:00
}
2011-06-04 11:19:22 -07:00
public static string GetConnectionString(string path)
2011-05-23 16:29:14 -07:00
{
2011-06-22 23:56:17 -07:00
//return String.Format("Data Source={0};Version=3;Cache Size=30000;Pooling=true;Default Timeout=2", path);
return String.Format("Data Source={0}", path);
2011-05-23 16:29:14 -07:00
}
2011-06-04 11:19:22 -07:00
public static String MainConnectionString
2011-05-23 16:29:14 -07:00
{
get
{
2011-06-22 23:56:17 -07:00
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.sdf"));
2011-05-23 16:29:14 -07:00
}
}
2011-06-04 11:19:22 -07:00
public static String LogConnectionString
2011-05-23 16:29:14 -07:00
{
get
{
2011-06-22 23:56:17 -07:00
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.sdf"));
2011-05-23 16:29:14 -07:00
}
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
2011-06-14 19:31:41 -07:00
{
MigrationsHelper.Run(connectionString, true);
2011-06-22 23:56:17 -07:00
var sqliteConnection = new SqlCeConnection(connectionString);
DbConnection connection = sqliteConnection;
2011-06-22 23:56:17 -07:00
if (profiled)
{
connection = ProfiledDbConnection.Get(sqliteConnection);
}
var db = new Database(connection);
db.ForceDateTimesToUtc = false;
if (connection.State != ConnectionState.Open)
connection.Open();
2011-06-14 19:31:41 -07:00
return db;
}
2011-05-23 16:29:14 -07:00
}
}