sqlx-ts icon indicating copy to clipboard operation
sqlx-ts copied to clipboard

Selecting * does not create proper types

Open simplenotezy opened this issue 1 year ago • 1 comments

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.

simplenotezy avatar Jun 26 '24 20:06 simplenotezy

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

JasonShin avatar Jun 27 '24 12:06 JasonShin