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

Is it possible to use the sqlAlchemy expression distinct()? #179

Open
DjingoDjango opened this issue Aug 7, 2018 · 1 comment
Open

Is it possible to use the sqlAlchemy expression distinct()? #179

DjingoDjango opened this issue Aug 7, 2018 · 1 comment
Labels

Comments

@DjingoDjango
Copy link

First off; A big thank you to the people who have contributed to making both pyeve and eve-sqlalchemy! Fantastic tools!

the eve-sqlAlchemy docs state the following:
With this version of Eve you can use SQLAlchemy expressions such as: like, in, any, etc.

This question pertains to the "etc" part. I would like to query a stock history for the most recent transaction for each article type in stock history. The docs refer to the SA documentation SQLAlchemy internals for an elaboration on the etc part.

I found a distinct() expression in the referenced documentation. Reading some more of the sqlalchemy docs I fear that this is not an expression that would be of help in my specific case. But I would like to double check with you guys just to be sure.

I have tried a range of different query syntax. This one;
http://"domain-or-ip"/stock?where={"article":"distinct('article')"} returns an empty xml file. The fact that it is not throwing an error message was the reason why I thought it migth be ok to ask this question here.

I hope this question is not out of bounds and would like to extend my gratitude in advance, to any answer, regardless of whether or not the answer is of help!

@dkellner
Copy link
Collaborator

I'm afraid the "easiest" way to support this request would be to add a custom endpoint (e.g. with a Flask blueprint). Using DISTINCT alone would not give you the desired results anyway, you would need to group by article type to be able to use MAX on the date.

Unfortunately getting the query right will not help you with rendering the response properly (and adhering to all those Eve settings like pagination).

@nicolaiarocci Do you happen to have a good recipe for adding custom read-only endpoints to Eve where the only customization is the selection which records to show? I just did a quick research and it seems not too many people are asking for this, so maybe it's obvious and I'm missing something here.

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

No branches or pull requests

2 participants