
    gs7                       d dl mZ d dlmZ d dlmZmZmZmZm	Z	 d dl
mZmZ d dlmZ ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ dd	lmZ dd
l m!Z!m"Z"  ed      Z# G d dee#         Z$ G d dee#         Z% G d de%e#         Z& G d dee#   e$e#         Z' G d dee#   e%e#         Z( G d dee#   e$e#         Z) G d dee#         Z*y)    )annotations)JSONDecodeError)AnyGenericOptionalTypeVarUnion)HeadersQueryParams)ValidationError   )APIResponseBaseFilterRequestBuilderBaseRPCRequestBuilderBaseSelectRequestBuilderCountMethodSingleAPIResponse
pre_delete
pre_insert
pre_select
pre_update
pre_upsert)APIErrorgenerate_default_error_message)ReturnMethod)AsyncClientget_origin_and_cast_ReturnTc                  8    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZy)AsyncQueryRequestBuilderc                X    || _         || _        || _        || _        || _        || _        y Nsessionpathhttp_methodheadersparamsjsonselfr$   r%   r&   r'   r(   r)   s          U/var/www/openai/venv/lib/python3.12/site-packages/postgrest/_async/request_builder.py__init__z!AsyncQueryRequestBuilder.__init__   /     	&	    c                  K   | j                   j                  | j                  | j                  | j                  | j
                  | j                         d{   }	 |j                  r| j                  dk7  r|j                  }| j                  j                  d      dk(  r|S | j                  j                  d      r<d| j                  j                  d      v rd| j                  j                  d      vr|S t        t           j                  |      S t        |j	                               7 # t        $ r}t        |j	                               |d}~wt        $ r t        t!        |            w xY ww)zExecute the query.

        .. tip::
            This is the last method called, after the query is built.

        Returns:
            :class:`APIResponse`

        Raises:
            :class:`APIError` If the API raised an error.
        r)   r(   r'   NHEADAccepttext/csvzapplication/vnd.pgrst.planz+json)r$   requestr&   r%   r)   r(   r'   
is_successtextgetr   r   from_http_request_responser   r   r   r   )r+   rbodyes       r,   executez AsyncQueryRequestBuilder.execute.   s;     ,,&&II;;LL ' 
 
	>||##v-66D||''1Z?#||'' 6$,,:J:J8:TT"$,,*:*:8*DD#'K"8,GGJJqvvx(()
*  	,1668$!+ 	>9!<==	>s\   AE:D1E:AD3 $E:%AD3 ;E:<D3 E:D3 1E:3	E7<E!E77E:Nr$   r   r%   strr&   r?   r'   r
   r(   r   r)   dictreturnNone)rA   zAPIResponse[_ReturnT]__name__
__module____qualname__r-   r=    r/   r,   r    r       sP      	
    
 $>r/   r    c                  8    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZy)AsyncSingleRequestBuilderc                X    || _         || _        || _        || _        || _        || _        y r"   r#   r*   s          r,   r-   z"AsyncSingleRequestBuilder.__init__V   r.   r/   c                  K   | j                   j                  | j                  | j                  | j                  | j
                  | j                         d{   }	 d|j                  cxk  rdk  rn nt        t           j                  |      S t        |j	                               7 R# t        $ r}t        |j	                               |d}~wt        $ r t        t        |            w xY ww)zExecute the query.

        .. tip::
            This is the last method called, after the query is built.

        Returns:
            :class:`SingleAPIResponse`

        Raises:
            :class:`APIError` If the API raised an error.
        r1   N   i+  )r$   r5   r&   r%   r)   r(   r'   status_coder   r   r9   r   r   r   r   r+   r:   r<   s      r,   r=   z!AsyncSingleRequestBuilder.executef   s      ,,&&II;;LL ' 
 

	>q}}++(2MMaPPqvvx((
  	,1668$!+ 	>9!<==	>sB   AC4B+C43B- C4B- +C4-	C16C!C11C4Nr>   )rA   zSingleAPIResponse[_ReturnT]rC   rG   r/   r,   rI   rI   U   sP      	
    
 >r/   rI   c                      e Zd ZddZy)AsyncMaybeSingleRequestBuilderc                   K   d }	 t         t           j                  |        d {   }|st        ddddd      |S 7 # t        $ r)}|j                  rd|j                  v rY d }~y Y d }~Cd }~ww xY ww)NzThe result contains 0 rowszMissing response204z"Please check traceback of the codezPostgrest couldn't retrieve response, please check traceback of the code. Please create an issue in `supabase-community/postgrest-py` if needed.)messagecodehintdetails)rI   r   r=   r   rV   rN   s      r,   r=   z&AsyncMaybeSingleRequestBuilder.execute   s     	/9AA$GGA 1!@  r	   H 	yy9QYYF	s;   A5A  >A  A5A   	A2	A-#
A5-A22A5N)rA   z%Optional[SingleAPIResponse[_ReturnT]])rD   rE   rF   r=   rG   r/   r,   rP   rP      s    r/   rP   c                  0    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)AsyncFilterRequestBuilderc           	         t        t        t                 j                  | |||       t        t        t                 j                  | ||||||       y r"   )r   r   r   r-   r    r*   s          r,   r-   z"AsyncFilterRequestBuilder.__init__   P     	4X>?HH'7F	
 	4X>?HH'4gvt	
r/   Nr>   rD   rE   rF   r-   rG   r/   r,   rX   rX      sK    

 
 	

 
 
 
 

r/   rX   c                  0    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)AsyncRPCFilterRequestBuilderc           	         t        t        t                 j                  | |||       t        t        t                 j                  | ||||||       y r"   )r   r   r   r-   rI   r*   s          r,   r-   z%AsyncRPCFilterRequestBuilder.__init__   sP     	4X>?HH'7F	
 	5h?@II'4gvt	
r/   Nr>   r[   rG   r/   r,   r]   r]      sK    

 
 	

 
 
 
 

r/   r]   c                  b    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZd	dZi f	 	 	 	 	 	 	 d
dZddZy)AsyncSelectRequestBuilderc           	         t        t        t                 j                  | |||       t        t        t                 j                  | ||||||       y r"   )r   r   r   r-   r    r*   s          r,   r-   z"AsyncSelectRequestBuilder.__init__   rZ   r/   c                    d| j                   d<   t        t           | j                   | j                  | j                  | j
                  | j                  | j                        S )zSpecify that the query will only return a single row in response.

        .. caution::
            The API will raise an error if the query returned more than one row.
        !application/vnd.pgrst.object+jsonr3   r'   r&   r)   r(   r%   r$   )r'   rI   r   r&   r)   r(   r%   r$   r+   s    r,   singlez AsyncSelectRequestBuilder.single   sQ     "EX(2LL((;;LL
 	
r/   c                    d| j                   d<   t        t           | j                   | j                  | j                  | j
                  | j                  | j                        S )zRetrieves at most one row from the result. Result must be at most one row (e.g. using `eq` on a UNIQUE column), otherwise this will result in an error.rc   r3   rd   )r'   rP   r   r&   r)   r(   r%   r$   re   s    r,   maybe_singlez&AsyncSelectRequestBuilder.maybe_single   sN    !DX-h7LL((;;LL
 	
r/   c                   |j                  d      }d}|dk(  rd}n|dk(  rd}n|dk(  rd}|j                  d	      rd
|j                  d	       dnd}| j                  j                  || d| d|       | _        t        t           | j
                  | j                  | j                  | j                  | j                  | j                        S )Ntype plainplphraseph
web_searchwconfig()fts.rd   )
r8   r(   addr    r   r'   r&   r)   r%   r$   )r+   columnqueryoptionstype_	type_partconfig_parts          r,   text_searchz%AsyncSelectRequestBuilder.text_search   s     F#	GIhIl"I6=kk(6K'++h/02QSkkoof3{m1UG.TU'1LL((;;LL
 	
r/   c                    d| j                   d<   t        t           | j                  | j                  | j
                  | j                   | j                  | j                        S )zASpecify that the query must retrieve data as a single CSV string.r4   r3   r#   )r'   rI   r?   r$   r%   r&   r(   r)   re   s    r,   csvzAsyncSelectRequestBuilder.csv  sN    !+X(-LL((LL;;
 	
r/   Nr>   )rA   z#AsyncSingleRequestBuilder[_ReturnT])rA   z(AsyncMaybeSingleRequestBuilder[_ReturnT])rx   r?   ry   r?   rz   zdict[str, Any]rA   #AsyncFilterRequestBuilder[_ReturnT])rA   zAsyncSingleRequestBuilder[str])rD   rE   rF   r-   rf   rh   r~   r   rG   r/   r,   r`   r`      s    

 
 	

 
 
 
 

 
 

 BD

"%
0>
	,
.

r/   r`   c                     e Zd ZddZddd	 	 	 	 	 	 	 ddZdej                  ddd	 	 	 	 	 	 	 	 	 	 	 ddZdej                  dd	dd
	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdej                  d	 	 	 	 	 	 	 ddZ	dej                  d	 	 	 	 	 ddZ
y)AsyncRequestBuilderc                     || _         || _        y r"   )r$   r%   )r+   r$   r%   s      r,   r-   zAsyncRequestBuilder.__init__  s    	r/   Ncountheadc               z    t        |||d\  }}}}t        t           | j                  | j                  ||||      S )zRun a SELECT query.

        Args:
            *columns: The names of the columns to fetch.
            count: The method to use to get the count of rows returned.
        Returns:
            :class:`AsyncSelectRequestBuilder`
        r   )r   r`   r   r$   r%   )r+   r   r   columnsmethodr(   r'   r)   s           r,   selectzAsyncRequestBuilder.select  sB     )3G5t(T%(2LL$))VWfd
 	
r/   FTr   	returningupsertdefault_to_nullc                   t        |||||      \  }}}}t        t           | j                  | j                  ||||      S )a  Run an INSERT query.

        Args:
            json: The row to be inserted.
            count: The method to use to get the count of rows returned.
            returning: Either 'minimal' or 'representation'
            upsert: Whether the query should be an upsert.
            default_to_null: Make missing fields default to `null`.
                Otherwise, use the default value for the column.
                Only applies for bulk inserts.
        Returns:
            :class:`AsyncQueryRequestBuilder`
        r   )r   r    r   r$   r%   )	r+   r)   r   r   r   r   r   r(   r'   s	            r,   insertzAsyncRequestBuilder.insert,  sO    , )3+)
% (1LL$))VWfd
 	
r/   rk   r   r   ignore_duplicateson_conflictr   c                   t        ||||||      \  }}}	}t        t           | j                  | j                  ||	||      S )a   Run an upsert (INSERT ... ON CONFLICT DO UPDATE) query.

        Args:
            json: The row to be inserted.
            count: The method to use to get the count of rows returned.
            returning: Either 'minimal' or 'representation'
            ignore_duplicates: Whether duplicate rows should be ignored.
            on_conflict: Specified columns to be made to work with UNIQUE constraint.
            default_to_null: Make missing fields default to `null`. Otherwise, use the
                default value for the column. This only applies when inserting new rows,
                not when merging with existing rows under `ignoreDuplicates: false`.
                This also only applies when doing bulk upserts.
        Returns:
            :class:`AsyncQueryRequestBuilder`
        r   )r   r    r   r$   r%   )
r+   r)   r   r   r   r   r   r   r(   r'   s
             r,   r   zAsyncRequestBuilder.upsertM  sR    2 )3/#+)
% (1LL$))VWfd
 	
r/   r   r   c               ~    t        |||      \  }}}}t        t           | j                  | j                  ||||      S )a  Run an UPDATE query.

        Args:
            json: The updated fields.
            count: The method to use to get the count of rows returned.
            returning: Either 'minimal' or 'representation'
        Returns:
            :class:`AsyncFilterRequestBuilder`
        r   )r   rX   r   r$   r%   )r+   r)   r   r   r   r(   r'   s          r,   updatezAsyncRequestBuilder.updater  sI      )3)
%
 )2LL$))VWfd
 	
r/   c               |    t        ||      \  }}}}t        t           | j                  | j                  ||||      S )zRun a DELETE query.

        Args:
            count: The method to use to get the count of rows returned.
            returning: Either 'minimal' or 'representation'
        Returns:
            :class:`AsyncFilterRequestBuilder`
        r   )r   rX   r   r$   r%   )r+   r   r   r   r(   r'   r)   s          r,   deletezAsyncRequestBuilder.delete  sF     )3)
% )2LL$))VWfd
 	
r/   )r$   r   r%   r?   rA   rB   )r   r?   r   Optional[CountMethod]r   zOptional[bool]rA   z#AsyncSelectRequestBuilder[_ReturnT])r)   Union[dict, list]r   r   r   r   r   boolr   r   rA   "AsyncQueryRequestBuilder[_ReturnT])r)   r   r   r   r   r   r   r   r   r?   r   r   rA   r   )r)   r@   r   r   r   r   rA   r   )r   r   r   r   rA   r   )rD   rE   rF   r-   r   r   representationr   r   r   r   rG   r/   r,   r   r     sY    (,#	

 %
 	

 
-
. (,"."="= $

 %	

  
 
 
 
,
J (,"."="="' $#
#
 %	#

  #
  #
 #
 #
 
,#
R (,"."="=

 %	

  
 
-
8 (,"."="=	
 %
  	

 
-
r/   r   N)+
__future__r   r)   r   typingr   r   r   r   r	   httpxr
   r   pydanticr   base_request_builderr   r   r   r   r   r   r   r   r   r   r   
exceptionsr   r   typesr   utilsr   r   r   r    rI   rP   rX   r]   r`   r   rG   r/   r,   <module>r      s    "   9 9 & $    B   4:5>wx0 5>p.> 1 .>b%>x%H *
 8 BD\]eDf 
&
(#%>x%H
*N
 8 BD\]eDf N
bK
'(+ K
r/   