- Gave the package a descriptive name.
- Passed over with black once more.
- Created setup.py to install dependencies.
- Updated author to reflect repo ownership to Dusty.
- Changed `git` command to use the __url__ attribute.
- Changed music to use ogg vorbis instead of mp3, purely for
performance.
- Tried to make sure nothing broke.
- Updated dockerfile. Pretty sure we don't need it though...
38 lines
1013 B
Python
38 lines
1013 B
Python
import asyncio
|
|
|
|
import asyncpg
|
|
|
|
|
|
class DatabaseConnection:
|
|
def __init__(
|
|
self,
|
|
host: str = "localhost",
|
|
port: int = 5432,
|
|
database: str = "",
|
|
user: str = "",
|
|
password: str = "",
|
|
):
|
|
if user == "" or password == "" or database == "":
|
|
raise RuntimeError("Username or Password are blank")
|
|
self.kwargs = {
|
|
"host": host,
|
|
"port": port,
|
|
"database": database,
|
|
"user": user,
|
|
"password": password,
|
|
}
|
|
self._conn = None
|
|
asyncio.get_event_loop().run_until_complete(self.acquire())
|
|
self.fetchval = self._conn.fetchval
|
|
self.execute = self._conn.execute
|
|
self.fetch = self._conn.fetch
|
|
self.fetchrow = self._conn.fetchrow
|
|
|
|
async def acquire(self):
|
|
if not self._conn:
|
|
self._conn = await asyncpg.create_pool(**self.kwargs)
|
|
|
|
async def close(self):
|
|
await self._conn.close()
|
|
self._conn = None
|