Recommendation: use template literals
See original GitHub issueNode.js has node-sql-template-strings package, why can’t we have this?
Example:
// mysql:
mysql.query('SELECT author FROM books WHERE name = ? AND author = ?', [book, author])
// is equivalent to
mysql.query(SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`)
Links: https://github.com/felixfbecker/node-sql-template-strings https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >ES6 Template Literals (Template Strings) - CanIUse
Template literals are string literals allowing embedded expressions using backtick characters (`). You can use multi-line strings and string interpolation ...
Read more >JavaScript Template Literals - W3Schools
Template literals provide an easy way to interpolate variables and expressions into strings. The method is called string interpolation. The syntax is:.
Read more >Understanding Template Literals in JavaScript - DigitalOcean
This section will review how to declare strings with single quotes and double ... const template = `Template literals use the \` character....
Read more >Nesting Template Literals: A Recommended Approach
Nesting together multiple template literals can create unnecessary complexity, which reduces the code quality. The code becomes less readable ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am a bit skeptical about this feature. User can easily make a mistake. For example
User can easily forget to put
SQLin front of the query and there is no way for us to provide a warning to user. This is vulnerable to SQL injection.I think we should just go with named placeholder instead. It is harder for user to make mistake
I assume ?? is used for fields, table names and other things that don’t need to be in “quotes”. ? may be used for text
Example, if you were to replace everything:
Thanks