Closed albertopoljak closed 5 years ago
Lot of methods can be just querries that will call getter/setter methods.
Example:
async def change_default_license_expiration(self, guild_id: int, expiration_hours: int):
query = "UPDATE GUILDS SET DEFAULT_LICENSE_DURATION_HOURS=? WHERE GUILD_ID=?"
await self.connection.execute(query, (expiration_hours, guild_id))
await self.connection.commit()
Last 2 lines can be separated into a universal method that does just those 2 lines and taking arguments query and query parameters. Example
async def update_database(self, query, *args):
"""
Use for insert/update statements
:param query: query to execute
:param args: arguments, results in a tuple
"""
await self.connection.execute(query, args)
await self.connection.commit()
So then in the first method we would have something like this:
async def change_default_license_expiration(self, guild_id: int, expiration_hours: int):
query = "UPDATE GUILDS SET DEFAULT_LICENSE_DURATION_HOURS=? WHERE GUILD_ID=?"
await self.update_database(query, expiration_hours, guild_id)
I'm willing to give this a try.
Sure go ahead and good luck :) I'll keep updating some misc code but won't touch database_handler or anything that uses it.
Hacktoberfest , info below