PluralKit/PluralKit.Core/Database/Repository/ModelRepository.Config.cs
2021-11-30 17:04:42 -05:00

23 lines
764 B
C#

using SqlKata;
namespace PluralKit.Core;
public partial class ModelRepository
{
public Task<SystemConfig> GetSystemConfig(SystemId system, IPKConnection conn = null)
=> _db.QueryFirst<SystemConfig>(conn, new Query("config").Where("system", system));
public async Task<SystemConfig> UpdateSystemConfig(SystemId system, SystemConfigPatch patch, IPKConnection conn = null)
{
var query = patch.Apply(new Query("config").Where("system", system));
var config = await _db.QueryFirst<SystemConfig>(conn, query, "returning *");
_ = _dispatch.Dispatch(system, new UpdateDispatchData
{
Event = DispatchEvent.UPDATE_SETTINGS,
EventData = patch.ToJson()
});
return config;
}
}