Add Field Operations Support for Dynamic Query Generation #12
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
🚀 Add Field Operations Support for Dynamic Query Generation
📋 Summary
This PR introduces comprehensive field operations support to PySpringModel, enabling dynamic query generation similar to Spring Data JPA. Users can now create complex database queries using method naming conventions with various comparison operators and conditions.
✨ New Features
Supported Field Operations
EQUALSfind_by_nameIN_infind_by_status_inGREATER_THAN_gtfind_by_age_gtGREATER_EQUAL_gtefind_by_age_gteLESS_THAN_ltfind_by_age_ltLESS_EQUAL_ltefind_by_age_lteLIKE_likefind_by_name_likeNOT_EQUALS_nefind_by_status_neNOT_IN_not_infind_by_category_not_inIntelligent Parameter Field Mapping
A significant enhancement that improves API quality and developer experience:
statuses→status)Key Capabilities
_and_and_or_operators🔧 Implementation Details
Core Changes
Enhanced Query Builder (
method_query_builder.py):FieldOperationenum for supported operationsImproved Query Service (
crud_repository_implementation_service.py):Intelligent Parameter Field Mapping:
statuses→status)Comprehensive Testing:
test_field_operations.pywith extensive test coverageCode Example
🧪 Testing
Test Coverage
📚 Documentation
Added comprehensive documentation in
docs/query_operators.mdincluding:🔄 Backward Compatibility
🎯 Benefits
🚦 Migration Guide
No migration required! Existing code continues to work as-is. New field operations are opt-in through method naming conventions.
🔬 Technical Challenges & Solutions
Parameter Field Mapping Complexity
The Challenge: The original parameter-to-field mapping had a critical design flaw - it assumed parameter names and field names would be in the same order, leading to incorrect mappings and silent failures.
The Solution: Implemented a robust, order-independent mapping system with clear rules:
statuses→status)Result: A system that's both powerful and predictable, supporting high-quality API design while maintaining simplicity.
📝 Checklist
Related Issues: Closes #[issue_number]
Breaking Changes: None
Dependencies: No new dependencies added
Performance Impact: Minimal - only affects new field operation methods
This PR significantly enhances PySpringModel's query capabilities, making it more powerful and developer-friendly while maintaining full backward compatibility.