fix(aurora): fixed some issues with aiosqlite

This commit is contained in:
Seaswimmer 2024-06-05 00:39:56 -04:00
parent 56a2f96a2d
commit 3383e84221
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F
4 changed files with 34 additions and 38 deletions

View file

@ -1,7 +1,5 @@
# pylint: disable=cyclic-import
import json
from contextlib import asynccontextmanager
from typing import Any, AsyncGenerator
import aiosqlite
from discord import Guild
@ -10,14 +8,13 @@ from redbot.core import data_manager
from .logger import logger
@asynccontextmanager
async def connect() -> AsyncGenerator[aiosqlite.Connection, Any, None]:
async def connect() -> aiosqlite.Connection:
"""Connects to the SQLite database, and returns a connection object."""
try:
connection = await aiosqlite.connect(
database=data_manager.cog_data_path(raw_name="Aurora") / "aurora.db"
)
yield connection
return connection
except aiosqlite.OperationalError as e:
logger.error("Unable to access the SQLite database!\nError:\n%s", e.msg)
@ -25,10 +22,6 @@ async def connect() -> AsyncGenerator[aiosqlite.Connection, Any, None]:
f"Unable to access the SQLite Database!\n{e.msg}"
) from e
finally:
if connection:
await connection.close()
async def create_guild_table(guild: Guild):
database = await connect()