Add Modifiable Query Support with Commit Control #9
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 Modifiable Query Support with Commit Control
🎯 Overview
This PR introduces fine-grained control over database transaction commits in the PySpringModel query system. The new
is_modifyingparameter allows developers to specify whether a query operation should automatically commit changes to the database.🚀 Features Added
1. Enhanced Session Management
PySpringModel.create_managed_session()to accept ashould_commitparameter2. Query Decorator Enhancement
is_modifyingparameter to the@Querydecoratoris_modifying=False(no automatic commit)is_modifying=Truefor operations that should commit (INSERT, UPDATE, DELETE)3. Service Layer Updates
QueryExecutionService.execute_query()to handle the modifying flag📝 Usage Examples
Read-Only Queries (Default)
Modifying Queries
🔧 Technical Implementation
Core Changes
py_spring_model/core/model.pyshould_commit: bool = Trueparameter tocreate_managed_session()py_spring_model/py_spring_model_rest/service/query_service/query.pyis_modifying: boolparameter toQueryExecutionService.execute_query()is_modifying: bool = Falseparameter toQuerydecoratorcreate_managed_session(should_commit=is_modifying)Session Management Flow
🧪 Testing
Comprehensive Test Suite Added
Test Coverage
🔄 Backward Compatibility
@Querydecorators work as beforeis_modifyingflags incrementally🎯 Benefits
1. Performance Optimization
2. Explicit Intent
3. Transaction Control
🚨 Breaking Changes
None - This is a fully backward-compatible change.
📋 Checklist
🔍 Review Focus Areas
should_commitparameter handling