-
Notifications
You must be signed in to change notification settings - Fork 4
Replace the mediaitems_view in some cases.
#920
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
Conversation
This allows us to pass in the needed episode_ids and cut the query time by 2 orders of magnitude. There are a few consequences: * SQLc config needed to be upgraded to v2 * In order for SQLc to properly understand the function it needs a active SQL connection * The function returns are always "nullable" so we need to account for that in the Go code * Since the returns for the `list` variant is no longer identical we need a separate mapping
backend/sqlc.yaml
Outdated
| json_tags_case_style: camel | ||
| overrides: | ||
| # For reference, when we need string-arrays (e.g. "usergroups" for a row on the materialized view) | ||
| # I think I had to do that manually for every column like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol i think this is a remnant from my POC. can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding the db connection is fine with me although it's ofc nice to avoid it if we can.
the nullability is less comfortable but since it's only that function its not horrible.
- maybe run once locally first.
- try the out param thing, maybe it works without a connection
but i approve, its gefn if you want to merge this
|
|
||
| -- +goose StatementBegin | ||
| CREATE OR REPLACE FUNCTION mediaitems_by_episodes(episodeids int[]) | ||
| RETURNS TABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe try OUT params, since this PR is mentioning that: sqlc-dev/sqlc#3175
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately you can't combine them: [42804] ERROR: RETURN cannot have a parameter in function with OUT parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other alternative would be to create a materialized view for the innermost SELECTS, then we could probably get away with a "normal" view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now using "setof" option for returning from a function
This takes care both of needing a real DB connection, as well as nullable fields.
This takes care both of needing a real DB connection, as well as nullable fields.


This allows us to pass in the needed episode_ids and cut the query time by 2 orders of magnitude.
There are a few consequences:
listvariant is no longer identical we need a separate mappingThe logic is tested but I have not tested it yet with an running API.