#nullable enable using System; using System.Data; using System.Threading.Tasks; using Dapper; namespace PluralKit.Core { public static class ModelQueryExt { public static Task QueryMember(this IDbConnection conn, int id) => conn.QueryFirstOrDefaultAsync("select * from members where id = @id", new {id}); public static Task QueryOrInsertGuildConfig(this IDbConnection conn, ulong guild) => conn.QueryFirstAsync("insert into servers (id) values (@Guild) on conflict do nothing returning *", new {Guild = guild}); public static Task QueryOrInsertSystemGuildConfig(this IDbConnection conn, ulong guild, int 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 IDbConnection conn, ulong guild, int 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}); } }