async def list_datasets(db: AsyncSession, user: Optional[User] = None, **filters) -> Sequence[Dataset]:
    """
    List stored datasets. If `user` is provided, only datasets available to the user will be returned.
    Additionally, filters based on `Dataset` class attributes can be applied

    """
    query = select(Dataset).filter_by(**filters).order_by(Dataset.inserted_at.asc())

    if user and not user.is_owner:
        query = query.join(
            WorkspaceUser,
            and_(
                WorkspaceUser.workspace_id == Dataset.workspace_id,
                WorkspaceUser.user_id == user.id,
            ),
        )

    result = await db.scalars(query)

    return result.all()

    List stored datasets. If `user` is provided, only datasets available to the user will be returned.
    Additionally, filters based on `Dataset` class attributes can be applied

    
argilla-server/src/argilla_server/contexts/datasets.py