some EloqueraDb cleanup
This commit is contained in:
parent
1671fd1776
commit
5930a15d3a
|
@ -3,6 +3,7 @@ using Eloquera.Client;
|
|||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
|
@ -84,25 +85,26 @@ namespace NzbDrone.Core.Test.Datastore
|
|||
[Test]
|
||||
public void new_objects_should_get_id()
|
||||
{
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
Db.Insert(testSeries);
|
||||
testSeries.Id.Should().NotBe(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_id_when_returned_from_database()
|
||||
{
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
Db.Insert(testSeries);
|
||||
var item = Db.AsQueryable<Series>();
|
||||
|
||||
item.Should().HaveCount(1);
|
||||
item.First().Id.Should().NotBe(0);
|
||||
item.First().Id.Should().BeLessThan(100);
|
||||
item.First().Id.Should().Be(testSeries.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_find_object_by_id()
|
||||
{
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
Db.Insert(testSeries);
|
||||
var item = Db.AsQueryable<Series>().Single(c => c.Id == testSeries.Id);
|
||||
|
||||
item.Id.Should().NotBe(0);
|
||||
|
@ -116,10 +118,8 @@ namespace NzbDrone.Core.Test.Datastore
|
|||
}
|
||||
}
|
||||
|
||||
public class UnknownType
|
||||
public class UnknownType : BaseRepositoryModel
|
||||
{
|
||||
[ID]
|
||||
public string Id;
|
||||
public string Field1 { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
|
@ -13,7 +11,7 @@ namespace NzbDrone.Core.Datastore
|
|||
void Delete(long rootFolderId);
|
||||
}
|
||||
|
||||
public abstract class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : BaseRepositoryModel, new()
|
||||
public class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : BaseRepositoryModel, new()
|
||||
{
|
||||
public BasicRepository(EloqueraDb eloqueraDb)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eloquera.Client;
|
||||
|
@ -20,26 +19,20 @@ namespace NzbDrone.Core.Datastore
|
|||
return _db.Query<T>();
|
||||
}
|
||||
|
||||
public T Insert<T>(T obj)
|
||||
public T Insert<T>(T obj) where T : BaseRepositoryModel
|
||||
{
|
||||
//Todo: need to verify that this is properly setting the ID of T
|
||||
_db.Store(obj);
|
||||
obj.Id = _db.Store(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public long InsertAndGetId<T>(T obj)
|
||||
{
|
||||
return _db.Store(obj);
|
||||
}
|
||||
|
||||
public IList<T> InsertMany<T>(IEnumerable<T> objects)
|
||||
public IList<T> InsertMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel
|
||||
{
|
||||
return DoMany(objects, Insert);
|
||||
}
|
||||
|
||||
public T Update<T>(T obj)
|
||||
{
|
||||
_db.Store(obj);
|
||||
_db.Store(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -53,7 +46,7 @@ namespace NzbDrone.Core.Datastore
|
|||
_db.Delete(obj);
|
||||
}
|
||||
|
||||
public void DeleteMany<T>(IEnumerable<T> objects) where T: new()
|
||||
public void DeleteMany<T>(IEnumerable<T> objects) where T : new()
|
||||
{
|
||||
foreach (var o in objects)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Eloquera.Client;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Model;
|
||||
using PetaPoco;
|
||||
|
||||
|
@ -7,11 +8,8 @@ namespace NzbDrone.Core.Repository
|
|||
{
|
||||
[TableName("Episodes")]
|
||||
[PrimaryKey("EpisodeId", autoIncrement = true)]
|
||||
public class Episode
|
||||
public class Episode:BaseRepositoryModel
|
||||
{
|
||||
[ID]
|
||||
public long Id;
|
||||
|
||||
public int EpisodeId { get; set; }
|
||||
|
||||
public int? TvDbEpisodeId { get; set; }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using Eloquera.Client;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using PetaPoco;
|
||||
|
@ -8,11 +9,8 @@ using PetaPoco;
|
|||
namespace NzbDrone.Core.Repository
|
||||
{
|
||||
[PrimaryKey("SeriesId", autoIncrement = false)]
|
||||
public class Series
|
||||
public class Series:BaseRepositoryModel
|
||||
{
|
||||
[ID]
|
||||
public long Id;
|
||||
|
||||
public virtual int SeriesId { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
|
|
@ -22,8 +22,7 @@ namespace NzbDrone.Core.RootFolders
|
|||
|
||||
public RootFolder Add(RootFolder rootFolder)
|
||||
{
|
||||
rootFolder.Id = EloqueraDb.InsertAndGetId(rootFolder);
|
||||
return rootFolder;
|
||||
return EloqueraDb.Insert(rootFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue