Retire more IDataStore methods
This commit is contained in:
		@@ -1,20 +1,34 @@
 | 
			
		||||
#nullable enable
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
using Dapper;
 | 
			
		||||
 | 
			
		||||
using PluralKit.Core;
 | 
			
		||||
 | 
			
		||||
namespace PluralKit.Core
 | 
			
		||||
{
 | 
			
		||||
    public static class ModelQueryExt
 | 
			
		||||
    {
 | 
			
		||||
        public static Task<PKSystem?> QuerySystem(this IPKConnection conn, SystemId id) =>
 | 
			
		||||
            conn.QueryFirstOrDefaultAsync<PKSystem?>("select * from systems where id = @id", new {id});
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        public static Task<int> GetSystemMemberCount(this IPKConnection conn, SystemId id, PrivacyLevel? privacyFilter = null)
 | 
			
		||||
        {
 | 
			
		||||
            var query = new StringBuilder("select count(*) from members where system = @Id");
 | 
			
		||||
            if (privacyFilter != null)
 | 
			
		||||
                query.Append($" and member_visibility = {(int) privacyFilter.Value}");
 | 
			
		||||
            return conn.QuerySingleAsync<int>(query.ToString(), new {Id = id});
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Task<IEnumerable<ulong>> GetLinkedAccounts(this IPKConnection conn, SystemId id) =>
 | 
			
		||||
            conn.QueryAsync<ulong>("select uid from accounts where system = @Id", new {Id = id});
 | 
			
		||||
 | 
			
		||||
        public static Task<PKMember?> QueryMember(this IPKConnection conn, MemberId id) =>
 | 
			
		||||
            conn.QueryFirstOrDefaultAsync<PKMember?>("select * from members where id = @id", new {id});
 | 
			
		||||
        
 | 
			
		||||
        public static Task<PKMember?> QueryMemberByHid(this IPKConnection conn, string hid) =>
 | 
			
		||||
            conn.QueryFirstOrDefaultAsync<PKMember?>("select * from members where hid = @hid", new {hid = hid.ToLowerInvariant()});
 | 
			
		||||
        
 | 
			
		||||
        public static Task<GuildConfig> QueryOrInsertGuildConfig(this IPKConnection conn, ulong guild) =>
 | 
			
		||||
            conn.QueryFirstAsync<GuildConfig>("insert into servers (id) values (@guild) on conflict (id) do update set id = @guild returning *", new {guild});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,12 @@ namespace PluralKit.Core
 | 
			
		||||
 | 
			
		||||
        public static Task DeleteSystem(this IPKConnection conn, SystemId id) =>
 | 
			
		||||
            conn.ExecuteAsync("delete from systems where id = @Id", new {Id = id});
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        public static Task<PKMember> CreateMember(this IPKConnection conn, SystemId system, string memberName) =>
 | 
			
		||||
            conn.QueryFirstAsync<PKMember>(
 | 
			
		||||
                "insert into members (hid, system, name) values (find_free_member_hid(), @SystemId, @Name) returning *",
 | 
			
		||||
                new {SystemId = system, Name = memberName});
 | 
			
		||||
 | 
			
		||||
        public static Task<PKMember> UpdateMember(this IPKConnection conn, MemberId id, MemberPatch patch)
 | 
			
		||||
        {
 | 
			
		||||
            var (query, pms) = patch.Apply(new UpdateQueryBuilder("members", "id = @id"))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user