mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-06 05:47:53 +00:00
refactor: add SqlKata for SQL generation, move connection handling into ModelRepository
This commit is contained in:
parent
6251d29abb
commit
92e45a07ff
60 changed files with 806 additions and 640 deletions
28
PluralKit.Core/Database/Utils/QueryPatchWrapper.cs
Normal file
28
PluralKit.Core/Database/Utils/QueryPatchWrapper.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
internal class QueryPatchWrapper
|
||||
{
|
||||
private Dictionary<string, object> _dict = new();
|
||||
|
||||
public QueryPatchWrapper With<T>(string columnName, Partial<T> partialValue)
|
||||
{
|
||||
if (partialValue.IsPresent)
|
||||
_dict.Add(columnName, partialValue);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue