#Wich reference for filter like : repo.list_and_count(YourTable.name.is_(None))

1 messages · Page 1 of 1 (latest)

karmic sable
#

Hello guys,

Do you know where I can fin filters used by litestar on repo/services/... using methods like is_, ...

I understand SQLA select with where clauses methods ex: select(Table).join(...).where(), but don't find how to convert them into filters.

Actually i override statement using where conditions instead of using filters cause I can't find a doc that list all methods.

Plus, when should I use statement instead of filter ?

Have a sunny day

forest muralBOT
#
Notes for Wich reference for filter like : repo.list_and_count(YourTable.name.is_(None))
At your assistance

@karmic sable

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

compact hinge
#

The "filters" are provided by SQLAlchemy, and are what you get when doing something like Table.column == <some value>. You can just pass these directly into the repo methods: repo.list_and_count(Table.column == "foo")

karmic sable
karmic sable
#

for exemple in this case (fullstack) :

            filters.append(
                TeamModel.id.in_(select(TeamMemberModel.team_id).where(TeamMemberModel.user_id == current_user.id)),  # type: ignore[arg-type]
            )

If I understand correctly, I should call wich fields should be filtred as column.field.condition ?

#

so if I want to convert :

        results, total = await profile_service.list_and_count(
            *filters,
            statement=select(Profile)
            .join(Profile.owners)
            .where(User.id == current_user.id),
        )
#
            Profile.id.in_(
                select(Profile.id)
                .join(Profile.owners)
                .where(User.id == current_user.id)
            )

owners reference table of users, it is right approach ?
Then, how can I use them on get ? to restrict the get to certain data ?

turbid gyro
inner tartanBOT
#

src/app/domain/teams/controllers/teams.py line 48

async def list_teams(
turbid gyro
#

I'm prettty sure this is what you are looking for

karmic sable
turbid gyro
turbid gyro
#

there are few things other than options and execution_options that can get get used in some statements

#

those are good candidates to for a statement override