@@ -36,16 +36,147 @@ test('list', async () => {
3636 "is_set_returning_function": false,
3737 "language": "sql",
3838 "name": "add",
39+ "return_table_name": null,
3940 "return_type": "integer",
4041 "return_type_id": 23,
4142 "return_type_relation_id": null,
43+ "returns_multiple_rows": false,
44+ "returns_set_of_table": false,
4245 "schema": "public",
4346 "security_definer": false,
4447 }
4548 `
4649 )
4750} )
4851
52+ test ( 'list set-returning function with single object limit' , async ( ) => {
53+ const res = await pgMeta . functions . list ( )
54+ expect ( res . data ?. filter ( ( { name } ) => name === 'get_user_audit_setof_single_row' ) )
55+ . toMatchInlineSnapshot ( `
56+ [
57+ {
58+ "args": [
59+ {
60+ "has_default": false,
61+ "mode": "in",
62+ "name": "user_row",
63+ "type_id": 16395,
64+ },
65+ ],
66+ "argument_types": "user_row users",
67+ "behavior": "STABLE",
68+ "complete_statement": "CREATE OR REPLACE FUNCTION public.get_user_audit_setof_single_row(user_row users)
69+ RETURNS SETOF users_audit
70+ LANGUAGE sql
71+ STABLE ROWS 1
72+ AS $function$
73+ SELECT * FROM public.users_audit WHERE user_id = user_row.id;
74+ $function$
75+ ",
76+ "config_params": null,
77+ "definition": "
78+ SELECT * FROM public.users_audit WHERE user_id = user_row.id;
79+ ",
80+ "id": 16498,
81+ "identity_argument_types": "user_row users",
82+ "is_set_returning_function": true,
83+ "language": "sql",
84+ "name": "get_user_audit_setof_single_row",
85+ "return_table_name": "users_audit",
86+ "return_type": "SETOF users_audit",
87+ "return_type_id": 16418,
88+ "return_type_relation_id": 16416,
89+ "returns_multiple_rows": false,
90+ "returns_set_of_table": true,
91+ "schema": "public",
92+ "security_definer": false,
93+ },
94+ ]
95+ ` )
96+ } )
97+
98+ test ( 'list set-returning function with multiples definitions' , async ( ) => {
99+ const res = await pgMeta . functions . list ( )
100+ expect ( res . data ?. filter ( ( { name } ) => name === 'get_todos_setof_rows' ) ) . toMatchInlineSnapshot ( `
101+ [
102+ {
103+ "args": [
104+ {
105+ "has_default": false,
106+ "mode": "in",
107+ "name": "user_row",
108+ "type_id": 16395,
109+ },
110+ ],
111+ "argument_types": "user_row users",
112+ "behavior": "STABLE",
113+ "complete_statement": "CREATE OR REPLACE FUNCTION public.get_todos_setof_rows(user_row users)
114+ RETURNS SETOF todos
115+ LANGUAGE sql
116+ STABLE
117+ AS $function$
118+ SELECT * FROM public.todos WHERE "user-id" = user_row.id;
119+ $function$
120+ ",
121+ "config_params": null,
122+ "definition": "
123+ SELECT * FROM public.todos WHERE "user-id" = user_row.id;
124+ ",
125+ "id": 16499,
126+ "identity_argument_types": "user_row users",
127+ "is_set_returning_function": true,
128+ "language": "sql",
129+ "name": "get_todos_setof_rows",
130+ "return_table_name": "todos",
131+ "return_type": "SETOF todos",
132+ "return_type_id": 16404,
133+ "return_type_relation_id": 16402,
134+ "returns_multiple_rows": true,
135+ "returns_set_of_table": true,
136+ "schema": "public",
137+ "security_definer": false,
138+ },
139+ {
140+ "args": [
141+ {
142+ "has_default": false,
143+ "mode": "in",
144+ "name": "todo_row",
145+ "type_id": 16404,
146+ },
147+ ],
148+ "argument_types": "todo_row todos",
149+ "behavior": "STABLE",
150+ "complete_statement": "CREATE OR REPLACE FUNCTION public.get_todos_setof_rows(todo_row todos)
151+ RETURNS SETOF todos
152+ LANGUAGE sql
153+ STABLE
154+ AS $function$
155+ SELECT * FROM public.todos WHERE "user-id" = todo_row."user-id";
156+ $function$
157+ ",
158+ "config_params": null,
159+ "definition": "
160+ SELECT * FROM public.todos WHERE "user-id" = todo_row."user-id";
161+ ",
162+ "id": 16500,
163+ "identity_argument_types": "todo_row todos",
164+ "is_set_returning_function": true,
165+ "language": "sql",
166+ "name": "get_todos_setof_rows",
167+ "return_table_name": "todos",
168+ "return_type": "SETOF todos",
169+ "return_type_id": 16404,
170+ "return_type_relation_id": 16402,
171+ "returns_multiple_rows": true,
172+ "returns_set_of_table": true,
173+ "schema": "public",
174+ "security_definer": false,
175+ },
176+ ]
177+ ` )
178+ } )
179+
49180test ( 'list functions with included schemas' , async ( ) => {
50181 let res = await pgMeta . functions . list ( {
51182 includedSchemas : [ 'public' ] ,
@@ -136,9 +267,12 @@ test('retrieve, create, update, delete', async () => {
136267 "is_set_returning_function": false,
137268 "language": "sql",
138269 "name": "test_func",
270+ "return_table_name": null,
139271 "return_type": "integer",
140272 "return_type_id": 23,
141273 "return_type_relation_id": null,
274+ "returns_multiple_rows": false,
275+ "returns_set_of_table": false,
142276 "schema": "public",
143277 "security_definer": true,
144278 },
@@ -186,9 +320,12 @@ test('retrieve, create, update, delete', async () => {
186320 "is_set_returning_function": false,
187321 "language": "sql",
188322 "name": "test_func",
323+ "return_table_name": null,
189324 "return_type": "integer",
190325 "return_type_id": 23,
191326 "return_type_relation_id": null,
327+ "returns_multiple_rows": false,
328+ "returns_set_of_table": false,
192329 "schema": "public",
193330 "security_definer": true,
194331 },
@@ -240,9 +377,12 @@ test('retrieve, create, update, delete', async () => {
240377 "is_set_returning_function": false,
241378 "language": "sql",
242379 "name": "test_func_renamed",
380+ "return_table_name": null,
243381 "return_type": "integer",
244382 "return_type_id": 23,
245383 "return_type_relation_id": null,
384+ "returns_multiple_rows": false,
385+ "returns_set_of_table": false,
246386 "schema": "test_schema",
247387 "security_definer": true,
248388 },
@@ -290,9 +430,12 @@ test('retrieve, create, update, delete', async () => {
290430 "is_set_returning_function": false,
291431 "language": "sql",
292432 "name": "test_func_renamed",
433+ "return_table_name": null,
293434 "return_type": "integer",
294435 "return_type_id": 23,
295436 "return_type_relation_id": null,
437+ "returns_multiple_rows": false,
438+ "returns_set_of_table": false,
296439 "schema": "test_schema",
297440 "security_definer": true,
298441 },
@@ -345,9 +488,12 @@ test('retrieve set-returning function', async () => {
345488 "is_set_returning_function": true,
346489 "language": "sql",
347490 "name": "function_returning_set_of_rows",
491+ "return_table_name": "users",
348492 "return_type": "SETOF users",
349493 "return_type_id": Any<Number>,
350494 "return_type_relation_id": Any<Number>,
495+ "returns_multiple_rows": true,
496+ "returns_set_of_table": true,
351497 "schema": "public",
352498 "security_definer": false,
353499 }
0 commit comments