-
Notifications
You must be signed in to change notification settings - Fork 0
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: implement pagination behavior for grouped models #125
Conversation
97d281b
to
988f836
Compare
988f836
to
9205a38
Compare
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.
That seems a bit overengineered to me ;)
Why even bother with a query constructor? You could combine the get_items_query_constructor
and the construct_
methods into one:
get_query(model, query, limit, offset):
if group_by_value := getattr(model, "model_config", {}).get("group_by", None):
return construct_grouped_pagination_query(query, group_by_value, limit, offset)
return construct_ungrouped_pagination_query(quer, limit, offset)
I deliberately implemented this using match case because this allows pattern matching on It is very likely that additional constructors will be needed in the future (e.g. for filtering and ordering etc), so I feel like this should be pluggable. I am aware that query construction is kind of untidy at the moment, this is why I will implement #134 as soon as these changes are merged. |
The commit message starts with: "The get_items_query_constructor should be implemented using match/case;" - I'm not sure what this means The
We can easily make this pluggable once this is actually needed. We don't have to make the code overly complex so we can cater to every possible scenario that might come up in the future. |
True, this is misleading, will change the commit message.
I essentially agree, still I am much in favor of using the suggested The alternative to using the partial pattern matching mechanism on the The |
259e558
to
0ba0f09
Compare
The (Another example is the |
This might be (a mild case of) overengineering now. I would agree on implementing Generally, I see your point and you are correct. But if I completely tear this down now, I will have to re-implement everything for issue #134 again. I have a pretty clear picture now of how the query construction logic should be organized. So the current PR is more of a documented transition to the (urgently needed) #134 refactoring.
I totally agree, this is a remnant from an earlier implementation. I still want |
ccdac22
to
b1ddf09
Compare
b1ddf09
to
5ec7256
Compare
5ec7256
to
6598e6c
Compare
Ok, here is another version: I encapsulated the class SPARQLModelAdapter(Generic[_TModelInstance]):
# ...
def query(
self,
*,
page: int = 1,
size: int = 100,
) -> Page[_TModelInstance]:
"""Run a query against an endpoint and return a Page model object."""
count_query: str = construct_count_query(query=self._query, model=self._model)
items_query: str = construct_items_query(
query=self._query,
model=self._model,
limit=size,
offset=calculate_offset(page, size),
)
# ... This might still be considered overengineered or at least "eagerly modular", but as I said, I consider this PR more as a documented transition towards an |
Closes #114.