GithubHelp home page GithubHelp logo

Comments (6)

dantownsend avatar dantownsend commented on June 11, 2024 1

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.

dantownsend avatar dantownsend commented on June 11, 2024

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.

mastercoms avatar mastercoms commented on June 11, 2024

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.

dantownsend avatar dantownsend commented on June 11, 2024

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.

mastercoms avatar mastercoms commented on June 11, 2024

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.

mastercoms avatar mastercoms commented on June 11, 2024

That's already amazing progress! Thanks so much!

from piccolo_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.