3
return pool.query`select * from mytable where id = ${value}`

What is the above equivalent to in a full javascript?

I tried

return pool.query(`select * from mytable where id = $(value)`) 

but apparently it's different.

It is from https://www.npmjs.com/package/mssql thanks

forJ
  • 4,309
  • 6
  • 34
  • 60
  • 1
    Possible duplicate of [Backticks calling a function](https://stackoverflow.com/questions/29660381/backticks-calling-a-function) – Marty Aug 31 '17 at 05:45
  • same as `return pool.query("select * from mytable where id = " + value)` – Weedoze Aug 31 '17 at 05:50

2 Answers2

2

This syntax;

pool.query`select * from mytable where id = ${value}

is called Tagged Template Literals. It is an ES6 feature.

It is equivalent to;

pool.query([ 'select * from mytable where id =', value ]);

There is more information on this here.

Bulkan
  • 2,555
  • 1
  • 20
  • 31
0

try this one:

return pool.query(`select * from mytable where id = ${value}`) 
Felix
  • 5,452
  • 12
  • 68
  • 163
  • haven't understood the question like you.... I thought he was looking for the right synthax .. – Felix Aug 31 '17 at 05:50
  • 1
    I did not downvote, but answers with no explanation are never as good as they could be. As it stands now, one has to do a manual diff between what you typed and what the OP typed to try to figure out what you changed. That makes your answer useless by itself and certainly far from as good as it could be. Please add words of explanation about what you changed and why. – jfriend00 Aug 31 '17 at 05:50
  • just on mobilephone at the moment ;) sorry for short answer – Felix Aug 31 '17 at 05:57