First Check
Commit to Help
Example Code
from typing import List
from sqlmodel import Field, Session, SQLModel, create_engine
class Block(SQLModel, table=True):
id: int = Field(..., primary_key=True)
values: List[str]
engine = create_engine("sqlite:///test_database.db", echo=True)
SQLModel.metadata.create_all(engine)
b = Block(id=0, values=['test', 'test2'])
with Session(engine) as session:
session.add(b)
session.commit()
Description
I'm trying to store a list or similar types directly to the database.
Currently this does not seem to be the case. The above example code gives me the following error:
InterfaceError: (sqlite3.InterfaceError) Error binding parameter 1 - probably unsupported type.
[SQL: INSERT INTO block (id, "values") VALUES (?, ?)]
[parameters: (0, ['test', 'test2'])]
(Background on this error at: https://sqlalche.me/e/14/rvf5)
Wanted Solution
I would like to directly use the List type (or similar types like Dicts) to store data to a database column. I would expect SQLModel to serialize them.
Wanted Code
Alternatives
From another thread I tried to use this:
values: List[str] = Field(sa_column=Column(ARRAY(String)))
But this results in another error.
Operating System
Linux, Windows
Operating System Details
I'm working on the WSL.
SQLModel Version
0.0.4
Python Version
3.7.12
Additional Context
First Check
Commit to Help
Example Code
Description
I'm trying to store a list or similar types directly to the database.
Currently this does not seem to be the case. The above example code gives me the following error:
Wanted Solution
I would like to directly use the List type (or similar types like Dicts) to store data to a database column. I would expect SQLModel to serialize them.
Wanted Code
Alternatives
From another thread I tried to use this:
values: List[str] = Field(sa_column=Column(ARRAY(String)))
But this results in another error.
Operating System
Linux, Windows
Operating System Details
I'm working on the WSL.
SQLModel Version
0.0.4
Python Version
3.7.12
Additional Context