Sonarr/NzbDrone.Core/Datastore/EloqueraDb.cs

70 lines
1.3 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-04 00:10:15 +00:00
public T Create<T>(T obj)
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
_db.Store(obj);
return obj;
2013-02-03 22:01:36 +00:00
}
2013-02-04 00:10:15 +00:00
public IList<T> CreateMany<T>(IEnumerable<T> objects)
2013-02-03 22:01:36 +00:00
{
2013-02-04 00:10:15 +00:00
return DoMany(objects, Create);
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-04 00:10:15 +00:00
_db.Store(obj);
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 00:10:15 +00:00
public void Delete<T>(T obj)
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-04 00:10:15 +00:00
public void DeleteMany<T>(IEnumerable<T> objects)
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();
}
}
}