-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
nest the top resource - Add a way for * to be remapped in select #3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you show the SQL query you do for this? Is it something like: select (id,name) as "$" from test.projects;
$
------------------
(1,"Windows 7")
(2,"Windows 10")
(3,IOS)
(4,OSX)
(5,Orphan)
(5 rows) I'm not seeing why would this be useful. |
It's rather select tbl as "$" from test.projects tbl When outputing JSON, since this is a row type, then the result is a json object. The beauty of it is that you actually don't even have to list all the fields ! It's useful when calling subrelations so as to not mix fields and objects.
Here, it allows me to use frameworks on the client side that know how to deserialize into custom instances directly "$" into, say, the "principal" object and "some_relation" into other instances. This is actually a real requirement : it has been a pain point for me to have to deal with the fields of my table being mingled with fields that regard a distant relation. My code actually has to split the result from postgrest. I think it has a place ; it's kind of the reverse of |
Hm, so instead of "unnesting" you want to "nest" the resulting JSON arbitraritly. GET /my_table?select=my_custom_nest:*,some_relation(*) Q: Is this only relevant for the root resource? Because you can already rename nested/embedded resources |
A: Yes it is for the reason you mentioned. And yes, this is exactly what I wish to do. |
Doing the above seems possible on PostgreSQL side, but I don't think that's the right URL syntax. |
One idea could be to have a special placeholder that refers to the root resource, say
|
That would do the trick nicely. |
If we were doing something like this, I think the "alias the star" approach would be really nice and clean. I'd not want to introduce even more new syntax. |
With "alias the star" you couldn't control the specified columns. Additionally, the
This is also not a priority for me and not sure if this is the right syntax. I guess the feature makes sense to allow the complete shaping of the resulting JSON though. |
Actually, better proposition (imo) :
I added indentation for readability. I am thus proposing that instead of aliasing What do you think ? |
It does look better in terms of flexibilty but it's strange to have an "empty" resource
The above syntax makes it a bit clearer that we are manipulating the resulting JSON too, whereas with the |
Still it would be much better we had an explicit operation to do the above instead of a special placeholder. Something like the spread |
I haven't thought about the parsers, but "empty" in this place would really be a natural extension of our existing syntax, so +1 for that. |
I guess it should be fine, since we already support empty embeds. I can't think of a better syntax. |
/my_table?select=$:*
is an error. I can rename a field with select. Since in postgres it is possible to select a whole row, it would be interesting to be able to rename it as well.While on its own it may not look much, when traversing relationships, it gets really interesting - especially on the frontend side for deserialization.
The text was updated successfully, but these errors were encountered: