-
Notifications
You must be signed in to change notification settings - Fork 290
Database policy support for PUT/PATCH operations - MsSql #1428
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aniruddh25
reviewed
Apr 27, 2023
Aniruddh25
reviewed
Apr 27, 2023
Aniruddh25
reviewed
Apr 27, 2023
Aniruddh25
reviewed
Apr 27, 2023
src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs
Outdated
Show resolved
Hide resolved
Aniruddh25
reviewed
Apr 27, 2023
Aniruddh25
approved these changes
Apr 27, 2023
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience for waiting on the review! LGTM, left a few suggestions.
Aniruddh25
reviewed
Apr 28, 2023
seantleonard
reviewed
May 1, 2023
src/Service/Resolvers/Sql Query Structures/SqlUpsertQueryStructure.cs
Outdated
Show resolved
Hide resolved
seantleonard
reviewed
May 1, 2023
seantleonard
reviewed
May 2, 2023
seantleonard
approved these changes
May 3, 2023
…thub.com/Azure/data-api-builder into dev/agarwalayush/db-policy-for-put-patch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Why make this change?
As per the behaviour expected from PUT/PATCH operations with database policies discussed in #1430, implement db policy support for MsSql to fix #1370.
What is this change?
Prior to this change, there was only one database policy for each operation. Since now database policies will be supported for both insert (or create)/update actions via PUT/PATCH operations, these 2 operations can have 2 database policies defined for them, one for each action. Hence, the
DbPolicyPredicates(string) property inBaseSqlQueryStructureclass is replaced byDbPolicyPredicatesForOperations(dictionary:Config.Action,string).The query generated by
MsSqlQueryBuilder.Build(SqlUpsertQueryStructure structure)is modified such that only one (or none) of the insert/update operations execute, depending on:Previously, we always used to perform the update operation irrespective of whether the row existed or not. From now onwards, we would first determine if the row actually exists or not. We will perform update only if it exists.
The method
IQueryExecutor.GetMultipleResultSetsIfAnyAsynchas been provided another implementation specific to MsSql inMsSqlQueryExecutor. The DbDataReader instance for the query being executed for the PUT/PATCH return operation would always contain atleast 1 result set and atmost 2 result sets.The property
IS_FIRST_RESULT_SETinSqlMutationEngineis renamed toIS_UPDATE_RESULT_SETto better denote its purpose.Different scenarios are added to the method
MsSqlQueryExecutor.GetMultipleResultSetsIfAnyAsyncto throw appropriate exceptions (Forbidden/Authorization failure - 403 and NotFound - 404). Appropriate comments are added within the code to demonstrate each case.How was this tested?