hermes-server/Store/UserStore.cs

50 lines
1.5 KiB
C#
Raw Normal View History

using HermesSocketLibrary.db;
using HermesSocketServer.Models;
using HermesSocketServer.Store.Internal;
namespace HermesSocketServer.Store
{
public class UserStore : AutoSavedStore<string, User>
{
private readonly Database _database;
private readonly Serilog.ILogger _logger;
public UserStore([FromKeyedServices("User")] DatabaseTable table, Database database, Serilog.ILogger logger)
: base(table, database, logger)
{
_database = database;
_logger = logger;
}
public override async Task Load()
{
string sql = "SELECT id, name, email, role, \"ttsDefaultVoice\" FROM \"User\";";
await _database.Execute(sql, new Dictionary<string, object>(), (reader) =>
{
string id = reader.GetString(0);
_store.Add(id, new User()
{
Id = id,
Name = reader.GetString(1),
Email = reader.GetString(2),
Role = reader.GetString(3),
DefaultVoice = reader.GetString(4),
});
});
_logger.Information($"Loaded {_store.Count} users from database.");
}
protected override void OnInitialAdd(string key, User value)
{
}
protected override void OnInitialModify(string key, User value)
{
}
protected override void OnInitialRemove(string key)
{
}
}
}