Skip to content
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

fix: Issues with DBConnection class #845

Merged
merged 8 commits into from
Dec 27, 2023

Conversation

RisingOrange
Copy link
Collaborator

@RisingOrange RisingOrange commented Dec 20, 2023

Our custom DBConnection class can be used as a context manager like this:
https://github.com/ankipalace/ankihub_addon/blob/b76d2118c8afee21ae6ad589846efbd5ac64e801/tests/addon/test_unit.py#L1131-L1133

(ankihub_db.connection() returns an instance of DBConnection)
One could expect that if there was an exception in the context, the operations would be rolled back. This is how it works for sqlite3.Connection when it's used as a context manager. However this is currently not the case for DBConnection. This will be fixed by this PR.

For context: The intention behind supporting the usage of DBConnection as a context manager was mainly to improve performance. Instantiating a DBConnection object requires opening a new database connection, which is relatively expensive. It also can't be re-used when not used as a context manager:
https://github.com/ankipalace/ankihub_addon/blob/b76d2118c8afee21ae6ad589846efbd5ac64e801/tests/addon/test_unit.py#L1114-L1121
So using the DBConnection as a context manager was a way to improve performance when multiple queries need to be performed in a loop.

Related issues

fix: Issues with DBConnection class

Proposed changes

  • Adjust DBConnection to rollback changes when there is an exception in the context
  • Add docstrings to the DBConnection class and its methods
  • Add tests for the DBConnection class

Copy link

codecov bot commented Dec 20, 2023

Codecov upload limit reached ⚠️

This org is currently on the free Basic Plan; which includes 250 free private repo uploads each rolling month. This limit has been reached and additional reports cannot be generated. For unlimited uploads, upgrade to our pro plan.

Do you have questions or need help? Connect with our sales team today at [email protected]

@RisingOrange RisingOrange marked this pull request as ready for review December 21, 2023 16:43
@RisingOrange RisingOrange merged commit 069f6ce into main Dec 27, 2023
6 checks passed
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.

2 participants