-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Get formatted query from Pool.query() method #991
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
b44221d
f341946
249b0a3
e350fad
6bf1987
119d6ec
3cd3833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,8 @@ Pool.prototype.end = function (cb) { | |
| Pool.prototype.query = function (sql, values, cb) { | ||
| var query = Connection.createQuery(sql, values, cb); | ||
|
|
||
| query.isFormatted = false; | ||
|
|
||
| if (!(typeof sql === 'object' && 'typeCast' in sql)) { | ||
| query.typeCast = this.config.connectionConfig.typeCast; | ||
| } | ||
|
|
@@ -195,6 +197,10 @@ Pool.prototype.query = function (sql, values, cb) { | |
| conn.query(query); | ||
| }); | ||
|
|
||
| if (!query.isFormatted) { | ||
| query.isFormatted = true; | ||
| query.sql = this.format(query.sql, query.values); | ||
| } | ||
| return query; | ||
| }; | ||
|
|
||
|
|
@@ -255,6 +261,13 @@ Pool.prototype.escapeId = function escapeId(value) { | |
| return mysql.escapeId(value, false); | ||
| }; | ||
|
|
||
| Pool.prototype.format = function(sql, values) { | ||
| if (typeof this.config.connectionConfig.queryFormat == "function") { | ||
| return this.config.connectionConfig.queryFormat.call(this, sql, values, this.config.connectionConfig.timezone); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to think about if it's acceptable that the context of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did find a solution to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it take care of this context issue, though? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise there is no need to add a new commit, really. I've already adjusted your commit to make it an instance method (still under your name). The problem right now is backwards compatibility with this function context. |
||
| } | ||
| return mysql.format(sql, values, this.config.connectionConfig.stringifyObjects, this.config.connectionConfig.timezone); | ||
| }; | ||
|
|
||
| function spliceConnection(array, connection) { | ||
| var index; | ||
| if ((index = array.indexOf(connection)) !== -1) { | ||
|
|
||
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.
Move this so it always exists, otherwise we are altering the hidden class and fracturing it.
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.e. it should be set within
createQuery