1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 01:11:43 +00:00
Radarr/NzbDrone.Core/Datastore/EloqueraDb.cs

70 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-04 01:27:34 +00:00
public T Insert<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 01:27:34 +00:00
public IList<T> InsertMany<T>(IEnumerable<T> objects)
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-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
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-04 04:18:59 +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();
}
}
}