mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 02:08:27 -04:00
Removed cr repostiory, started a general purpose db extensions file
This commit is contained in:
@@ -10,7 +10,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
|
||||
IQuoteRepository Quotes { get; }
|
||||
IGuildConfigRepository GuildConfigs { get; }
|
||||
ICustomReactionRepository CustomReactions { get; }
|
||||
IWaifuRepository Waifus { get; }
|
||||
IDiscordUserRepository DiscordUsers { get; }
|
||||
IXpRepository Xp { get; }
|
||||
|
@@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories
|
||||
{
|
||||
public interface ICustomReactionRepository : IRepository<CustomReaction>
|
||||
{
|
||||
IEnumerable<CustomReaction> ForId(ulong id);
|
||||
int ClearFromGuild(ulong id);
|
||||
CustomReaction GetByGuildIdAndInput(ulong? guildId, string input);
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
{
|
||||
public class CustomReactionsRepository : Repository<CustomReaction>, ICustomReactionRepository
|
||||
{
|
||||
public CustomReactionsRepository(DbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public int ClearFromGuild(ulong id)
|
||||
{
|
||||
return _context.Database.ExecuteSqlInterpolated($"DELETE FROM CustomReactions WHERE GuildId={id};");
|
||||
}
|
||||
|
||||
public IEnumerable<CustomReaction> ForId(ulong id)
|
||||
{
|
||||
return _set
|
||||
.AsNoTracking()
|
||||
.AsQueryable()
|
||||
.Where(x => x.GuildId == id)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public CustomReaction GetByGuildIdAndInput(ulong? guildId, string input)
|
||||
{
|
||||
return _set.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LinqToDB;
|
||||
|
||||
namespace NadekoBot.Modules.CustomReactions
|
||||
{
|
||||
public static class CustomReactionsExtensions
|
||||
{
|
||||
public static int ClearFromGuild(this DbSet<CustomReaction> crs, ulong guildId)
|
||||
{
|
||||
return crs.Delete(x => x.GuildId == guildId);
|
||||
}
|
||||
|
||||
public static IEnumerable<CustomReaction> ForId(this DbSet<CustomReaction> crs, ulong id)
|
||||
{
|
||||
return crs
|
||||
.AsNoTracking()
|
||||
.AsQueryable()
|
||||
.Where(x => x.GuildId == id)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static CustomReaction GetByGuildIdAndInput(this DbSet<CustomReaction> crs, ulong? guildId, string input)
|
||||
{
|
||||
return crs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Db
|
||||
{
|
||||
public static class DbExtensions
|
||||
{
|
||||
public static T GetById<T>(this DbSet<T> set, int id) where T: DbEntity
|
||||
=> set.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
}
|
@@ -15,9 +15,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
private IGuildConfigRepository _guildConfigs;
|
||||
public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
|
||||
|
||||
private ICustomReactionRepository _customReactions;
|
||||
public ICustomReactionRepository CustomReactions => _customReactions ?? (_customReactions = new CustomReactionsRepository(_context));
|
||||
|
||||
private IWaifuRepository _waifus;
|
||||
public IWaifuRepository Waifus => _waifus ?? (_waifus = new WaifuRepository(_context));
|
||||
|
||||
|
Reference in New Issue
Block a user