freepizzas-dev / onebot

A barebones Discord bot based on nextcord.py that includes some basic modules to play around with.
MIT License
6 stars 0 forks source link

Abstract away database operations from Cogs #10

Open freepizzas-dev opened 1 year ago

freepizzas-dev commented 1 year ago

Expose bot.db_read() and bot.db_store() operations to Cogs that abstract away dealing with any sort of SQL operations. Have the bot DB functions handle connections and commits, as well as exceptions.

The calling Cog's name can be used to define tables or databases to keep data segregated both per-guild and per-module.

If Cogs need to perform complex transactions on the DB for consistency reasons, a lock can be exposed through the bot as well. But a short default timeout should be implented and signaled (configurable through onebot_config).

Meanwhile, this refactor can be used as an opportunity to switch to an async sqlite implementation. (Issue #5)