Skip to content

how do you make "get_item" search query using string ? #380

Open
@pramadito

Description

@pramadito

i get confused while reading the documentation, there example code for get all items, there example code to get item with id one but i found no example search database using string.

endpoints

@router.get("/search/{search}", response_model=List[schemas.HouseItem])
def search_houseitem_open(
    db: Session = Depends(deps.get_db),
    q: Optional[str] = None,
    skip: int = 0,    
    limit: int = 100,
) -> Any:
    """
    search houseitems.
    """
    houseitems = crud.houseitem.get_multi_by_search(
            db=db, q = q , skip=skip, limit=limit
        )
    
    return houseitems

crud

def get_multi_by_search(
        self, db: Session, *,  q : Optional[str] = None , skip: int = 0, limit: int = 100
    ) -> List[ModelType]:
        return (
            db.query(self.model)
            .filter()  #what filter should i use
            .offset(skip)
            .limit(limit)
            .all()
        )

is this code correct? what filter should i use so it can match case SQL “LIKE” statement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions