Comments (6)
I had a quick play around with this.
My main challenge now is creating a Pydantic model (which is used in the OpenAPI schema if using FastAPIWrapper
) for this:
{
"queries": [
{
"director": "Bay",
"director__match": "exact"
},
{
"director": "Abrams",
"director__match": "exact"
}
]
}
This would be easier:
{
"queries": [
"director=Bay&director__match=exact",
"director=Abrams&director__match=exact"
]
}
So the model is just:
class QueryModel(BaseModel):
queries: list[str]
But I think having it an object is preferable. Will play around some more.
from piccolo_api.
Was the problem that if we need to specify too many values for __visible_fields
we exceed the max URL size?
GET /movie/?__visible_fields=id,name,director.name
I know we discussed adding an all
option:
GET /movie/?__visible_fields=id,name,director.all
Is that enough to solve the problem? I thought about allowing the __visible_fields
to be specified as a header as well - not sure if that would help.
In terms of allowing multiple queries in one go, we could add something like PiccoloCRUDAggregate
.
Some rough pseudo-code:
class PiccoloCRUDAggregate:
def __init__(self, crud_classes: list[PiccoloCRUD]):
self.crud_classes = crud_classes
def post(self, payload):
response = []
for query in payload.queries:
response.append(self.some_crud_class.process_query(query))
return response
We would call it like:
POST /crud-aggregate/
{
"queries": [
"/movies/?__visible_fields=name,director.name",
"/actors/?__visible_fields=name",
]
}
That would allow multiple requests to be processed in one go (almost GraphQL like), but I'm not sure if that's what you had in mind.
from piccolo_api.
This is separate from the earlier visible fields feedback, we just are needing rows back from multiple different matches. The aggregate function would work but I'd rather one for each model for better type support.
Query would be like
POST /movies/batch/get
{
queries: [
{
director: "Bay",
director__match: "exact"
},
{
director: "Abrams",
director__match: "exact"
}
]
}
Pseudo code:
def post(self, payload):
response = []
for query in payload.queries;
response.append(self.base_method(convert_dict_to_query_params(query)))
return response
from piccolo_api.
Yeah, I like that.
I'm just thinking about what the endpoint's URL should be.
POST /movies/batch/get
POST /movies/query/
POST /movies/search/
from piccolo_api.
It could also be /movies/batch then add a method: "GET" in the body. Though that might make types confusing.
I think since there is already bulk delete and an upcoming bulk update, it would probably make more sense to make a unique name like you've suggested in those last two examples. I like query more than search, since search implies something else in my mind.
from piccolo_api.
That's already amazing progress! Thanks so much!
from piccolo_api.
Related Issues (20)
- Update `logging.getLogger()` to use `__name__` instead of `__file__` HOT 3
- Support async validator functions
- Python 3.11 support
- Extend `db_exception_handler` to handle not-null exceptions
- CRUD Endpoint POST response is a list HOT 9
- Starlite support HOT 17
- Feature Request: Instead of just exposing the crud endpoints, can it generate the actual methods in a file? HOT 2
- Be able to sort by multiple columns in `PiccoloCRUD`
- Add `allow_unauthenticated` to `JWTMiddleware`
- TypeError: __init__() got an unexpected keyword argument 'excluded_paths' HOT 5
- Feature to modify body and query_parameters in `PiccoloCRUD` HOT 8
- Fix code scanning alert - Unused global variable
- Drop Python 3.7 support
- Catch foreign key constraint errors in `PiccoloCRUD`
- `schema_extra` param not passed to `pydantic_model_{output | optional | plural}` methods HOT 1
- Piccolo Admin API docs are not rendering
- Better error display on PATCH request
- Alpha version for Pydantic 2.0 / Piccolo 1.0a1? HOT 2
- PiccoloCRUD `post_single` return id of the inserted row instead of the row HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piccolo_api.