Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docs about SQLModel #48

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
```
Loading