Initial commit
This commit is contained in:
32
Services/DbInitializer.cs
Normal file
32
Services/DbInitializer.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using JsonFlatFileDataStore;
|
||||
using mstdnCats.Models;
|
||||
|
||||
namespace mstdnCats.Services
|
||||
{
|
||||
public class DbInitializer
|
||||
{
|
||||
public static Task<IDocumentCollection<Post>> SetupDb(string _dbname)
|
||||
{
|
||||
// Setup DB
|
||||
IDocumentCollection<Post>? collection = null;
|
||||
|
||||
try
|
||||
{
|
||||
// Initialize DB
|
||||
var store = new DataStore($"{_dbname}.json", minifyJson: false);
|
||||
collection = store.GetCollection<Post>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Task.FromResult<IDocumentCollection<Post>>(null);
|
||||
}
|
||||
|
||||
// Return collection
|
||||
return Task.FromResult(collection);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user