-
Notifications
You must be signed in to change notification settings - Fork 286
MsSql: HTTP PUT Request (Upsert) #190
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
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
…able support. Proper Upsert request validation.
…rt request validation.
… and pending final notifcation of custom PG REST support removal.
gledis69
reviewed
Feb 8, 2022
gledis69
reviewed
Feb 8, 2022
gledis69
reviewed
Feb 8, 2022
gledis69
reviewed
Feb 8, 2022
gledis69
reviewed
Feb 8, 2022
DataGateway.Service/Resolvers/Sql Query Structures/SqlUpsertQueryStructure.cs
Outdated
Show resolved
Hide resolved
gledis69
reviewed
Feb 8, 2022
DataGateway.Service/Resolvers/Sql Query Structures/SqlUpsertQueryStructure.cs
Outdated
Show resolved
Hide resolved
gledis69
reviewed
Feb 8, 2022
gledis69
reviewed
Feb 8, 2022
…G and MySQL REST API tests for PUT , pending their implementation in separate PRs. MySQL revert Insert as we are migrating to one DB roundtrip approach, and need proper query building guidance.
Aniruddh25
reviewed
Feb 15, 2022
Aniruddh25
reviewed
Feb 15, 2022
Aniruddh25
reviewed
Feb 15, 2022
…mns. Fixed logic for populating columns and params for PKs.
… Update variable names for UpsertRequest validation.
…n 400 bad request .
…esting. Updated REST API tests to only enable PUT for MSSQL, pending PG and MySQL implementation and adherence to One DB Roundtrip mutation query design.
… and make more methods virtual for manual skipping.
…ability to use one DB roundtrip mutation model. Also utilize insert constant for PUT.
774de2c to
97df382
Compare
Contributor
Author
|
Updated PR description with latest PUT strategy details. |
Aniruddh25
reviewed
Feb 15, 2022
…sending HTTP 400 for trying to insert in a table with autogen'd primary key. Adjusted test framework to accommodate.
10a2534 to
a90f0b0
Compare
Aniruddh25
approved these changes
Feb 16, 2022
Collaborator
Aniruddh25
left a comment
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.
Thank you for making sure we capture the right PUT behavior and with Transactions!
This was referenced Feb 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #79 by added capability to UPSERT objects via primary key.
Requirements to Run Locally
Please note: refresh your local database schemas
with the updated
MsSqlBooks.sqlandPostgreSqlBooks.sqlif you are running tests locally.Microsoft REST Guidelines
Implementation adheres to Microsoft REST Guidelines
"Services MAY optionally support PUT to update existing resources, but if they do they MUST use replacement semantics (that is, after the PUT, the resource's properties MUST match what was provided in the request, including deleting any server properties that were not provided)."
Implementation Notes
Modifies the
SqlMutationEnginemethodpublic async Task<JsonDocument> ExecuteAsync(RestRequestContext context)to handle UPSERTs. Operation can maintain idempotency by returning the fields that were successfully changed using the OUTPUT clause after the UPDATE/INSERT statement. Upserts are performed with a single payload used on ONE database roundtrip.public string Build(SqlUpsertQueryStructure structure)withinMsSqlQueryBuilder.cs. The result can be TWO result sets:Per the PM repo RFC Issue 50, PUT requires a request to define the Primary Key in the URL, and include remaining non-PK key/value pairs in the request body. The request will fail when trying to perform PUT that results in an Insert IF the primary key column of the entity is AutoGenerated (IDENTITY() column). The request will also fail if the request does not include key/value pairs for non nullable/non default valued fields.
Open Questions
Should we be redundant with config such that
Tests
UpsertById
Sample Requests
https://localhost:5001/books/id/1Request Body:
{ "title": "A Hobbit's Journey into the Forest 2", "publisher_id": 1234 }HTTP 204 No ContentHTTP 400 Bad RequestThis is because the Book table's primary key is autogenerated.https://localhost:5001/magazines/id/1Request Body:
{ "title": "Batman", "issueNumber": 1234 }HTTP 204 No ContentHTTP 201 CreatedOperation-Location:<resourceURI>this is successful because the magazine table does not have an autogenerated PK.https://localhost:5001/books/id/2Request Body: `{extendedTitle:"the hobbit",publisherId:"1234"}
If parameter listed in body are inconsistent with target resource schema, provide appropriate error:
JSON Response:
HTTP 400 Bad Requestwhich may need to be revised to beHTTP 409 Conflict.