Add return_keys support to upsert method and implement safe execution pattern for all CRUD operations #4
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.
This PR addresses an important compatibility issue with the
upsert
method and inconsistent handling ofreturn_keys
across different table object types.Problem
The
upsert
method was missing support for thereturn_keys
parameter, which is available in other CRUD operations (insert
,update
,update_with_where
,delete
). Additionally, most methods usingreturn_keys
had an unsafe execution pattern that only worked with SQLAlchemy Table objects, failing with Declarative objects.Solution
1. Added
return_keys
Support toupsert
MethodThe
upsert
method now accepts areturn_keys
parameter and returns the upserted data when specified:2. Implemented Safe Execution Pattern
All methods now use a safe pattern that works with both SQLAlchemy Table objects and Declarative objects:
This ensures compatibility across different SQLAlchemy usage patterns without breaking existing code.
Changes Made
return_keys
parameter to both sync and asyncupsert
methodsinsert
,update
, andupdate_with_where
methods to use the safe execution patternImpact
upsert
method now supports returning inserted/updated datareturn_keys
supportThe implementation follows the existing patterns in the codebase and maintains the high code quality standards with proper error handling and logging.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.