-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Automatic Filters for Auto Generated Endpoints #15
Comments
@dtiesling do you want to do it? |
Sure! If I can write it for flask-muck I’m sure I can get it working for fastcrud. Assign it to me and I’ll check it out this week. |
I don't think I'm following this ticket. I thought the request was to add filtering to get_multi but the docs say that is already supported. |
I believe it's for the get_multi endpoint, not the method. Can you please clarify it @AndreGuerra123? |
OIC I missed that it wasn't implemented at the endpoint level. This will be an interesting way to learn FastAPI. @igorbenav do you have any opinions on the schema for sending filters? In Flask-Muck I have it as json-encoded object in the Another option is to try dynamically building a list of all possible filters for a model and adding those to the endpoint. It also looks simple to grab all the parameters off the raw request object and use those to generate the arbitrary filters but then they wouldn't be documented in the OpenAPI spec. |
Hmm maybe combining json-encoded objects for complex filters, but still dynamically building the simple filters by column is a good balance between simplicity and flexibility. Another possibility is actually creating all possible (even complex) filters based on the column type (numeric or date alow gt, gte etc). This would be complete chaos when there are too many filters though. Either way, I think it would be best to let the user have some control over it, having the option of no filters, simple filters only or combined for example. What do you think? |
From my understanding (I could be totally wrong), the get_multi method is used by the endpoint. I assume that if there are some filters defined in the method it works. However, there are several caveats some specific to the get_multi method, others to the filtering strategy itself:
Recommendation from what I feel it's intuitive:
Hope I have helped. If you need the refs I found from other projects I will gladly add them here. Just not want to contaminate your project with external links. Regards, |
I had a little time to look into this tonight. Having the filters come in as a json blob makes the whole thing easier from an implementation standpoint because there is a static query param argument that we can type hint. If the preference is each filter is its own query param I'm leaning toward an approach where the query params are read directly from the request object. To handle the issue of the openapi spec I think there could be a helper that generates all the openapi parameters and passes it to the |
Cool, @dtiesling, go ahead and update as you go please |
Hey, @dtiesling, any news? |
Sorry @igorbenav Ive had a ton of stuff come up lately and haven’t been able to get to this. You should pull me off of this ticket and I’ll update here if I free up and can make more movement on it. |
Sure |
Hi folks, I'm in the same scenario. I would like to filter or add a WHERE clause in this |
@samuel-favarin-dbc if you are talking about FastCRUD's get_multi method, you can already do this. You just need to pass the filters as kwargs, documentation here. Ex: get all users with name "John": crud = FastCRUD(User)
crud.get_multi(
db=db,
name="John"
) It also supports filters like greater than, greater than or equal etc. Docs here. If you are talking about filters in the auto generated get_multi endpoint, I need to do some stuff before. |
Is your feature request related to a problem? Please describe.
I would like to be able to filter get_multi endpoint.
Describe the solution you'd like
I want to be filtering and searching in the get_multi endpoint. This is such a common feature in most CRUD system that I consider relevant. This is also available in flask-muck.
Describe alternatives you've considered
Some out-of-the-box solution are out there:
https://github.com/arthurio/fastapi-filter (sqlalchemy + mongo)
https://github.com/OleksandrZhydyk/FastAPI-SQLAlchemy-Filters (specific sqlalchemy)
Additional context
Add any other context or screenshots about the feature request here.
Ifnot being implemented could an example be provided?
The text was updated successfully, but these errors were encountered: