-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLAlchemy rewrite #49
base: master
Are you sure you want to change the base?
Conversation
I wasn't sure what to do with the requirements file, so please test this out and let me know what I should pin sopel versions to... This should work with any version of sopel, but please confirm my suspicions :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr: sopel.db.engine
isn't technically part of the API, and shouldn't be used directly by plugins.
I doubt it. Sopel before 7.0 (current |
f621e54
to
ebdf786
Compare
Refactored all the database connectivity things. |
ebdf786
to
dd89279
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some issues with consistency. Seems to be very confusing naming variables engine
if they actually hold Connection
objects?
Also, the repeated try/except for getting a DB session could probably stand to get abstracted out into a function. Maybe a function that takes a Sopel
(bot
) object and returns the session
(or raises an exception if it can't get one)?
I was really hoping to avoid importing SQLAlchemy into this project, but I get the impression that we have to unless the DB
object API in Sopel itself gets fleshed out a ton.
sopel_modules/github/webhook.py
Outdated
print("OperationalError: Unable to connect to database.") | ||
raise | ||
|
||
session = scoped_session(sessionmaker(bind=engine)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes you use engine
, sometimes engine.engine
. Are you sure about this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weirdly it works both ways lol
The colors don't translate into GH comments, but I promise they still look fabulous.
|
Why is the same identical function defined twice? Not to nitpick too much, but that seems very silly. Even sillier than the fact that
Indeed, the relative lack of formatting options here vs. on IRC caught me out when trying to write nice PR descriptions for additions to |
02ff91f
to
a6d4fdb
Compare
a6d4fdb
to
edd3cdb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing a full-on review, but there's one thing I noticed (line-noted). Also, should this not use a similar approach to Sopel's own DB class for thread-safety? That is, with regard to the scoped session management approach you proposed in sopel-irc/sopel#1755.
def get_db_session(bot): | ||
try: | ||
engine = bot.db.connect() | ||
except OperationalError: | ||
print("OperationalError: Unable to connect to database.") | ||
raise | ||
|
||
return scoped_session(sessionmaker(bind=engine)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this pulled in from .utils
now?
It's no longer necessary to make any changes just to make this plugin keep working—tweaks to Sopel's database API mean this and other plugins that use direct DB access with Sopel 6.x will continue to work with 7.x if the default SQLite database backend is in use. That said, we should still migrate onto SQLAlchemy eventually. It'll give this plugin compatibility with more database types, and as more upstream users take advantage of the new supported backends the restriction to using this plugin with SQLite will become more onerous. |
No description provided.