2020-06-13 14:03:57 +00:00
#nullable enable
2020-06-13 11:58:27 +00:00
using System.Threading.Tasks ;
using Dapper ;
namespace PluralKit.Core
{
public static class ModelQueryExt
{
2020-06-14 19:37:04 +00:00
public static Task < PKSystem ? > QuerySystem ( this IPKConnection conn , SystemId id ) = >
2020-06-13 17:42:04 +00:00
conn . QueryFirstOrDefaultAsync < PKSystem ? > ( "select * from systems where id = @id" , new { id } ) ;
2020-06-14 19:37:04 +00:00
public static Task < PKMember ? > QueryMember ( this IPKConnection conn , MemberId id ) = >
2020-06-13 14:03:57 +00:00
conn . QueryFirstOrDefaultAsync < PKMember ? > ( "select * from members where id = @id" , new { id } ) ;
2020-06-13 16:31:20 +00:00
public static Task < GuildConfig > QueryOrInsertGuildConfig ( this IPKConnection conn , ulong guild ) = >
2020-06-13 17:15:50 +00:00
conn . QueryFirstAsync < GuildConfig > ( "insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *" , new { guild } ) ;
2020-06-13 14:03:57 +00:00
2020-06-14 19:37:04 +00:00
public static Task < SystemGuildSettings > QueryOrInsertSystemGuildConfig ( this IPKConnection conn , ulong guild , SystemId system ) = >
2020-06-13 14:03:57 +00:00
conn . QueryFirstAsync < SystemGuildSettings > (
"insert into member_guild (guild, member) values (@guild, @member) on conflict (guild, member) do update set guild = @guild, member = @member returning *" ,
new { guild , system } ) ;
public static Task < MemberGuildSettings > QueryOrInsertMemberGuildConfig (
2020-06-14 19:37:04 +00:00
this IPKConnection conn , ulong guild , MemberId member ) = >
2020-06-13 14:03:57 +00:00
conn . QueryFirstAsync < MemberGuildSettings > (
"insert into member_guild (guild, member) values (@guild, @member) on conflict (guild, member) do update set guild = @guild, member = @member returning *" ,
new { guild , member } ) ;
2020-06-13 11:58:27 +00:00
}
}