o
    g                     @  sf   d dl mZ d dlZd dlmZ d dlmZ	 d dl
mZ ddlmZ ddlmZ G dd de	jZdS )	    )annotationsN)abort   )
PaginationQueryPaginationc                   @  sL   e Zd ZdZdddd	Zddd
dZddddZdddddddddZdS )Querya  SQLAlchemy :class:`~sqlalchemy.orm.query.Query` subclass with some extra methods
    useful for querying in a web application.

    This is the default query class for :attr:`.Model.query`.

    .. versionchanged:: 3.0
        Renamed to ``Query`` from ``BaseQuery``.
    Nidentt.Anydescription
str | Nonereturnc                 C  s"   |  |}|du rtd|d |S )zLike :meth:`~sqlalchemy.orm.Query.get` but aborts with a ``404 Not Found``
        error instead of returning ``None``.

        :param ident: The primary key to query.
        :param description: A custom message to show on the error page.
        N  r   )getr   )selfr	   r   rv r   X/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/flask_sqlalchemy/query.py
get_or_404   s   
zQuery.get_or_404c                 C  s    |   }|du rtd|d |S )zLike :meth:`~sqlalchemy.orm.Query.first` but aborts with a ``404 Not Found``
        error instead of returning ``None``.

        :param description: A custom message to show on the error page.
        Nr   r   )firstr   )r   r   r   r   r   r   first_or_404%   s   zQuery.first_or_404c              	   C  s4   z|   W S  tjtjfy   td|d Y dS w )a  Like :meth:`~sqlalchemy.orm.Query.one` but aborts with a ``404 Not Found``
        error instead of raising ``NoResultFound`` or ``MultipleResultsFound``.

        :param description: A custom message to show on the error page.

        .. versionadded:: 3.0
        r   r   N)onesa_excNoResultFoundMultipleResultsFoundr   )r   r   r   r   r   
one_or_4042   s
   
zQuery.one_or_404T)pageper_pagemax_per_page	error_outcountr   
int | Noner   r   r    boolr!   r   c                C  s   t | |||||dS )a>  Apply an offset and limit to the query based on the current page and number
        of items per page, returning a :class:`.Pagination` object.

        :param page: The current page, used to calculate the offset. Defaults to the
            ``page`` query arg during a request, or 1 otherwise.
        :param per_page: The maximum number of items on a page, used to calculate the
            offset and limit. Defaults to the ``per_page`` query arg during a request,
            or 20 otherwise.
        :param max_per_page: The maximum allowed value for ``per_page``, to limit a
            user-provided value. Use ``None`` for no limit. Defaults to 100.
        :param error_out: Abort with a ``404 Not Found`` error if no items are returned
            and ``page`` is not 1, or if ``page`` or ``per_page`` is less than 1, or if
            either are not ints.
        :param count: Calculate the total number of values by issuing an extra count
            query. For very complex queries this may be inaccurate or slow, so it can be
            disabled and set manually if necessary.

        .. versionchanged:: 3.0
            All parameters are keyword-only.

        .. versionchanged:: 3.0
            The ``count`` query is more efficient.

        .. versionchanged:: 3.0
            ``max_per_page`` defaults to 100.
        )queryr   r   r   r    r!   r   )r   r   r   r   r    r!   r   r   r   paginate?   s   #zQuery.paginate)N)r	   r
   r   r   r   r
   )r   r   r   r
   )r   r"   r   r"   r   r"   r    r#   r!   r#   r   r   )__name__
__module____qualname____doc__r   r   r   r%   r   r   r   r   r      s    	r   )
__future__r   typingtsqlalchemy.excexcr   sqlalchemy.ormormsa_ormflaskr   
paginationr   r   r   r   r   r   r   <module>   s    