Re:PostgresJs: The Fastest full featured PostgreSQL client f...
by joshuacc on Saturday October 14, 2023 @11:11AM
(#37881094)
Tags 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.
Re:PostgresJs: The Fastest full featured PostgreSQL client f...
by brap on Saturday October 14, 2023 @11:13AM
(#37881112)
Ohhh got it, thanks!
Re:PostgresJs: The Fastest full featured PostgreSQL client f...
by whenlambo on Saturday October 14, 2023 @11:10AM
(#37881084)
You can use expressions inside template literals and those are auto-escaped for you by postgres.js
Re:PostgresJs: The Fastest full featured PostgreSQL client f...
by brap on Saturday October 14, 2023 @11:12AM
(#37881105)
What 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!
Re:PostgresJs: The Fastest full featured PostgreSQL client f...
by crubier on Saturday October 14, 2023 @04:41PM
(#37884083)
Also, 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
From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).