1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-29 02:57:15 +02:00
Sonarr/src/NzbDrone.Core/Datastore/Database.cs

55 lines
1.3 KiB
C#
Raw Normal View History

2013-03-25 06:51:32 +03:00
using System;
using Marr.Data;
using NLog;
using NzbDrone.Common.Instrumentation;
2013-03-25 06:51:32 +03:00
namespace NzbDrone.Core.Datastore
{
public interface IDatabase
{
IDataMapper GetDataMapper();
Version Version { get; }
void Vacuum();
2013-03-25 06:51:32 +03:00
}
public class Database : IDatabase
{
2013-11-28 10:52:22 +03:00
private readonly Func<IDataMapper> _datamapperFactory;
2013-03-25 06:51:32 +03:00
2014-12-17 09:12:26 +02:00
private readonly Logger _logger = NzbDroneLogger.GetLogger(typeof(Database));
2013-11-28 10:52:22 +03:00
public Database(Func<IDataMapper> datamapperFactory)
2013-03-25 06:51:32 +03:00
{
2013-11-28 10:52:22 +03:00
_datamapperFactory = datamapperFactory;
2013-03-25 06:51:32 +03:00
}
2013-11-28 10:52:22 +03:00
public IDataMapper GetDataMapper()
2013-05-11 23:06:57 +03:00
{
2013-11-28 10:52:22 +03:00
return _datamapperFactory();
}
public Version Version
{
get
{
2013-11-28 10:52:22 +03:00
var version = _datamapperFactory().ExecuteScalar("SELECT sqlite_version()").ToString();
return new Version(version);
}
}
public void Vacuum()
{
try
{
2014-12-17 09:12:26 +02:00
_logger.Info("Vacuuming database");
2013-11-28 10:52:22 +03:00
_datamapperFactory().ExecuteNonQuery("Vacuum;");
2014-12-17 09:12:26 +02:00
_logger.Info("Database Compressed");
}
catch (Exception e)
{
2014-12-17 09:12:26 +02:00
_logger.Error("An Error occurred while vacuuming database.", e);
}
2013-05-11 23:06:57 +03:00
}
2013-03-25 06:51:32 +03:00
}
}