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