
    P}bgf                     |    d dl mZ d dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ dgZ G d de
          Zd	S )
    )NotSupportedError)	StatementTable)
DeferrableFQ)BaseConstraint)Col)QueryExclusionConstraintc                   n     e Zd ZdZdddddd fd
Zd Zd Zd Zd	 Zd
 Z	d Z
 fdZ fdZd Z xZS )r   zdCONSTRAINT %(name)s EXCLUDE USING %(index_type)s (%(expressions)s)%(include)s%(where)s%(deferrable)sN )
index_type	condition
deferrableinclude	opclassesc                   |r%|                                 dvrt          d          |st          d          t          d |D                       st          d          t          |t	          d           t
          f          st          d          |r|rt          d          t          |t	          d           t          f          st          d          t          |t	          d           t          t          f          st          d	          |r)|r'|                                 d
k    rt          d          t          |t          t          f          st          d          |r/t          |          t          |          k    rt          d          || _
        |pd| _        || _        || _        |rt          |          nd| _        || _        t!                                          |           d S )N>   gistspgistz;Exclusion constraints only support GiST or SP-GiST indexes.zFAt least one expression is required to define an exclusion constraint.c              3   t   K   | ]3}t          |t          t          f          ot          |          d k    V  4dS )   N)
isinstancelisttuplelen).0exprs     v/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/django/contrib/postgres/constraints.py	<genexpr>z/ExclusionConstraint.__init__.<locals>.<genexpr>   sS       
 
 tdE]++>D		Q
 
 
 
 
 
    z+The expressions must be a list of 2-tuples.z3ExclusionConstraint.condition must be a Q instance.z7ExclusionConstraint with conditions cannot be deferred.z=ExclusionConstraint.deferrable must be a Deferrable instance.z4ExclusionConstraint.include must be a list or tuple.r   z9Covering exclusion constraints only support GiST indexes.z6ExclusionConstraint.opclasses must be a list or tuple.zhExclusionConstraint.expressions and ExclusionConstraint.opclasses must have the same number of elements.GISTr   )name)lower
ValueErrorallr   typer   r   r   r   r   expressionsr   r   r   r   r   super__init__)	selfr#   r(   r   r   r   r   r   	__class__s	           r   r*   zExclusionConstraint.__init__   sa     	***,,4FFFM    	    
 
#
 
 
 
 
 	L JKKK)d4jj!_55 	E    	 	I   *tDzz:&>?? 	O   'DJJe#<== 	F    	z 	j&6&6&8&8F&B&BK   )dE]33 	H    	[))S^^;;  
 '$."$)08uW~~~b"d#####r!   c                    g }t          | j                  D ]\  }\  }}t          |t                    rt	          |          }|                    |          }|                    |          \  }}	t          |t                    sd| d}	 | j        |         }
|
r|d|
}n# t          $ r Y nw xY w|t          fd|	D                       z  }|                    |d|           |S )N)query() c              3   B   K   | ]}                     |          V  d S Nquote_valuer   pschema_editors     r   r    z:ExclusionConstraint._get_expression_sql.<locals>.<genexpr>U   s1      KKqm77::KKKKKKr!   z WITH )	enumerater(   r   strr   resolve_expressioncompiler
   r   
IndexErrorr   append)r+   compilerr8   r.   r(   idx
expressionoperatorsqlparamsopclasss     `        r   _get_expression_sqlz'ExclusionConstraint._get_expression_sqlF   s.   +4T5E+F+F 	? 	?'C'*h*c** +z]]
#66U6CCJ"**:66KCj#.. ! #jjj.- 3%(SS''2C   KKKKFKKKKKKCsssHH=>>>>s   B%%
B21B2c                     | j         d S |                    | j                   }|                    |j                  \  }}|t	          fd|D                       z  S )Nc              3   B   K   | ]}                     |          V  d S r3   r4   r6   s     r   r    z9ExclusionConstraint._get_condition_sql.<locals>.<genexpr>^   s1      HHA=44Q77HHHHHHr!   )r   build_whereas_sql
connectionr   )r+   r?   r8   r.   whererC   rD   s     `    r   _get_condition_sqlz&ExclusionConstraint._get_condition_sqlY   sg    >!4!!$.11ll8]-EFFVUHHHHHHHHHHHr!   c           	         t          d          }|                    |j                  }|                     |||          }|                     |||          }fd| j        D             }| j        |                    | j                  | j	        d
                    |          |                    |          |rd|z  nd|                    | j                  dz  S )	NF)
alias_cols)rK   c                 N    g | ]!}j                             |          j        "S r   )_meta	get_fieldcolumn)r   
field_namemodels     r   
<listcomp>z6ExclusionConstraint.constraint_sql.<locals>.<listcomp>e   s,    [[[
5;((44;[[[r!   z, z WHERE (%s) )r#   r   r(   r   rL   r   )r   get_compilerrK   rF   rM   r   template
quote_namer#   r   join_index_include_sql_deferrable_constraint_sqlr   )r+   rU   r8   r.   r?   r(   r   r   s    `      r   constraint_sqlz"ExclusionConstraint.constraint_sql`   s    e...%%1I%JJ..xNN++HmUKK	[[[[dl[[[}!,,TY77/99[11$77wGG2;C]Y..'BB4?SS 
  
 
 	
r!   c                     |                      |           t          dt          |j        j        |j                  |                     ||                    S )Nz(ALTER TABLE %(table)s ADD %(constraint)s)table
constraint)check_supportedr   r   rQ   db_tablerZ   r^   r+   rU   r8   s      r   
create_sqlzExclusionConstraint.create_sqlo   sX    ]+++6,m.FGG**5-@@
 
 
 	
r!   c                 j    |                     |j        ||                    | j                            S r3   )_delete_constraint_sqlsql_delete_checkrZ   r#   rd   s      r   
remove_sqlzExclusionConstraint.remove_sqlw   s6    33*$$TY//
 
 	
r!   c                 X    | j         r |j        j        j        st	          d          d S d S )Nz7Covering exclusion constraints requires PostgreSQL 12+.)r   rK   featuressupports_covering_gist_indexesr   )r+   r8   s     r   rb   z#ExclusionConstraint.check_supported~   sE    < 	 8 A ` 	#I  	 	 	 	r!   c                 @   t                                                      \  }}}| j        |d<   | j        
| j        |d<   | j                                        dk    r
| j        |d<   | j        r
| j        |d<   | j        r
| j        |d<   | j        r
| j        |d<   |||fS )Nr(   r   r   r   r   r   r   )	r)   deconstructr(   r   r   r$   r   r   r   )r+   pathargskwargsr,   s       r   rn   zExclusionConstraint.deconstruct   s    "WW0022dF $ 0}>%"&.F;?  ""f,,#'?F< ? 	3#'?F< < 	- $F9> 	1"&.F;T6!!r!   c                 P   t          || j                  rp| j        |j        k    o_| j        |j        k    oO| j        |j        k    o?| j        |j        k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S t                      
                    |          S r3   )r   r,   r#   r   r(   r   r   r   r   r)   __eq__)r+   otherr,   s     r   rs   zExclusionConstraint.__eq__   s    eT^,, 			UZ' 25#332 E$552 %/12 5#33	2
 -2 %/1 ww~~e$$$r!   c                 l   d| j         j        dt          | j                  dt          | j                  dt          | j                  | j        dn	d| j        z  | j        dn	d| j        z  | j        sdndt          | j                  z  | j	        sdnd	t          | j	                  z  d
S )N<z: index_type=z expressions=z name=rW   z condition=%sz deferrable=%rz include=%sz opclasses=%s>)
r,   __qualname__reprr   r(   r#   r   r   r   r   )r+   s    r   __repr__zExclusionConstraint.__repr__   s     N'''!!!!!""""OOO.(BBo.NN/)BB/?$//QQlJBBT\8J8J(JJnPBB/D<P<P*PPP	
 		
r!   )__name__
__module__rx   rY   r*   rF   rM   r^   re   ri   rb   rn   rs   rz   __classcell__)r,   s   @r   r   r      s        uH 04t6$ 6$ 6$ 6$ 6$ 6$ 6$p  &I I I
 
 

 
 

 
 
  " " " " "% % % % %

 

 

 

 

 

 

r!   N)	django.dbr   !django.db.backends.ddl_referencesr   r   django.db.modelsr   r   r   django.db.models.constraintsr	   django.db.models.expressionsr
   django.db.models.sqlr   __all__r   r   r!   r   <module>r      s    ' ' ' ' ' ' > > > > > > > > - - - - - - - - - - 7 7 7 7 7 7 , , , , , , & & & & & & 
!_
 _
 _
 _
 _
. _
 _
 _
 _
 _
r!   