andywer / andywer/postguard

Support for column aliases (`as`)

Aperta
#30 1 commento 2 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
TypeScript
Stelle
179
Fork
7
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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 {
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`:

```sql
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!

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.