confighantering. connection t postgres. test av import
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Bibblan.Business.Services;
|
||||
using Bibblan.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace Bibblan.Controllers
|
||||
{
|
||||
@@ -9,8 +11,13 @@ namespace Bibblan.Controllers
|
||||
public class CalibreController : ControllerBase
|
||||
{
|
||||
CalibreService _service;
|
||||
public CalibreController(CalibreService service) {
|
||||
PostgresCalibreContext _postgresContext;
|
||||
SqliteCalibreContext _sqliteContext;
|
||||
|
||||
public CalibreController(CalibreService service, SqliteCalibreContext sqliteContext, PostgresCalibreContext postgresContext) {
|
||||
_service = service;
|
||||
_postgresContext = postgresContext;
|
||||
_sqliteContext = sqliteContext;
|
||||
}
|
||||
|
||||
[HttpGet("books")]
|
||||
@@ -27,5 +34,278 @@ namespace Bibblan.Controllers
|
||||
return File(bytes, "image/jpeg", true);
|
||||
}
|
||||
|
||||
[HttpGet("dump")]
|
||||
public IActionResult Dump()
|
||||
{
|
||||
//var e = _postgresContext.Database.EnsureCreated();
|
||||
//var script = _postgresContext.Database.GenerateCreateScript();
|
||||
// _postgresContext.Database.ExecuteSqlRaw(script);
|
||||
|
||||
var books = 1;// DumpBooks();
|
||||
var auhtors = 1;// DumpAuthors();
|
||||
var comments = 1;// DumpComments();
|
||||
var data = 1;// DumpData();
|
||||
var identifiers = 1;// DumpIdentifiers();
|
||||
var languages = 1;// DumpLanguages();
|
||||
var publishers = 1;// DumpPublishers();
|
||||
var ratings = 1;// DumpRatings();
|
||||
var series = 1;// DumpSeries();
|
||||
var tags = 1;// DumpTags();
|
||||
|
||||
var ba = 1;// Dumpa(_postgresContext, _sqliteContext.BooksAuthorsLink.OrderBy(x => x.Id), _postgresContext.BooksAuthorsLink);
|
||||
var bl = 1;// Dumpa(_postgresContext, _sqliteContext.BooksLanguagesLink.OrderBy(x => x.Id), _postgresContext.BooksLanguagesLink);
|
||||
var bp = 1;// Dumpa(_postgresContext, _sqliteContext.BooksPublishersLink.OrderBy(x => x.Id), _postgresContext.BooksPublishersLink);
|
||||
var br = 1;// Dumpa(_postgresContext, _sqliteContext.BooksRatingsLink.OrderBy(x => x.Id), _postgresContext.BooksRatingsLink);
|
||||
var bs = 1;// Dumpa(_postgresContext, _sqliteContext.BooksSeriesLink.OrderBy(x => x.Id), _postgresContext.BooksSeriesLink);
|
||||
var bt = 1;// Dumpa(_postgresContext, _sqliteContext.BooksTagsLink.OrderBy(x => x.Id), _postgresContext.BooksTagsLink);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
books,
|
||||
auhtors,
|
||||
comments,
|
||||
data,
|
||||
identifiers,
|
||||
languages,
|
||||
publishers,
|
||||
ratings,
|
||||
series,
|
||||
tags,
|
||||
links = new
|
||||
{
|
||||
ba,
|
||||
bl,
|
||||
bp,
|
||||
br,
|
||||
bs,
|
||||
bt
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int Dumpa<T>(DbContext toContext, IQueryable<T> from, DbSet<T> to)
|
||||
where T : class
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var records = from.Skip(current).Take(step);
|
||||
done = records.Count() == 0;
|
||||
foreach (var record in records)
|
||||
{
|
||||
to.Add(record);
|
||||
}
|
||||
toContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
|
||||
}
|
||||
|
||||
private int DumpBooks() {
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var books = _sqliteContext.Books.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = books.Count() == 0;
|
||||
foreach (var book in books)
|
||||
{
|
||||
_postgresContext.Books.Add(book);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpAuthors()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var authors = _sqliteContext.Authors.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = authors.Count() == 0;
|
||||
foreach (var author in authors)
|
||||
{
|
||||
_postgresContext.Authors.Add(author);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpComments()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var comments = _sqliteContext.Comments.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = comments.Count() == 0;
|
||||
foreach (var comment in comments)
|
||||
{
|
||||
_postgresContext.Comments.Add(comment);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpData()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var data = _sqliteContext.Data.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = data.Count() == 0;
|
||||
foreach (var d in data)
|
||||
{
|
||||
_postgresContext.Data.Add(d);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpIdentifiers()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var identifiers = _sqliteContext.Identifiers.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = identifiers.Count() == 0;
|
||||
foreach (var id in identifiers)
|
||||
{
|
||||
_postgresContext.Identifiers.Add(id);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpLanguages()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var languages = _sqliteContext.Languages.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = languages.Count() == 0;
|
||||
foreach (var lang in languages)
|
||||
{
|
||||
_postgresContext.Languages.Add(lang);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpPublishers()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var publishers = _sqliteContext.Publishers.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = publishers.Count() == 0;
|
||||
foreach (var pub in publishers)
|
||||
{
|
||||
if(pub.Sort == null)
|
||||
{
|
||||
pub.Sort = pub.Name;
|
||||
}
|
||||
_postgresContext.Publishers.Add(pub);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpRatings()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var ratings = _sqliteContext.Ratings.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = ratings.Count() == 0;
|
||||
foreach (var rating in ratings)
|
||||
{
|
||||
_postgresContext.Ratings.Add(rating);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpSeries()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var series = _sqliteContext.Series.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = series.Count() == 0;
|
||||
foreach (var ser in series)
|
||||
{
|
||||
_postgresContext.Series.Add(ser);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private int DumpTags()
|
||||
{
|
||||
var current = 0;
|
||||
int step = 100;
|
||||
|
||||
var done = false;
|
||||
while (!done)
|
||||
{
|
||||
var tags = _sqliteContext.Tags.OrderBy(b => b.Id).Skip(current).Take(step);
|
||||
done = tags.Count() == 0;
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
_postgresContext.Tags.Add(tag);
|
||||
}
|
||||
_postgresContext.SaveChanges();
|
||||
current += step;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user