How to encode prisma find many result as JSON? #332
Answered
by
RobertCraigie
felinto-dev
asked this question in
Q&A
-
Could you give me some advice about what to do here? I need to pack and send Prisma query results to third-party API but I always receive an error. PS: If I print the "downloads" variable I get a downloads list, as expected. |
Beta Was this translation helpful? Give feedback.
Answered by
RobertCraigie
Mar 12, 2022
Replies: 1 comment 5 replies
-
Prisma queries return pydantic models. If you need to serialise a model to JSON then you simply have to call Serialising a list of models is more complicated, but this should work for you (I'm on mobile and can't confirm at the moment): from typing import List
from pydantic import BaseModel
from prisma.models import DownloadRequest
class DownloadRequestList(BaseModel):
__root__: List[DownloadRequest]
data = DownloadRequestList(__root__=downloads)
return data.json() |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
felinto-dev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prisma queries return pydantic models. If you need to serialise a model to JSON then you simply have to call
.json()
.Serialising a list of models is more complicated, but this should work for you (I'm on mobile and can't confirm at the moment):