feat(aurora): add support for OFFSET in Moderation.get_latest()

This commit is contained in:
Seaswimmer 2024-06-04 12:23:12 -04:00
parent cb420d2fc4
commit a10af37f14
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -229,9 +229,9 @@ class Moderation(AuroraGuildModel):
return ()
@classmethod
def get_latest(cls, bot: Red, guild_id: int, limit: int | None = None, types: Iterable | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]:
params = []
query = f"SELECT * FROM moderation_{guild_id} ORDER BY moderation_id DESC"
def get_latest(cls, bot: Red, guild_id: int, limit: int | None = None, offset: int = 0, types: Iterable | None = None, cursor: Cursor | None = None) -> Tuple["Moderation"]:
params = [offset]
query = f"SELECT * FROM moderation_{guild_id} ORDER BY moderation_id DESC OFFSET ?"
if limit:
query += " LIMIT ?"
params.append(limit)
@ -239,7 +239,7 @@ class Moderation(AuroraGuildModel):
query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})"
params.extend(types)
query += ";"
return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=tuple(params) if limit else (), cursor=cursor)
return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=tuple(params) if params else (), cursor=cursor)
@classmethod
def get_next_case_number(cls, bot: Red, guild_id: int, cursor: Cursor | None = None) -> int: