pgtyped
pgtyped copied to clipboard
Incorrect column name for unnamed column
I have the following query:
const checkBlacklist = sql<ICheckBlacklistQuery>`
SELECT COUNT(*) > 0
FROM user_blacklist
WHERE
(user_id = $userID AND target_user_id = $targetUserID)
OR (user_id = $targetUserID AND user_id = $userID)
`
In this query, I don't give column a name, and by default, PostgreSQL returns column named ?column?
. Unfortunately, pgtyped uses this exact name, without escaping or checking, for the generated type:
/** 'CheckBlacklist' return type */
export interface ICheckBlacklistResult {
?column?: boolean;
}
Which is invalid Typescript code.
Thanks for reporting this. It should certainly be escaped. Meanwhile a temporary solution will be to name the column:
const checkBlacklist = sql<ICheckBlacklistQuery>`
SELECT COUNT(*) > 0 AS is_user_blacklisted
FROM user_blacklist
WHERE
(user_id = $userID AND target_user_id = $targetUserID)
OR (user_id = $targetUserID AND user_id = $userID)
`
Anonymous return fields are now explicitly forbidden and generate an error. Please consider naming them instead.