Skip to content

Begin work on switching out for sqlalchemy#15

Open
optimumtact wants to merge 2 commits intomasterfrom
dbdev
Open

Begin work on switching out for sqlalchemy#15
optimumtact wants to merge 2 commits intomasterfrom
dbdev

Conversation

@optimumtact
Copy link
Owner

@optimumtact optimumtact commented Sep 19, 2020

Planned implementation of multi DB support
TGDB cog api

# Global config
.tgdb add instance <instancekey> #Create a new database instance
.tgdb config <instancekey> [current config commands, current, blah, etc] # configure that db instance (host/pass/user etc)
# Guild command/config
.tgdb use <instancekey> #Tell the bot this guild uses this db instance
.tgdb toggle #turn tgdb on/off

Cog side api

#Default for most uses
tgdb.get_contextual_api_for_context(Discord.context:ctx)
#if you don't have a context, you need a guild to operate in, and only get a TGapi
tgdb.get_api_for_guild(Discord.guild)

This will get the ctx.guild and use that to look up the instancekey in the guild config
It will use that instance key to find the database and return it (or throw an tgcommon.NotFound exception)
This returns an TGAPIWithContext class, which has helper utility methods and can reference the self.db and self.ctx values
which are set as appropriate.

Cog's depending on the TGDB cog should roughly do the following

def some_command(ctx, ckey: str)
tgdb = self.bot.get_cog("TGDB")
api = tgdb.get_contextual_api_for_context(ctx)
users = api.get_discord_link_users_by_ckey(ckey)
for each users:
    #do something

Future work this implies:
Commands/cogs demanding a minimum supported database schema level (starting at 5.10 obviously)
Only switch a cog to the new schema if absolutely necessary

Potentially supporting other databases? BeeSchema5.10.py? BeeAPIWithContext class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant