Skip to content

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

Merged
merged 1 commit into from
Feb 23, 2014
Merged

Fix call site when using Pool.prototype.query #715

merged 1 commit into from
Feb 23, 2014

Conversation

dougwilson
Copy link
Member

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. This results in the following change:

var mysql = require('mysql');
var pool = mysql.createPool(...);

pool.query('ERROR', function (err, rows) { // 1
  if (err) throw err;
  // The stack trace now includes the line marked 1
  // Prior to this, the stack trace included nothing from this file
});

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.
@sidorares
Copy link
Member

looks good! 👍

var connection;
var query = Connection.createQuery(sql, values, function (err, rows, fields) {
connection.release();
cb.apply(this, arguments);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

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

@ronkorving
Copy link
Contributor

Apologies, I stand corrected :)

@dougwilson
Copy link
Member Author

@sidorares any news on merging this? :)

@sidorares
Copy link
Member

oh, I was waiting for second 'OK'. @dresende - could you review please?

@felixge
Copy link
Collaborator

felixge commented Feb 4, 2014

LGTM

dresende added a commit that referenced this pull request Feb 23, 2014
Fix call site when using Pool.prototype.query
@dresende dresende merged commit f4b0744 into mysqljs:master Feb 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants