sqlc-dev / sqlc-gen-typescript

289 stars 12 forks source link

Inability to create queries with Array arguments #29

Open ex-nihil opened 3 months ago

ex-nihil commented 3 months ago

I am experiencing an issue where it is not possible to create queries with an argument that takes an array of items. The documentation provides the following examples for creating such queries:

-- name: ListAuthorsByIDs :many
SELECT * FROM authors
WHERE id IN (sqlc.slice('ids'));
-- name: ListAuthorsByIDs :many
SELECT * FROM authors
WHERE id = ANY($1::int[]);

However, these methods do not generate the expected TypeScript types for the input arguments. Using ANY($1::int[]) results in a missing identifier.

{
    : number[];
}

Using sqlc.slice('ids') results in the type not being identified as an array.

{
    ids: string;
}

Steps to Reproduce

The steps are for postgresql, but the issue seems to be the same for all SQL dialects.

ex-nihil commented 3 months ago

Was able to work around it by using sqlc.arg together with ANY.

-- name: ListAuthorsByIDs :many
SELECT * FROM authors
WHERE id = ANY(sqlc.arg(id)::int[]);