andywer / andywer/postguard

Support for column aliases (`as`)

Đang mở
#30 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
TypeScript
Star
179
Fork
7
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.