U
    Wi                     @  s   d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ eeef ZG dd deZdS )    )annotations)AnyDictOptionalUnioncast)
deprecated)HeadersQueryParamsTimeout   )BasePostgrestClient) DEFAULT_POSTGREST_CLIENT_HEADERS DEFAULT_POSTGREST_CLIENT_TIMEOUT)CountMethod
SyncClient)__version__   )SyncRequestBuilderSyncRPCFilterRequestBuilderc                   @  s   e Zd ZdZdeedddddddd	d
ddZd,ddddddddZd dddZd	dddZ	d	dddZ
dddddZdddddZedded dd!dd"d#Zd-dd&d'ddd(d)d*d+Zd$S ).SyncPostgrestClientzPostgREST client.publicTschemaheaderstimeoutverifystrzDict[str, str]zUnion[int, float, Timeout]boolNone)base_urlr   r   r   r   returnc                C  s(   t j| |||||d tt| j| _d S )Nr   )r   __init__r   r   session)selfr!   r   r   r   r    r&   \/home/afrizal/public_html/fastapi/venv/lib/python3.8/site-packages/postgrest/_sync/client.pyr#      s    	zSyncPostgrestClient.__init__r   )r!   r   r   r   r"   c                 C  s   t ||||dddS )NT)r!   r   r   r   Zfollow_redirectsZhttp2r   )r%   r!   r   r   r   r&   r&   r'   create_session+   s    z"SyncPostgrestClient.create_session)r"   c                 C  s   | S Nr&   r%   r&   r&   r'   	__enter__;   s    zSyncPostgrestClient.__enter__c                 C  s   |    d S r)   )aclose)r%   exc_typeexctbr&   r&   r'   __exit__>   s    zSyncPostgrestClient.__exit__c                 C  s   | j   dS )z&Close the underlying HTTP connections.N)r$   r,   r*   r&   r&   r'   r,   A   s    zSyncPostgrestClient.aclosezSyncRequestBuilder[_TableT])tabler"   c                 C  s   t t | jd| S )zPerform a table operation.

        Args:
            table: The name of the table
        Returns:
            :class:`AsyncRequestBuilder`
        /)r   _TableTr$   r%   r1   r&   r&   r'   from_E   s    zSyncPostgrestClient.from_c                 C  s
   |  |S zAlias to :meth:`from_`.r5   r4   r&   r&   r'   r1   O   s    zSyncPostgrestClient.tablez0.2.0z1.0.0zUse self.from_() insteadr   c                 C  s
   |  |S r6   r7   r4   r&   r&   r'   
from_tableS   s    zSyncPostgrestClient.from_tableNFdictzOptional[CountMethod]z SyncRPCFilterRequestBuilder[Any])funcparamscountheadgetr"   c                 C  sR   |rdn
|rdnd}|r*t dd| int  }tt | jd| ||t |dS )a  Perform a stored procedure call.

        Args:
            func: The name of the remote procedure to run.
            params: The parameters to be passed to the remote procedure.
            count: The method to use to get the count of rows returned.
            head: When set to `true`, `data` will not be returned. Useful if you only need the count.
            get: When set to `true`, the function will be called with read-only access mode.
        Returns:
            :class:`AsyncRPCFilterRequestBuilder`
        Example:
            .. code-block:: python

                await client.rpc("foobar", {"arg": "value"}).execute()

        .. versionchanged:: 0.10.9
            This method now returns a :class:`AsyncRPCFilterRequestBuilder`.
        .. versionchanged:: 0.10.2
            This method now returns a :class:`AsyncFilterRequestBuilder` which allows you to
            filter on the RPC's resultset.
        HEADGETPOSTZPreferzcount=z/rpc/)json)r	   r   r   r$   r
   )r%   r:   r;   r<   r=   r>   methodr   r&   r&   r'   rpcX   s         zSyncPostgrestClient.rpc)T)NFF)__name__
__module____qualname____doc__r   r   r#   r(   r+   r0   r,   r5   r1   r   r   r8   rD   r&   r&   r&   r'   r      s&    
   r   N)
__future__r   typingr   r   r   r   r   deprecationr   Zhttpxr	   r
   r   Zbase_clientr   	constantsr   r   typesr   utilsr   versionr   Zrequest_builderr   r   r   r3   r   r&   r&   r&   r'   <module>   s   