Updated lots of stuff, got multi scrape working, need to test not-nullable chapter novel ids with our current model, now supports sqlite and postgres concurrently (and easy add more), need to get it deployed/do auth
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System.Reflection;
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NuGet.Configuration;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
@@ -30,7 +31,22 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
||||
return entity;
|
||||
}
|
||||
|
||||
public virtual async Task<TEntityType> Upsert(TEntityType entity)
|
||||
public virtual async Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true)
|
||||
{
|
||||
var newEntities = new List<TEntityType>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
newEntities.Add(await Upsert(entity, false));
|
||||
}
|
||||
|
||||
if (saveAfter)
|
||||
{
|
||||
await DbContext.SaveChangesAsync();
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
|
||||
public virtual async Task<TEntityType> Upsert(TEntityType entity, bool saveAfter=true)
|
||||
{
|
||||
bool exists = await DbContext.Set<TEntityType>().ContainsAsync(entity);
|
||||
if (!exists)
|
||||
@@ -40,10 +56,16 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
||||
else
|
||||
{
|
||||
var dbEntry = await GetIncluded(entity);
|
||||
DbContext.Entry(dbEntry).CurrentValues.SetValues(entity);
|
||||
entity.DateCreated = dbEntry.DateCreated;
|
||||
var entry = DbContext.Entry(dbEntry);
|
||||
entry.CurrentValues.SetValues(entity);
|
||||
entity = dbEntry;
|
||||
}
|
||||
|
||||
await DbContext.SaveChangesAsync();
|
||||
if (saveAfter)
|
||||
{
|
||||
await DbContext.SaveChangesAsync();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user