This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
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 is a follow-up to #822 and includes that commit's changes as well.
Looking over the MySQL REPLACE documentation, I see that it mentions a REPLACE being either a DELETE then INSERT, or just an INSERT. I figured that there were two ways to implement this: as another interface with a unique function (
Replacer
with aReplace
function for example), or by leveraging the already-includedInsert
andDelete
functions from their respective interfaces. I decided to go with the latter option for the below reasons.One point is in the reduction of code needed for someone wanting to implement the library. The more that the framework handles (without appreciable loss of freedom), the better. Then there is also the consideration of triggers. If DELETE and INSERT calls should make use of triggers (which are probably already built into the implementing
Delete
andInsert
functions), then simply calling those as normal will allow for correct behavior by default.The biggest downside that I could see is that
Delete
is now forced to check if the given row exists, and return the appropriate error if not. For some implementations, this will not make an impact on the written code nor performance, but for others it definitely will. I felt that the trade off was worth it, but I'm interesting in hearing your opinions as well.A third potential option is to allow for a custom
Replace
function if provided, otherwise defaulting to DELETE + INSERT from earlier. For example:This would solve both of the problems as far as I can tell, but would not follow in the pattern established for every other keyword, and thus I decided against this.