Skip to content

support MySQL functions in query values #1542

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
SeregPie opened this issue Oct 12, 2016 · 3 comments
Closed

support MySQL functions in query values #1542

SeregPie opened this issue Oct 12, 2016 · 3 comments
Labels

Comments

@SeregPie
Copy link

Hello. I just started using node.js and your mysql module is very helpful. I like the query values feature but I cannot use it if I have functions and variables in the query. Why not implement an extra class which will be not escaped?

escape(/*...*/) {
    if (value instanceof MysqlFunc) {
        return value.toString();
    } else {
        //... as usual
    }
}

let sql = 'INSERT INTO user SET ?';
let user = {name: 'Alex', created: connection.mysqlFunc('now()')};
connection.query(sql, user, (err, result) => {
    //...
});
@dresende
Copy link
Collaborator

dresende commented Nov 4, 2016

This is something I already thought of. sqlstring module could, instead of ignoring functions, just call them (perhaps passing connection handler) and synchronously replace function return string. Although your example is not actually useful (since you can define a date as current timestamp by default) there are many useful functions one could use, not just for insert statements.

@dougwilson
Copy link
Member

Yea, this is already in progress and a solution is supposed to be in the next release of this module next week.

@dougwilson
Copy link
Member

We have a PR in sqlstring that needs some touch up and then I planned on landing it over this weekend.

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