prisma-client-py icon indicating copy to clipboard operation
prisma-client-py copied to clipboard

Support query raw annotations

Open RobertCraigie opened this issue 2 years ago • 3 comments

Problem

Prisma recently changed how raw queries work internally, values are now returned alongside meta information, for example:

{
  "count": {"prisma__type": "bigint", "prisma__value": "1"}
}

Suggested solution

We need to figure out how to support this internally as we can't just naively return the results from the raw query anymore, we may have to do some form of parsing using a BaseModel / Field...

RobertCraigie avatar Jun 28 '22 10:06 RobertCraigie

Will there be an object.type attribute?

TheOnlyWayUp avatar Jun 28 '22 15:06 TheOnlyWayUp

@TheOnlyWayUp I was planning for this change to be internal only, so everything would stay the same for users.

In the Node client, the raw query annotations are used internally to be able to correctly deserialize the response data, I suspect it will end up being the same solution for us.

The raw query interface could be updated to return an object instead of a dictionary but I'm not sure how I feel about that yet. Example:

record = await client.query_first('SELECT name FROM User')
assert record.name == 'Robert'

I know that this solution would work with Pyright (as it respects a custom __getattr__ and disables type checking) but I'm not sure if mypy plays nicely with this.

RobertCraigie avatar Jun 28 '22 15:06 RobertCraigie

Hi Robert, maybe this will help you. To generate dynamic model. https://github.com/carlos-rian/pysqlx-engine/blob/main/sqlx_engine/_core/parser.py

carlos-rian avatar Jul 19 '22 02:07 carlos-rian