-
Notifications
You must be signed in to change notification settings - Fork 155
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
feat: patch connections created by a pool's getConnection #98
feat: patch connections created by a pool's getConnection #98
Conversation
Copied the basic connection tests and runs them with the connection created by the pool. Also adds a test to ensure the getConnection function is replaced with one called 'patchedGetConnection'.
Should just test if the basic functionality still works when gained from the pool, no need for the edge cases to be re-run.
Added what I think should be all that's needed for mysql2 support, still wouldn't mind if someone who's more familiar with mysql2 could take a look at it as well. |
Tried using this within our application which uses
I did get it to work by adding further conditions to avoid the infinite recursion - changing the function
|
@M-TGH thanks for adding the changes - did not get any issues so far ;) Any chance of getting this merged any time soon? |
@@ -66,16 +66,42 @@ function patchCreatePool(mysql) { | |||
}; | |||
} | |||
|
|||
function patchGetConnection(pool) { |
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.
Would this also work with PoolCluster
if instead of grabbing the callback from the 1st argument, you grabbed it from the last argument?
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.
Looks like it would work, I'll add it into this PR, if you prefer me to split it up into a separate PR let me know (it may make the PR a bit big in size).
344eab9
to
b1e3cb3
Compare
This feels somewhat risky since it's just called 'of'. Let me know if we should maybe avoid this for now or you have any suggestions.
@chrisradek I've added basic support for mysql.createPoolCluster in dfc1c55 (getConnection & query). Let me know if you would prefer it in a separate PR. I've also added support for poolCluster.of in db8e782, however I'm on the fence about patching of this way since it's rather ambiguous. |
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.
@M-TGH
I just had one comment on the code. And thank you for writing all of these tests!
I get your concerns about patching of
in this way. Unfortunately, it doesn't seem that mysql
exposes a clear way to determine if we're working with a Pool
vs PoolCluster
, so your implementation does look reasonable to me. Maybe a comment specifying that of
exists on a PoolCluster
and returns a Pool
would help explain to future devs why it is being patched.
Good catch on the args, added a fix in 5bb11c8. |
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.
@M-TGH
Sorry, I missed one thing around promises earlier. If you can make that last change, I'll be happy to merge this in!
Updated the check in 1937797.
I'll replace those in a separate PR since they weren't added in this one, however let me know if you prefer it included in this PR. |
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.
@M-TGH
Awesome, thank you for making those changes, and for your contribution! Merging this in!
Issue #, if available: #87
Description of changes:
Adds a simple patchObject call around connections returned from a pools
getConnection
.Far as I could tell mysql doesn't take any other arguments for this, so it assumes the first argument is the callback.
I'm unsure what mysql2 makes of this, but I assume they promisified it which I didn't yet support. Would be nice to hear from someone who uses mysql2 what changes are still needed to support mysql2. I'll be looking into adding it but would like confirmation on what parameters it takes and what it returns.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.