3 ms·
> You mean you don't see tagged templates used at all? Or just not for sql? Not at all. Thanks for the explanation, so it's not just escaped param substitutio
by The_Colonel 3y ago
> You mean you don't see tagged templates used at all? Or just not for sql?
Not at all.
Thanks for the explanation, so it's not just escaped param substitution.
Which brings up the question if you can combine normal text substitution with SQL substitution, e.g.:
SELECT author FROM books WHERE name LIKE '%${book}%' AND author = ${author} AND ${extraCondition}
(it's pretty common to have to join query segments)
- kaba0 3y agoThe text processor does have context as well, so there is nothing preventing someone from doing just that. Not sure if there will be a standard SQL processor, though.
- deleted 3y ago[deleted]
- voxic11 3y agothe library recommends you do that this way const query = SQL`SELECT * FROM books` if (params.name) { query.append(SQL` WHERE name = ${params.name}`) } query.append(SQL` LIMIT 10 OFFSET ${params.offset || 0}`) or if you need raw values like a table name then just pass append a string. db.query(SQL`SELECT * FROM "`.append(table).append(SQL`" WHERE author = ${author} ORDER BY ${column} `).append(order))