Skip to content

Commit

Permalink
Added docs about SQLModel (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannal authored Apr 26, 2024
1 parent 0ce6ffa commit 4a3aa6b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
```

0 comments on commit 4a3aa6b

Please sign in to comment.