From 17e7103df0734d0e40fba6185bc8d6c8db93e420 Mon Sep 17 00:00:00 2001 From: Kay Cha Date: Fri, 26 Apr 2024 18:57:54 +0900 Subject: [PATCH] Added docs about SQLModel --- docs/usage.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/usage.md b/docs/usage.md index 4340bae..f6ca980 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -165,3 +165,28 @@ ${imports if imports else ""} # THE REST OF SCRIPT ``` + +### SQLModel + +If you're using sqlmodel, you'll need to annotate the type with StorageFile and enable the model's arbitrary_types_allowed configuration. + +```python +from sqlmodel import SQLModel, Column, Field +from sqlmodel.main import SQLModelConfig +from fastapi_storages import FileSystemStorage +from fastapi_storages.base import StorageFile +from fastapi_storages.integrations.sqlalchemy import FileType + + +class Upload(SQLModel, table=True): + id: int | None = Field(default=None, primary_key=True) + file: StorageFile = Field( + sa_column=Column( + FileType(storage=FileSystemStorage(path="/tmp")), + ), + ) + + model_config = SQLModelConfig( + arbitrary_types_allowed=True, + ) +```