fastapi / sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.
https://sqlmodel.tiangolo.com/
MIT License
14.71k stars 671 forks source link

Add support for deferred column loading #97

Open hitman-gdg opened 3 years ago

hitman-gdg commented 3 years ago

First Check

Commit to Help

Example Code

from sqlmodel import deferred

class User(sqlmodel, table=True):
    id: Optional[int] = Field(primary_key=True, default=None)
    name: str
    data: Optional[bytes] = Field(deferred=True)

Description

The ability to be able to included deferred sql columns

Wanted Solution

I would like to be able to work with sqlalchemy deferred columns, so that certain columns are not loaded by default as part of a model

Wanted Code

from sqlmodel import deferred

Alternatives

No response

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.9.6

Additional Context

No response

eddcorts commented 2 years ago

Having same issue, did you find any alternative with base SQLAlchemy or something?

FilipeMarch commented 1 year ago

Did you find a solution?

lucas-labs commented 1 year ago

I think that we can use the new sa_type now, in order to achieve this behaviour.

ngi commented 8 months ago

any news how to use sa_type for deferred loading?

MarkusDressel commented 2 weeks ago

@tiangolo can you provide some information if / how it possible to leverage SQLalchemy's deferred loading mechanism in SQLModel ?

I also could not find a way to make deferred loading on column level (not on query level) work. sa_column setting is not recognized by SQLModel and still loads the deferred column

blob: bytes | None = Field(default=None, sa_column=deferred(Column(LargeBinary)))