blakeembrey / sql-template-tag

ES2015 tagged template string for preparing SQL statements, works with `pg`, `mysql`, and `sqlite`

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Treatment of escaped back ticks

taylorgoolsby opened this issue · comments

Why are these different:

sql = sqltag`\`name\``
sql = mysql.format(sql.sql, sql.values)
// output is "\\`name\\`"
sql = mysql.format(`\`name\``)
// output is "`name`"

I ran these in runkit.

It's a problem for me because I have queries like this:

sql = sqltag`
  UPDATE User SET
  \`name\` = 'Taylor';
`
sql = mysql.format(sql.sql, sql.values)

Output:

UPDATE User SET
\`name\` = 'Taylor';

The above output is invalid syntax.

The correct output should look like this:

sql = mysql.format(`
  UPDATE User SET
  \`name\` = 'Taylor';
`)

Output:

UPDATE User SET
`name` = 'Taylor';

Sounds like an oversight with using raw strings on my side. I can investigate the trade-offs with changing this and get a fix out for you.

Nice! Thank you so much!