JSON and Array types for sqlmodel

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google “How to X in SQLModel” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional

from sqlmodel import Field, SQLModel, JSON, ARRAY


class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    secret_name: JSON
    age: Optional[int] = None

Description

Got following error: new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs) File "pydantic/main.py", line 299, in pydantic.main.ModelMetaclass.__new__ File "pydantic/fields.py", line 411, in pydantic.fields.ModelField.infer File "pydantic/fields.py", line 342, in pydantic.fields.ModelField.__init__ File "pydantic/fields.py", line 456, in pydantic.fields.ModelField.prepare File "pydantic/fields.py", line 670, in pydantic.fields.ModelField.populate_validators File "pydantic/validators.py", line 715, in find_validators RuntimeError: no validator found for <class 'sqlalchemy.sql.sqltypes.JSON'>, seearbitrary_types_allowed in Config

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.8.0

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

28reactions
Chunkfordcommented, Aug 28, 2021

See if this works

from typing import List
from sqlmodel import Field, ARRAY, SQLModel, create_engine, Column, Float


class ArrayData(SQLModel, table=True):
    uuid: str = Field(primary_key=True)
    array: List[float] = Field(sa_column=Column(ARRAY(Float)))
10reactions
mv-yurchenkocommented, Aug 31, 2021

And I think examples with JSON and Array types will be very useful

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use JSON columns with SQLModel - Stack Overflow
I tried it with using SQLAlchemy only and it has worked. So any ideas how can I get the "connection" done between SQLModel...
Read more >
Update Data with FastAPI - SQLModel
Update Data with FastAPI¶. Now let's see how to update data in the database with a FastAPI path operation. HeroUpdate Model¶.
Read more >
Example: Combine a JSON ARRAY and a JSON Expression ...
Combine a JSON array and an expression that evaluates to a JSON array and specify 'ARRAY' as the result. Note, the result is...
Read more >
How to unnest / extract nested JSON data in BigQuery - Holistics
With Holistics's modeling layer, you can let your end-user have access to data in nested JSON arrays by: Write a SQL model to...
Read more >
Convert SQL Server results into JSON - SQLShack
SQL Server to JSON Supported Data Types ... You will now notice that another child array (with its own objects) labelled cust appears...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found