Skip to content

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

Closed

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?

Activity

  1. johnsonjsyuen commented on Jul 10, 2021

    @johnsonjsyuen
  2. locked and limited conversation to collaborators on Sep 1, 2025
  3. converted this issue into a discussion #1816 on Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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