mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Goodbye EF!
This commit is contained in:
parent
165600301c
commit
b8fff306bf
16 changed files with 52 additions and 134 deletions
|
@ -1,20 +0,0 @@
|
|||
using System.Data.Common;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
public class LogDbContext : DbContext
|
||||
{
|
||||
public LogDbContext(DbConnection connection)
|
||||
: base(connection, false)
|
||||
{
|
||||
}
|
||||
|
||||
public LogDbContext()
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Log> Logs { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DataTables.Mvc.Core.Helpers;
|
||||
using DataTables.Mvc.Core.Models;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using PetaPoco;
|
||||
|
@ -10,24 +12,20 @@ namespace NzbDrone.Core.Instrumentation
|
|||
public class LogProvider
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
private readonly LogDbContext _logDbContext;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
|
||||
public LogProvider(IDatabase database, LogDbContext logDbContext, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
|
||||
public LogProvider(IDatabase database, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
|
||||
{
|
||||
_database = database;
|
||||
_logDbContext = logDbContext;
|
||||
_diskProvider = diskProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
public IQueryable<Log> GetAllLogs()
|
||||
public List<Log> GetAllLogs()
|
||||
{
|
||||
return _logDbContext.Logs;
|
||||
return _database.Fetch<Log>();
|
||||
}
|
||||
|
||||
public IList<Log> TopLogs(int count)
|
||||
|
@ -44,9 +42,35 @@ namespace NzbDrone.Core.Instrumentation
|
|||
return logs;
|
||||
}
|
||||
|
||||
public Page<Log> GetPagedLogs(int pageNumber, int pageSize)
|
||||
public virtual Page<Log> GetPagedItems(DataTablesPageRequest pageRequest)
|
||||
{
|
||||
return _database.Page<Log>(pageNumber, pageSize, "SELECT * FROM Logs ORDER BY Time DESC");
|
||||
var query = Sql.Builder
|
||||
.Select(@"*")
|
||||
.From("Logs");
|
||||
|
||||
var startPage = (pageRequest.DisplayLength == 0) ? 1 : pageRequest.DisplayStart / pageRequest.DisplayLength + 1;
|
||||
|
||||
if (!string.IsNullOrEmpty(pageRequest.Search))
|
||||
{
|
||||
var whereClause = string.Join(" OR ", SqlBuilderHelper.GetSearchClause(pageRequest));
|
||||
|
||||
if (!string.IsNullOrEmpty(whereClause))
|
||||
query.Append("WHERE " + whereClause, "%" + pageRequest.Search + "%");
|
||||
}
|
||||
|
||||
var orderBy = string.Join(",", SqlBuilderHelper.GetOrderByClause(pageRequest));
|
||||
|
||||
if (!string.IsNullOrEmpty(orderBy))
|
||||
{
|
||||
query.Append("ORDER BY " + orderBy);
|
||||
}
|
||||
|
||||
return _database.Page<Log>(startPage, pageRequest.DisplayLength, query);
|
||||
}
|
||||
|
||||
public virtual long Count()
|
||||
{
|
||||
return _database.Single<long>(@"SELECT COUNT(*) from Logs");
|
||||
}
|
||||
|
||||
public void DeleteAll()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue