-
Notifications
You must be signed in to change notification settings - Fork 78
Add toSQL(dialect)
escaping support
#9
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
@dougwilson update? |
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.
Sorry I didn't get back right away; have been very busy :) I just took a look through this PR and it looks good. The only other thing I want to do really quick is go through as many other SQL driver modules for Node.js to see if any of them are doing .toSQL
or something similar to make sure there is no prior art before introducing this new pattern :)
haha, love the image :) So I browsed around and looked at the following:
and didn't see a similar feature (though I just looked through the documentation). This means that there doesn't seem to be any prior art to copy, so nothing to even worry about :) I did see that I'm going to look some more around tonight, otherwise it seems good to merge, which I will try and to tomorrow :D |
I went ahead and did my own searches as well. Knex's knex.select('*').from('users').where(knex.raw('id = ?', [1])).toSQL()
// Ouputs: { bindings: [1], method: 'select', sql: 'select * from "users" where id = ?', options: undefined, } So I don't really see any compatibility with Knex. I also went into a deeper dive into the other repos you mentioned. No I went ahead and also looked at Sequelize. They have a On the other hand, I did find a small project called sql-mason that does have a var Mason = require('sql-mason');
var builder = new Mason();
var query = builder.table('users').where('id', 1);
var sql = query.toSql(); //=> select * from `users` where `id` = ?;
var bindings = query.getBindings(); //=> [1] |
Ah, my mistake on the Knex :) Thank you so much for helping as well :) ! My initial thoughts (I forget if I said this before) around thinking |
Ugh, I need to merge this already :) I've been sitting there with your PR rebased on top of current I really do think using a method on the object is a good way, as the only other way would be to introduce a way to add a filter to all object such that you define converters separately from the objects themselves, such that tampering would have to happen outside of the user-controlled object. IDK man |
To be fair, if someone has the ability to externally influence the But I understand your concern. Created #13 as a possible alternative... |
Adds the ability to raw "escape" by passing an object which contains a
toSQL
method.This is also great for generic function handling:
This is per the discussion on #8 with @dougwilson