sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Added typecheck to sqlalchemy JSON

Open LucaGelmini opened this issue 1 year ago • 6 comments

In sqlmodel/main.py there was missing a typecheck for the JSON type supported by sqlalchemy. So it was not possible to define a model with a JSON field.

LucaGelmini avatar May 08 '24 15:05 LucaGelmini

please add JSONB support too

mmmcorpsvit avatar May 09 '24 18:05 mmmcorpsvit

Ah, never mind. Found a fix:

from sqlmodel import SQLModel, Field, JSON


class User(SQLModel, table=True):
    id: int = Field(..., primary_key=True)
    data: JSON = Field(default={}, sa_type=JSON)

vduseev avatar Jul 12 '24 17:07 vduseev

Hi @vduseev @LucaGelmini is there an update on when this can be merged?

alessiamarcolini avatar Jul 19 '24 14:07 alessiamarcolini

As I see this can be merged right now. The JSON compatibility was supported by SQLAlchemy, just that it wasn't implemented inside the SQLModel map of the SQLAlchemy types. So, I just changed two lines to include the JSON class 😂. Very straightforward change.

LucaGelmini avatar Jul 19 '24 14:07 LucaGelmini

First collaboration in a repo though, so if I'm missing something please tell me 🫡

LucaGelmini avatar Jul 19 '24 14:07 LucaGelmini

Really want this to be merged 🙏

TimNekk avatar Sep 06 '24 14:09 TimNekk