postgres-schema-ts icon indicating copy to clipboard operation
postgres-schema-ts copied to clipboard

Functions that return a table

Open ghost opened this issue 4 years ago • 2 comments

Hi @nettofarah , this is a super useful tool. Do you know if it would be possible to generate types for functions that return a table? Like for example:

CREATE FUNCTION get_groups()
    RETURNS TABLE (
        group_id integer,
        group_name text
    )
    LANGUAGE sql
AS $$
    -- SELECT ...
$$;

I would expect it to generate:

export interface get_groups {
  group_id: number
  group_name: string
}

ghost avatar Dec 29 '20 21:12 ghost

Hey, @joaopaulobdac. Thanks for the suggestion. This is the first time I hear about functions that return tables.

Would you like to start a pull request? I'm happy to help out any way I can. Maybe start with an unit/integration test, and I could help fill in the blanks with some implementation code?

nettofarah avatar Dec 31 '20 19:12 nettofarah

Yeah! I will be occupied in january because I have a couple of important exams in the upcoming weeks but after that I can start. You can use this type of function similarly to a view, with the benefit of being able to pass parameters to it.

joaopaulobdac avatar Dec 31 '20 20:12 joaopaulobdac