mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-06 13:57:54 +00:00
move database utils to Database/Utils, create DatabaseMigrator
This commit is contained in:
parent
d633cd4906
commit
3d2435eb2e
7 changed files with 91 additions and 62 deletions
|
|
@ -1,45 +0,0 @@
|
|||
using System.Text;
|
||||
|
||||
using Dapper;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class UpdateQueryBuilder
|
||||
{
|
||||
private readonly QueryBuilder _qb;
|
||||
private readonly DynamicParameters _params = new DynamicParameters();
|
||||
|
||||
private UpdateQueryBuilder(QueryBuilder qb)
|
||||
{
|
||||
_qb = qb;
|
||||
}
|
||||
|
||||
public static UpdateQueryBuilder Insert(string table) => new UpdateQueryBuilder(QueryBuilder.Insert(table));
|
||||
public static UpdateQueryBuilder Update(string table, string condition) => new UpdateQueryBuilder(QueryBuilder.Update(table, condition));
|
||||
public static UpdateQueryBuilder Upsert(string table, string conflictField) => new UpdateQueryBuilder(QueryBuilder.Upsert(table, conflictField));
|
||||
|
||||
public UpdateQueryBuilder WithConstant<T>(string name, T value)
|
||||
{
|
||||
_params.Add(name, value);
|
||||
_qb.Constant(name, $"@{name}");
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdateQueryBuilder With<T>(string columnName, T value)
|
||||
{
|
||||
_params.Add(columnName, value);
|
||||
_qb.Variable(columnName, $"@{columnName}");
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdateQueryBuilder With<T>(string columnName, Partial<T> partialValue)
|
||||
{
|
||||
return partialValue.IsPresent ? With(columnName, partialValue.Value) : this;
|
||||
}
|
||||
|
||||
public (string Query, DynamicParameters Parameters) Build(string suffix = "")
|
||||
{
|
||||
return (_qb.Build(suffix), _params);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue