postguard
postguard copied to clipboard
Support for column aliases (`as`)
Thanks for writing this library, it's exactly what I was looking for.
Is there a way to support column aliases? Here's what I get right now:
✖ Query validation failed in server/models/SomeModel.ts:39:13:
No table in the query's scope has a column "user_token".
Tables in scope: "some_table"
37 | export async function getUserToken(requestId: string): Promise<string | null> {
38 | const { rows } = await database.query<{user_token: string}>(sql`
> 39 | SELECT details -> 'user_token' AS user_token FROM some_table WHERE
| ^
40 | request_id = ${requestId} AND
41 | details -> 'user_token' IS NOT NULL
42 | ORDER BY timestamp DESC;
The workaround that seems to be fine is by using sql.raw
:
SELECT ${sql.raw('details -> \'user_token\' AS user_token')} FROM some_table WHERE
request_id = ${requestId} AND
details -> 'user_token' IS NOT NULL
ORDER BY timestamp DESC;
Is this the best way to handle it? Thanks!
Hi Andrew! Yeah, stick to that work-around for now if it works.
I cannot promise when exactly I will be able to look into this, but it should definitely be possible.
Thanks for reporting, btw.