4 ms·
Can anyone explain to me the purpose of tagged template strings? From what I understand it’s only a function that takes in a string, so this might have just be
by brap 3y ago
Can anyone explain to me the purpose of tagged template strings?
From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).
- whenlambo 3y agoYou can use expressions inside template literals and those are auto-escaped for you by postgres.js
- brap 3y agoWhat do you mean? This is true for any template string, not specifically the tagged template strings, no? Edit: I think I understand now from the other comment, thanks!
- joshuacc 3y agoTags are functions that receive an array of strings and then a series of arguments corresponding to values passed in the interpolation slots, allowing you to use template literal syntax while the tag function does something much more complex under the hood, potentially including returning non-string values.
- brap 3y agoOhhh got it, thanks!
- crubier 3y agoAlso, template strings like sql`foobar`, graphql`foobar` and others enable syntax awareness in IDEs. I have a big Typescript / SQL mixed codebase (No ORM), and its very nice to have VSCode syntax color and code-format TypeScript, GraphQL and SQL in the same file