Skip to content

Fix of issue with distinct queries in read queries #491

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

Merged
merged 9 commits into from
Apr 17, 2025
Merged

Fix of issue with distinct queries in read queries #491

merged 9 commits into from
Apr 17, 2025

Conversation

devsetgo
Copy link
Owner

@devsetgo devsetgo commented Apr 17, 2025

Pull Request Description: Fix of Issue with Distinct Queries in Read Queries

This pull request addresses a critical issue related to executing distinct queries in our read operations. The changes made improve the handling of fetch queries in the read_query and read_multi_query methods within the database_operations.py file.

Motivation

Previously, distinct queries could lead to inconsistent results or errors due to inadequate handling of query execution results, particularly when dealing with single-column outputs. By enhancing the logic for processing results from SQLAlchemy, we ensure that our queries return the expected data structure, whether that be scalars, dictionaries, or ORM objects. This change directly improves the robustness of our database operations, ensuring that applications relying on these queries behave correctly.

Key Improvements

  • Enhanced Result Handling: The logic for processing results has been updated to dynamically adapt based on the query's output structure. This includes handling single-column results appropriately using scalars() and ensuring that multiple-column results are correctly formatted as dictionaries.
  • New API Endpoint: A new FastAPI endpoint (/database/get-list-of-distinct-records) has been introduced to demonstrate the execution of distinct queries effectively. This endpoint includes logic to insert multiple records and query distinct values, providing a practical example for users.
  • Documentation Updates: The docstrings for the read_query and read_multi_query methods have been revised to clarify expected input and output, enhancing usability for developers.

Coverage and Testing

Changes have been made to the coverage reports, reflecting adjustments in the codebase. The coverage badge has been updated to show the current coverage percentage, ensuring transparency for contributors regarding the project's test coverage.

By merging this pull request, we enhance the overall functionality and reliability of our database interactions, providing a better experience for developers working with distinct queries in our application.

- Updated `get_primary_keys` in `DatabaseOperations` to return a list of primary key names instead of a dict_keys object.
- This resolves issues in tests expecting a list type for primary keys.
- Improves compatibility and consistency of the API.
…t for testing

- Added `/database/get-list-of-distinct-records` endpoint to insert 100 fake users and return distinct last names using a SELECT DISTINCT query.
- Uses bulk insert with `execute_many` for efficient test data creation.
- Improves demonstration of distinct queries and bulk operations in FastAPI example.
@devsetgo devsetgo added Bug Fixes Testing Tests and other testing processes labels Apr 17, 2025
Copy link

@devsetgo devsetgo merged commit 5ffbad4 into main Apr 17, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fixes Testing Tests and other testing processes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant