Refactor command message deletion
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
@@ -8,17 +6,22 @@ namespace PluralKit.Core
|
||||
{
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public Task SaveCommandMessage(IPKConnection conn, ulong message_id, ulong author_id) =>
|
||||
conn.QueryAsync("insert into command_message (message_id, author_id) values (@Message, @Author)",
|
||||
new {Message = message_id, Author = author_id });
|
||||
public Task SaveCommandMessage(IPKConnection conn, ulong messageId, ulong authorId) =>
|
||||
conn.QueryAsync("insert into command_messages (message_id, author_id) values (@Message, @Author)",
|
||||
new {Message = messageId, Author = authorId });
|
||||
|
||||
public Task<CommandMessage> GetCommandMessage(IPKConnection conn, ulong message_id) =>
|
||||
conn.QuerySingleOrDefaultAsync<CommandMessage>("select message_id, author_id from command_message where message_id = @Message",
|
||||
new {Message = message_id});
|
||||
}
|
||||
public Task<CommandMessage> GetCommandMessage(IPKConnection conn, ulong messageId) =>
|
||||
conn.QuerySingleOrDefaultAsync<CommandMessage>("select * from command_messages where message_id = @Message",
|
||||
new {Message = messageId});
|
||||
|
||||
public Task<int> DeleteCommandMessagesBefore(IPKConnection conn, ulong messageIdThreshold) =>
|
||||
conn.ExecuteAsync("delete from command_messages where message_id < @Threshold",
|
||||
new {Threshold = messageIdThreshold});
|
||||
}
|
||||
|
||||
public class CommandMessage
|
||||
{
|
||||
public ulong author_id { get; set; }
|
||||
public ulong AuthorId { get; set; }
|
||||
public ulong MessageId { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user