Skip to content
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

feat: insert embedded resources via computed columns #3226

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

laurenceisla
Copy link
Member

@laurenceisla laurenceisla commented Feb 14, 2024

WIP

@laurenceisla laurenceisla changed the title Implement inserting embedding resources via computed columns feat: insert embedded resources via computed columns Feb 15, 2024
@laurenceisla laurenceisla force-pushed the computed-insert branch 2 times, most recently from d7c3354 to 85ad53e Compare April 3, 2024 01:41
@laurenceisla laurenceisla force-pushed the computed-insert branch 2 times, most recently from dfdb39f to 739af4e Compare April 25, 2024 22:30
@steve-chavez
Copy link
Member

739af4e here was merged on 7671d63

@laurenceisla
Copy link
Member Author

laurenceisla commented May 30, 2024

It seems that #2933 is definitely going to be an issue when Prefer: return=representation is requested. Doing something like modifying a table inside a function and then doing a JOIN to that same table, uses the OLD data:

-- "tags" is modified inside "upsert_posts"
-- but the LEFT JOIN will show the OLD unmodified "tags"
SELECT * FROM upsert_posts(...) p
LEFT JOIN tags t ON p.id = t.pid;

It could be solved by embedding the RETURNING value of the function, but it cannot be further embedded. For example:

Here, the tags(post, ...) function returns a post table type. As mentioned above the embed will not be possible since the insertion of tags are not known:

curl "http://localhost:3000/posts?columns=name,tags(name)?select=*,tags(name) \
  -H "Content-Type: application/json" \
  -H "Prefer: return=representation" \
  -d '{"name": "my post", "tags": [{"name": "a"},{"name": "b"}]}'
[{
  "name": "my post",
  "tags": []
}]

Making tags(posts, ...) return tags and then using that as an embedding by default (without adding it to ?select=) could be a solution (but further embeds like select=tags(*,other_embed(*)) are not possible):

curl "http://localhost:3000/posts?columns=name,tags(name) \
  -H "Content-Type: application/json" \
  -H "Prefer: return=representation" \
  -d '{"name": "my post", "tags": [{"name": "a"},{"name": "b"}]}'
[{
  "name": "my post",
  "tags": [{"name": "a"},{"name": "b"}]
}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants