2021-12-18 11:18:35 +00:00
|
|
|
|
using LiteDB;
|
|
|
|
|
using LiteDB.Async;
|
2021-12-31 17:48:04 +00:00
|
|
|
|
using PettingZoo.Core.Settings;
|
2021-12-18 11:18:35 +00:00
|
|
|
|
|
|
|
|
|
namespace PettingZoo.Settings.LiteDB
|
|
|
|
|
{
|
|
|
|
|
public class BaseLiteDBRepository
|
|
|
|
|
{
|
|
|
|
|
private readonly string databaseFilename;
|
|
|
|
|
|
2021-12-20 10:51:28 +00:00
|
|
|
|
protected static readonly BsonMapper Mapper = new()
|
|
|
|
|
{
|
|
|
|
|
EmptyStringToNull = false
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-18 11:18:35 +00:00
|
|
|
|
|
|
|
|
|
public BaseLiteDBRepository(string databaseName)
|
|
|
|
|
{
|
2021-12-31 17:48:04 +00:00
|
|
|
|
databaseFilename = Path.Combine(PettingZooPaths.AppDataRoot, $"{databaseName}.litedb");
|
2021-12-18 11:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected ILiteDatabaseAsync GetDatabase()
|
|
|
|
|
{
|
2021-12-20 10:51:28 +00:00
|
|
|
|
return new LiteDatabaseAsync(databaseFilename, Mapper);
|
2021-12-18 11:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|