igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
530 stars 32 forks source link

IN and NOT IN filter #60

Closed FCMHUB closed 1 month ago

FCMHUB commented 2 months ago

Thanks for this awesome package.

Is your feature request related to a problem? Please describe. It should be possible to filter records using the IN and NOT IN operators in the get and get_multi functions.

Describe the solution you'd like

db_asset = await crud_users.get(
        db=db, 
        schema_to_select=User, 
        return_as_model=True, 
        id=id, 
        filter=User.id.not_in(ids),
        is_deleted=False,
)

It would be great to utilize logical operators such as and_ and or_.

Describe alternatives you've considered Currently, one must rely on SQLAlchemy methods to execute such filtering operations.

smt = select(User).where(User.reference_id == ref_id).filter(User.id.not_in(ids))
JakNowy commented 2 months ago

Please see my latest PR

and_ is handled by default by chaining filters. I also tried implementing or_ but I found it too complex with the current convention. not_in_ could be an additional option in my PR actually.

igorbenav commented 1 month ago

closed by #57