Feature request: a way to convert edgedb.Object to dict
See original GitHub issueSummary
Currently Object
class does not look like dict and different tools do not understand how to use it.
My suggestion is to add Object.to_dict
method or inherit from python dict
to allow direct use.
Use case
Converting query result to pydantic model:
class User(pydantic.BaseModel):
id: uuid.UUID
nickname: str
created_at: datetime.datetime
bio: Optional[str] = None
async def get(db: edgedb.AsyncIOConnection, *, id: uuid.UUID) -> Optional[User]:
result = await db.fetchall(
"""
SELECT User {
id,
nickname,
bio,
created_at,
}
FILTER
.id = <uuid>$id
AND .email_vefified = true
LIMIT 1
""",
id=id,
)
if not result:
return None
return User.parse_obj(result[0]) # unable to parse edgedb.Object
There are workarounds to this neither of which look good enough:
- custom function for converting (not convenient, probably not efficient)
- fetching results with
fetchone_json
and then usingparse_raw
pydantic method, but it’s very library specific, forces the use offetchone
overfetchall
and inefficient (double json conversion)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:24 (16 by maintainers)
Top Results From Across the Web
Issues · edgedb/edgedb-python - GitHub
Contribute to edgedb/edgedb-python development by creating an account on GitHub. ... Feature request: a way to convert edgedb.Object to dict.
Read more >Bringing .NET to EdgeDB
Today, we're excited to announce the official .NET binding for EdgeDB! I crafted the first version of the library a few months ago....
Read more >How to convert request.data to dict? - python - Stack Overflow
Edit: For post request: import requests import json url = "https://jsonplaceholder.typicode.com/posts/" payload = { "userId": 10, "id": 901, ...
Read more >NET SDK for Cloud Bucketing - DevCycle Docs
All requests, including user data are sent to DevCycle servers to ensure ... for a given user and return them as Dictionary<String, Feature>....
Read more >PEP 603: Adding a frozenmap type to collections
Author: Yury Selivanov yury@edgedb.com ... a dict ,; another frozenmap ,; an object with an items() method that is expected to return
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would it help if we add tools to generate files like https://github.com/kurtrottmann/simple-stack-fastapi-edgedb/blob/master/backend/app/schemas.py automatically from the DB schema? Would that allow you to no longer depend on pydantic?
And it sounds like you don’t need a recursive
asdict
?This would be amazing. If it was possible to generate Python and TypeScript types from SDL I could use them on every layer of my application stack:
After that add something like
edgerpc
(similar togrpc
) orsdl_to_protobufs
for service to service communication and the toolkit would be complete. 😃