sqlx-ts
sqlx-ts copied to clipboard
Selecting * does not create proper types
When using this code:
const usersQuery = await dataSource.query({
text: sql`
SELECT
*
FROM
"user"
WHERE
id = ANY($1)
`,
values: [ids],
});
The following types are generated:
export type UsersQueryParams = [boolean];
export interface IUsersQueryResult {
};
export interface IUsersQueryQuery {
params: UsersQueryParams;
result: IUsersQueryResult;
};
If I explicitly select a specific field, it works. This is my configuration:
{
"generate_types": {
"enabled": true,
"convertToCamelCaseColumnName": true
},
"connections": {
"default": {
"DB_TYPE": "postgres",
"DB_HOST": "localhost",
"DB_PORT": 26257,
"DB_USER": "root",
"DB_PASS": "passwd",
"DB_NAME": "defaultdb"
}
}
}
Using the latest and greatest 0.14.0.
My database is CockroachDB. Not sure if it has anything to do with it, but it is postgres based.
This is probably the same bug as the other issue https://github.com/JasonShin/sqlx-ts/issues/134 - this is caused by the quoted table name. I can see the wildcard queries are working correctly without the quotes around the table name
SELECT
*
FROM
user
WHERE
id = ANY($1)
The fix for this is being tracked here https://github.com/JasonShin/sqlx-ts/pull/135