adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

Support array literal spread param transform #555

Open nick-keller opened 9 months ago

nick-keller commented 9 months ago

The problem

If you want to have a param that is an array that you can pass to a function, you cannot. For instance:

SELECT FROM my_function(ARRAY['a', 'b', 'c']);

The solution

I added a param transform to allow for array literal spread as shown below.

/*
  @name selectFunctionResult
  @param values -> ARRAY[...]
*/
SELECT FROM my_function(:values);
const parameters = { values: ['a', 'b', 'c'] };
selectSomeUsers.run(parameters, connection);
-- Parameters: ['a', 'b', 'c']
SELECT FROM my_function(ARRAY[$1, $2, $3]);

Unfortunately I am having quite a hard time running everything locally, so maybe @adelsz you should double check on your machine that it works as expected.

Thx!

nick-keller commented 6 months ago

Hey @adelsz ! Could you please help me figure this out please. I just cannot get it to work on my machine 🙏