Skip to content

Request: expose SqlString.format #521

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

Closed
whoughton opened this issue Jun 20, 2013 · 4 comments
Closed

Request: expose SqlString.format #521

whoughton opened this issue Jun 20, 2013 · 4 comments
Labels

Comments

@whoughton
Copy link
Contributor

I'm using node-mysql in partnership with node-mysql-libmysqlclient, and one of the things I like about using node-mysql is that I can use it for building Querys, but as of right now only escape and escapeId are exposed. It would seem useful and not harmful to expose SqlString.format as well. I've added it in to my index.js right now and am using it as such.

exports.format   = SqlString.format;

I can submit a pull request if preferred, I just thought this might be an simple change and useful to the community.

As a further example I can then use it in my code as such, with a simple prepare method:

var prepare = function(sql, values) {
    if (typeof values === 'string') { values = [values]; }
    var query = mysql.createQuery(sql, values);
    if (!query.values) { query.values = []; }
    query.sql = mysql.format(query.sql, query.values);

    log("query: %s", query.sql);
    return query;
};

This also allows me to log the SQL query once prepared as well which is nice.

@kai-koch
Copy link
Collaborator

👍
But also needs to be documented, when exposed.

@dresende
Copy link
Collaborator

I think a pull request will be accepted :)

@whoughton
Copy link
Contributor Author

Done:
#523

@dresende
Copy link
Collaborator

Continuing there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants