2021-09-30 01:51:38 +00:00
|
|
|
using SqlKata;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Core;
|
2021-09-30 01:51:38 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
internal class QueryPatchWrapper
|
|
|
|
{
|
|
|
|
private readonly Dictionary<string, object> _dict = new();
|
2021-09-30 01:51:38 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public QueryPatchWrapper With<T>(string columnName, Partial<T> partialValue)
|
|
|
|
{
|
|
|
|
if (partialValue.IsPresent)
|
|
|
|
_dict.Add(columnName, partialValue);
|
2021-09-30 01:51:38 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return this;
|
2021-09-30 01:51:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public Query ToQuery(Query q) => q.AsUpdate(_dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static class SqlKataExtensions
|
|
|
|
{
|
|
|
|
internal static Query ApplyPatch(this Query query, Func<QueryPatchWrapper, QueryPatchWrapper> func)
|
|
|
|
=> func(new QueryPatchWrapper()).ToQuery(query);
|
2021-09-30 01:51:38 +00:00
|
|
|
}
|