-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix call site when using Pool.prototype.query #715
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
Conversation
This fixes the call site for long stack traces when using the query method on a pool object. Before the stack trace would only lead up to inside the getConnection method instead of the library caller.
looks good! 👍 |
var connection; | ||
var query = Connection.createQuery(sql, values, function (err, rows, fields) { | ||
connection.release(); | ||
cb.apply(this, arguments); |
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.
What's the value of this
here? Should null
or a self
-like variable be passed instead?
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.
All this did was move the previous
conn.query(sql, values, function (err, rows, fields) {
conn.release();
cb.apply(this, arguments);
});
The purpose is to cal the callback with the same this
that conn.query
would have called it with such that pool.query
and conn.query
have the same this
instead of possible different ones. This allows people to use conn.query
and pool.query
interchangeably.
If you were wondering what this
is pointing it, it is point to the connection
.
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.
I'm on a mobile device right now, so please forgive me for not diving deeper into this myself right now. It seems unlikely that "this" points to the connection from the createQuery callback though.
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.
It looks like it is actually a connection - 'this' for this anonymous function is set at https://github.com/felixge/node-mysql/blob/master/lib/protocol/sequences/Sequence.js#L78
Apologies, I stand corrected :) |
@sidorares any news on merging this? :) |
oh, I was waiting for second 'OK'. @dresende - could you review please? |
LGTM |
Fix call site when using Pool.prototype.query
This fixes the call site for long stack traces when using the
query
method on a pool object. Before the stack trace would only lead up to inside thegetConnection
method instead of the library caller. This results in the following change: