sonarr-repo-only/NzbDrone.Core/Datastore/EloqueraDb.cs

68 lines
1.4 KiB
C#
Raw Normal View History

2013-02-03 22:01:36 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using Eloquera.Client;
namespace NzbDrone.Core.Datastore
{
public class EloqueraDb : IDisposable
{
2013-02-04 00:10:15 +00:00
private readonly DB _db;
2013-02-03 22:01:36 +00:00
public EloqueraDb(DB db)
{
_db = db;
}
2013-02-04 00:10:15 +00:00
public IEnumerable<T> AsQueryable<T>()
2013-02-03 22:01:36 +00:00
{
return _db.Query<T>();
}
2013-02-13 01:25:32 +00:00
public T Insert<T>(T obj) where T : BaseRepositoryModel
2013-02-03 22:01:36 +00:00
{
2013-02-13 01:25:32 +00:00
obj.Id = _db.Store(obj);
2013-02-04 00:10:15 +00:00
return obj;
2013-02-03 22:01:36 +00:00
}
2013-02-13 01:25:32 +00:00
public IList<T> InsertMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel
2013-02-03 22:01:36 +00:00
{
2013-02-04 01:27:34 +00:00
return DoMany(objects, Insert);
2013-02-03 22:01:36 +00:00
}
2013-02-04 00:10:15 +00:00
public T Update<T>(T obj)
2013-02-03 22:01:36 +00:00
{
2013-02-13 01:25:32 +00:00
_db.Store(obj);
2013-02-04 00:10:15 +00:00
return obj;
2013-02-03 22:01:36 +00:00
}
2013-02-04 00:10:15 +00:00
public IList<T> UpdateMany<T>(IEnumerable<T> objects)
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
return DoMany(objects, Update);
2013-02-03 22:01:36 +00:00
}
2013-02-04 04:18:59 +00:00
public void Delete<T>(T obj) where T : new()
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
_db.Delete(obj);
2013-02-03 22:01:36 +00:00
}
2013-02-13 01:25:32 +00:00
public void DeleteMany<T>(IEnumerable<T> objects) where T : new()
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
foreach (var o in objects)
{
Delete(o);
}
2013-02-03 22:01:36 +00:00
}
2013-02-04 00:10:15 +00:00
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function)
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
return objects.Select(function).ToList();
2013-02-03 22:01:36 +00:00
}
public void Dispose()
{
_db.Dispose();
}
}
}