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
Handle sql comments inside the sql tagged template literal #107
Comments
I cannot think of a straightforward way to implement this. If you are available, give it a go – it would be a valuable contribution. |
This is why within I've said it before, and can only repeat it that any serious database module needs proper use of external SQL files. Writing gigantic SQL inside code is a terrible idea. Not only it is unmanageable that way, but you cannot even handle comments like that, or join multiple SQL statements independently. |
Eliminating the comments once you have the entire SQL is not the problem. The challenge is removing the associated values after they were bound. We cannot remove values before the query is ready to execute because there are no guarantees that the entire token is present, i.e. unsafe to make assumptions about start/ end of a comment. |
🎉 This issue has been resolved in version 24.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Living up to the "Promotes writing raw SQL" motto, I was wondering how can we use sql comments (that is,
-- a comment
and/* a comment */
) inside this librarysql
tagged template literal.More concretely, using a simple table like
sometimes I would like to be able to turn this
into this:
The second js snippet above will fail because the
query
object created by slonik will still create 3 value bindings ($1, $2, $3):However it will work if we delete the sql comment line in VALUES. In that case we get:
So the multiline javascript string given to the
sql
tagged template would have to be pre-processed somehow to have sql comments removed.Would this be a useful addition to slonik? If so I'd like to contribute.
The text was updated successfully, but these errors were encountered: