#nullable enable using System.Threading.Tasks; using Dapper; namespace PluralKit.Core { public static class ModelQueryExt { public static Task QuerySystem(this IPKConnection conn, SystemId id) => conn.QueryFirstOrDefaultAsync("select * from systems where id = @id", new {id}); public static Task QueryMember(this IPKConnection conn, MemberId id) => conn.QueryFirstOrDefaultAsync("select * from members where id = @id", new {id}); public static Task QueryOrInsertGuildConfig(this IPKConnection conn, ulong guild) => conn.QueryFirstAsync("insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *", new {guild}); public static Task QueryOrInsertSystemGuildConfig(this IPKConnection conn, ulong guild, SystemId system) => conn.QueryFirstAsync( "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 QueryOrInsertMemberGuildConfig( this IPKConnection conn, ulong guild, MemberId member) => conn.QueryFirstAsync( "insert into member_guild (guild, member) values (@guild, @member) on conflict (guild, member) do update set guild = @guild, member = @member returning *", new {guild, member}); } }