Skip to content

Commit

Permalink
fix: Change schema init to staticmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
nythepegasus committed Jan 10, 2025
1 parent 94e0ed9 commit a2b8dca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions SideBot/db/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class _Tags:
"""Internal DB class for tags."""

async def write_schema(self: asyncpg.Connection) -> None:
@staticmethod
async def write_schema(conn: asyncpg.Connection) -> None:
for x in [
"""
CREATE TYPE public.discorduser AS (
Expand Down Expand Up @@ -43,7 +44,7 @@ async def write_schema(self: asyncpg.Connection) -> None:
"CREATE INDEX IF NOT EXISTS tags_guild_id_idx ON tags (guild_id, name)",
]:
with contextlib.suppress(asyncpg.exceptions.DuplicateObjectError):
await self.execute(
await conn.execute(
x,
)

Expand Down Expand Up @@ -173,11 +174,12 @@ def __init__(
self.id = ident
self.tags = _Tags(conn)

@staticmethod
async def write_schema(
self: asyncpg.Connection,
conn: asyncpg.Connection,
) -> None:
"""Tag class."""
await _Tags.write_schema(self)
await _Tags.write_schema(conn)

@classmethod
async def get(
Expand Down
4 changes: 2 additions & 2 deletions SideBot/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def as_dict(self):
}

@classmethod
def from_dict(cls, data: dict):
def from_dict(cls, data: dict) -> "DBConfig":
return cls(
data["user"],
data["pass"],
Expand All @@ -52,7 +52,7 @@ def __init__(self, token: str, owner: int, db_url: str, cogs: list[str]):
self.cogs = cogs

@classmethod
def from_dict(cls, data: dict):
def from_dict(cls, data: dict) -> "BotConfig":
if "botDB" in data:
return cls(data["discordToken"], data["owner"], DBConfig.from_dict(data["botDB"]).connect_str, data["cogs"])
return cls(data["discordToken"], data["owner"], data["botDBURL"], data["cogs"])
Expand Down

0 comments on commit a2b8dca

Please sign in to comment.