
    ؄_n                         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	 ddl
mZ ddlmZ dd	lmZ d
Z G d de	          Z eedd          Z G d de          Z G d de          Z G d de          ZdS )   )ext   )util)schema)_generative)Insert)ClauseElement)alias)public_factory)r   insertc                   n    e Zd ZdZej        d             Ze	 	 	 	 	 dd            Ze	 dd            Z	dS )r   a  PostgreSQL-specific implementation of INSERT.

    Adds methods for PG-specific syntaxes such as ON CONFLICT.

    The :class:`_postgresql.Insert` object is created using the
    :func:`sqlalchemy.dialects.postgresql.insert` function.

    .. versionadded:: 1.1

    c                 8    t          | j        d          j        S )a  Provide the ``excluded`` namespace for an ON CONFLICT statement

        PG's ON CONFLICT clause allows reference to the row that would
        be inserted, known as ``excluded``.  This attribute provides
        all columns in this row to be referenceable.

        .. seealso::

            :ref:`postgresql_insert_on_conflict` - example of how
            to use :attr:`_expression.Insert.excluded`

        excluded)name)r
   tablecolumns)selfs    g/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/dml.pyr   zInsert.excluded!   s     TZj11199    Nc                 6    t          |||||          | _        | S )a  
        Specifies a DO UPDATE SET action for ON CONFLICT clause.

        Either the ``constraint`` or ``index_elements`` argument is
        required, but only one of these can be specified.

        :param constraint:
         The name of a unique or exclusion constraint on the table,
         or the constraint object itself if it has a .name attribute.

        :param index_elements:
         A sequence consisting of string column names, :class:`_schema.Column`
         objects, or other column expression objects that will be used
         to infer a target index.

        :param index_where:
         Additional WHERE criterion that can be used to infer a
         conditional target index.

        :param set\_:
         Required argument. A dictionary or other mapping object
         with column names as keys and expressions or literals as values,
         specifying the ``SET`` actions to take.
         If the target :class:`_schema.Column` specifies a ".
         key" attribute distinct
         from the column name, that key should be used.

         .. warning:: This dictionary does **not** take into account
            Python-specified default UPDATE values or generation functions,
            e.g. those specified using :paramref:`_schema.Column.onupdate`.
            These values will not be exercised for an ON CONFLICT style of
            UPDATE, unless they are manually specified in the
            :paramref:`.Insert.on_conflict_do_update.set_` dictionary.

        :param where:
         Optional argument. If present, can be a literal SQL
         string or an acceptable expression for a ``WHERE`` clause
         that restricts the rows affected by ``DO UPDATE SET``. Rows
         not meeting the ``WHERE`` condition will not be updated
         (effectively a ``DO NOTHING`` for those rows).

         .. versionadded:: 1.1


        .. seealso::

            :ref:`postgresql_insert_on_conflict`

        )OnConflictDoUpdate_post_values_clause)r   
constraintindex_elementsindex_whereset_wheres         r   on_conflict_do_updatezInsert.on_conflict_do_update1   s)    t $6T5$
 $
  r   c                 2    t          |||          | _        | S )a)  
        Specifies a DO NOTHING action for ON CONFLICT clause.

        The ``constraint`` and ``index_elements`` arguments
        are optional, but only one of these can be specified.

        :param constraint:
         The name of a unique or exclusion constraint on the table,
         or the constraint object itself if it has a .name attribute.

        :param index_elements:
         A sequence consisting of string column names, :class:`_schema.Column`
         objects, or other column expression objects that will be used
         to infer a target index.

        :param index_where:
         Additional WHERE criterion that can be used to infer a
         conditional target index.

         .. versionadded:: 1.1

        .. seealso::

            :ref:`postgresql_insert_on_conflict`

        )OnConflictDoNothingr   r   r   r   r   s       r   on_conflict_do_nothingzInsert.on_conflict_do_nothingp   s$    < $7$
 $
  r   NNNNNNNN)
__name__
__module____qualname____doc__r   memoized_propertyr   r   r   r"    r   r   r   r      s        	 	 
: : :  < < < [<| @D      [     r   r   z.dialects.postgresql.insertz.dialects.postgresql.Insertc                       e Zd ZddZdS )OnConflictClauseNc                    |]t          |t          j                  sCt          |t          j        t          j        t          j        f          rt          |d          p|}||t          d          t          |t          j                  r|| _
        d | _        d | _        nt          |t          j                  r(|j        }|j        d                             d          }nPt          |t          j                  r|j        }|j        }n'|j        }|j        d                             d          }|d | _
        || _        || _        d S |d x| _
        x| _        | _        d S d S )Nr   z8'constraint' and 'index_elements' are mutually exclusive
postgresqlr   )
isinstancer   string_typesr   Index
Constraintr   ExcludeConstraintgetattr
ValueErrorconstraint_targetinferred_target_elementsinferred_target_whereclauseexpressionsdialect_optionsgetr   r   r!   s       r   __init__zOnConflictClause.__init__   s   !j$*;<< Gv0#2GHB B G %Z88FJ
!) N   *d&788 )3&04-3700J55 !+!7(8FJJ  J(=>> !+!3(.!+!3(8FJJ  %%)D",:D)/:D,,, 488D" 8-000  r   r$   )r%   r&   r'   r<   r*   r   r   r,   r,      s(        (8 (8 (8 (8 (8 (8r   r,   c                       e Zd ZdZdS )r    r"   N)r%   r&   r'   __visit_name__r*   r   r   r    r       s        -NNNr   r    c                   .     e Zd ZdZ	 	 	 	 	 d fd	Z xZS )r   r   Nc                 8   t          t          |                               |||           | j        | j        t          d          t          |t                    r|st          d          d |                                D             | _	        || _
        d S )N)r   r   r   zVEither constraint or index_elements, but not both, must be specified unless DO NOTHINGz,set parameter must be a non-empty dictionaryc                     g | ]	\  }}||f
S r*   r*   ).0keyvalues      r   
<listcomp>z/OnConflictDoUpdate.__init__.<locals>.<listcomp>   s-     %
 %
 %
'S%S%L%
 %
 %
r   )superr   r<   r7   r6   r5   r/   dictitemsupdate_values_to_setupdate_whereclause)r   r   r   r   r   r   	__class__s         r   r<   zOnConflictDoUpdate.__init__   s     	 $''00!)# 	1 	
 	
 	
 )1&.D  
 $%% 	MT 	MKLLL%
 %
+/::<<%
 %
 %
! #(r   r#   )r%   r&   r'   r>   r<   __classcell__)rK   s   @r   r   r      sS        ,N ( ( ( ( ( ( ( ( ( (r   r   N) r   r   sqlr   sql.baser   sql.dmlr   StandardInsertsql.elementsr	   sql.expressionr
   util.langhelpersr   __all__r   r,   r    r   r*   r   r   <module>rV      sx                     # # # # # # / / / / / / ) ) ) ) ) ) # # # # # # . . . . . . | | | | |^ | | |~ 

)+H
 

)8 )8 )8 )8 )8} )8 )8 )8X. . . . .* . . .( ( ( ( () ( ( ( ( (r   