Skip to content
Discussion options

You must be logged in to vote

This question is pretty old, but seems to (still) be the first result when looking on how to handle binary data or files with SQLModel, so I'll leave here my solution:

from sqlmodel import SQLModel, Column, Field, LargeBinary

class Document(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    name: str
    filename: str
    data: bytes = Field(sa_column=Column(LargeBinary))

the sa_column attribute lets you define columns with SQLAlchemy entities (here, Column and LargeBinary are the original SQLALchemy classes re-imported by SQLModel).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants