ReliaQualAssociates / ramstk

Reliability, Availability, Maintainability, Safety (RAMS) analysis program.
https://www.reliaqual.com/rtk/
BSD 3-Clause "New" or "Revised" License
46 stars 15 forks source link

refactor: refactored basedatabase methods #1400

Closed weibullguy closed 1 month ago

weibullguy commented 2 months ago

Does this PR introduce a breaking change?

Describe the purpose of this pull request.

Refactor database classes for maintainability.

Describe how this was implemented.

Use ChatGPT to help refactor classes.

Describe any particular area(s) reviewers should focus on.

None

Pull Request Checklist

Summary by Sourcery

Refactor the BaseDatabase class to improve maintainability and error handling by introducing helper methods for database connections and query execution. Simplify error handling by consolidating exception management into a single method. Update tests to align with the refactored logic and verify the new error handling behavior.

Enhancements:

Tests:

sourcery-ai[bot] commented 2 months ago

Reviewer's Guide by Sourcery

This pull request refactors the basedatabase methods to improve maintainability and error handling. The changes include restructuring the database connection process, enhancing error handling, and improving code organization.

File-Level Changes

Change Details Files
Refactored database connection process
  • Created a new _connect_to_db helper method
  • Implemented a more robust connection process with better error handling
  • Added a new do_build_database_url method to construct database URLs
src/ramstk/models/db/basedatabase.py
Enhanced error handling throughout the BaseDatabase class
  • Introduced a new do_handle_db_error method for centralized error handling
  • Updated various methods to use the new error handling approach
  • Improved error messages and logging
src/ramstk/models/db/basedatabase.py
Improved code organization and readability
  • Broke down large methods into smaller, more focused functions
  • Added type hints and improved docstrings
  • Removed redundant code and simplified logic in several methods
src/ramstk/models/db/basedatabase.py
Updated tests to reflect changes in the BaseDatabase class
  • Modified existing tests to work with the refactored code
  • Added new tests for newly introduced methods
  • Updated error handling expectations in tests
tests/db/test_base.py
Modified DataAccessError exception
  • Changed DataAccessError to inherit from Exception instead of RAMSTKError
  • Made the error message parameter optional
src/ramstk/exceptions.py

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.