ORM: support json
- Dominant language
- Python
- Stars
- 415
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
We are not unpacking JSON by default -- we should consider doing that.
Pydantic supports JSON unpacking (partial & full), details here: https://docs.pydantic.dev/latest/concepts/json/#json-parsing
-----------------
If we have this in the schema
```esdl
type User {
name: str;
data: json;
}
```
we can maybe enable something like this then:
```python
# User subclasses the generated model:
class MyUser(models.default.User):
data: gel.JsonUnpacker[
models.default.User.__typeof__.data,
MyDataModel
]
# User defines their model to parse JSON:
class MyDataModel(pydantic.BaseModel):
...
```
Or, alternatively:
```python
# User subclasses the generated model to
# specify a *new* computed field to unpack
# JSON into
class MyUser(models.default.User):
parsed_data: gel.JsonUnpackFrom[
models.default.User.__typeof__.data,
MyDataModel
]
# User defines their model to parse JSON:
class MyDataModel(pydantic.BaseModel):
...
```
I think we have two options:
1. Always unpack JSON -- if there's a type for it setup -- use that. No type -- return whatever `json.loads()` returns
2. Only unpack JSON when the user asked for it, either with ORM model customization, or with the upcoming `.with_codecs()` API.
I'm in favor of (2).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.