feat: use sqlkata for a few more queries
This commit is contained in:
parent
8a727c6e80
commit
b2e4ff38e3
@ -56,10 +56,10 @@ internal partial class Database: IDatabase
|
||||
return await conn.ExecuteAsync(query.Sql + $" {extraSql}", query.NamedBindings);
|
||||
}
|
||||
|
||||
public async Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "")
|
||||
public async Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "", bool messages = false)
|
||||
{
|
||||
var query = _compiler.Compile(q);
|
||||
using var conn = await Obtain();
|
||||
using var conn = await Obtain(messages);
|
||||
using (_metrics.Measure.Timer.Time(CoreMetrics.DatabaseQuery, new MetricTags("Query", queryName)))
|
||||
return await conn.QueryFirstOrDefaultAsync<T>(query.Sql + $" {extraSql}", query.NamedBindings);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public interface IDatabase
|
||||
[CallerMemberName] string queryName = "");
|
||||
|
||||
Task<T> QueryFirst<T>(string q, object param = null, [CallerMemberName] string queryName = "", bool messages = false);
|
||||
Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
||||
Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "", bool messages = false);
|
||||
|
||||
Task<T> QueryFirst<T>(IPKConnection? conn, Query q, string extraSql = "",
|
||||
[CallerMemberName] string queryName = "");
|
||||
|
@ -7,7 +7,7 @@ namespace PluralKit.Core;
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public async Task<ulong?> GetDmChannel(ulong id)
|
||||
=> await _db.Execute(c => c.QueryFirstOrDefaultAsync<ulong?>("select dm_channel from accounts where uid = @id", new { id = id }));
|
||||
=> await _db.QueryFirst<ulong?>(new Query("accounts").Select("dm_channel").Where("uid", id));
|
||||
|
||||
public async Task<bool> GetAutoproxyEnabled(ulong id)
|
||||
=> await _db.QueryFirst<bool>(new Query("accounts").Select("allow_autoproxy").Where("uid", id));
|
||||
|
@ -23,14 +23,8 @@ public partial class ModelRepository
|
||||
return _db.ExecuteQuery(query, "on conflict do nothing", messages: true);
|
||||
}
|
||||
|
||||
public async Task<PKMessage?> GetMessage(ulong id)
|
||||
{
|
||||
return await _db.QueryFirst<PKMessage?>(
|
||||
"select * from messages where mid = @Id",
|
||||
new { Id = id },
|
||||
messages: true
|
||||
);
|
||||
}
|
||||
public Task<PKMessage?> GetMessage(ulong id)
|
||||
=> _db.QueryFirst<PKMessage?>(new Query("messages").Where("mid", id), messages: true);
|
||||
|
||||
public async Task<FullMessage?> GetFullMessage(ulong id)
|
||||
{
|
||||
|
@ -1,11 +1,10 @@
|
||||
using Dapper;
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public Task<Counts> GetStats()
|
||||
=> _db.Execute(conn => conn.QuerySingleAsync<Counts>("select * from info"));
|
||||
public Task<Counts> GetStats() => _db.QueryFirst<Counts>(new Query("info"));
|
||||
|
||||
public class Counts
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user