async def METHOD_NAME(
    conn: SAConnection,
    *,
    user_id: UserID,
    project_ids: list[ProjectID],
    file_id_prefix: str | None,
    partial_file_id: str | None,
    only_files: bool,
) -> list[FileMetaDataAtDB]:
    stmt = sa.select(file_meta_data).where(
        (
            (file_meta_data.c.user_id == f"{user_id}")
            | file_meta_data.c.project_id.in_(f"{pid}" for pid in project_ids)
        )
        & (
            file_meta_data.c.file_id.startswith(file_id_prefix)
            if file_id_prefix
            else True
        )
        & (
            file_meta_data.c.file_id.ilike(f"%{partial_file_id}%")
            if partial_file_id
            else True
        )
        & (
            file_meta_data.c.is_directory.is_(False)  # noqa FBT003
            if only_files
            else True
        )
    )
    return [FileMetaDataAtDB.from_orm(row) async for row in await conn.execute(stmt)]