typescript-sql-tagged-template-plugin icon indicating copy to clipboard operation
typescript-sql-tagged-template-plugin copied to clipboard

How to use fragments inside sql queries?

Open pleerock opened this issue 3 years ago • 3 comments

Thank you for your wonderful extension!

As I understand fragments are supposed to be parts of sql queries, they are useless otherwise. But how to include them inside sql queries?

const photoJoin = sqlFragment`
    INNER JOIN "photos" "photo" ON "photo"."authorId" = "user"."id"
`
const usersSql = sql`
SELECT * FROM "users" "user" ${photoJoin} WHERE userId=${userId}
`

But using this fragment leads to Failed to parse: syntax error at or near "$1". error. Did I miss something? Thanks!

pleerock avatar May 10 '21 20:05 pleerock