aquametalabs / aquameta

Web development platform built entirely in PostgreSQL
GNU General Public License v3.0
1.1k stars 52 forks source link

endpoint: support SETOF RECORD functions #237

Open erichanson opened 3 years ago

erichanson commented 3 years ago

PostgreSQL functions that return RECORD and SETOF RECORD are very handy because they can return results with variable structures, unlike most PostgreSQL functions which must always return results with the same column/columns. For example if we wanted to create a function bundle.row_at_commit(meta.row_id, commit_id), if its return type was SETOF RECORD it could any row at any particular commit. The caveat though is that when you call a function that returns SETOF RECORD, you have to also include the structure of the expected result.

We can support these with endpoint, but would need to add an additional parameter that specifies the expected table structure.. Design and implement. Generally, functions and the result sets they return need an audit. We probably want to follow a pattern similar to how we do with relations, aka methods that return row (zero or one rows as JSON), rows (zero or more rows as JSON), field (the literal value returned, as the configured mimetype). There is a whole matrix of how these would map to all the different types of PostgreSQL result types, as well as all the different datum.js types.