
    g,                    J   d dl mZ d dlZd dlZd dlZd dlmZ	 ddl
mZ ej                  rddlmZ  G d d      Z G d d	      Z G d
 de      Z G d d      Z G d de      Z G d d      ZddZddZ G d deee	j0                        Z G d dee	j0                        Zy)    )annotationsN   )Query)
SQLAlchemyc                      e Zd ZdZddZy)_QueryPropertyzRA class property that creates a query object for a model.

    :meta private:
    c                X    |j                  ||j                  j                               S )N)session)query_class__fsa__r
   )selfobjclss      V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/flask_sqlalchemy/model.py__get__z_QueryProperty.__get__   s*    ,,.  
 	
    N)r   zModel | Noner   ztype[Model]returnr   )__name__
__module____qualname____doc__r    r   r   r   r      s    

r   r   c                  P    e Zd ZU dZded<   	 eZded<   	  e       Zded<   	 d
dZ	y	)Modela  The base class of the :attr:`.SQLAlchemy.Model` declarative model class.

    To define models, subclass :attr:`db.Model <.SQLAlchemy.Model>`, not this. To
    customize ``db.Model``, subclass this and pass it as ``model_class`` to
    :class:`.SQLAlchemy`. To customize ``db.Model`` at the metaclass level, pass an
    already created declarative model class as ``model_class``.
    zt.ClassVar[SQLAlchemy]r   zt.ClassVar[type[Query]]r   zt.ClassVar[Query]queryc                .   t        j                  |       }|J |j                  rdt        |        d}nE|j                  rdt        |        d}n)dj                  t        t        |j                              }dt        |       j                   d| dS )Nz(transient )z	(pending z, < >)sainspect	transientidpendingjoinmapstridentitytyper   )r   statepks      r   __repr__zModel.__repr__8   s    

4    ??r$xj*B]]RXJa(B3sENN34B4:&&'qA..r   N)r   r(   )
r   r   r   r   __annotations__r   r   r   r   r-   r   r   r   r   r      s@     $#
 ,1K(0  ./E//r   r   c                  N     e Zd ZU dZded<   ded<   	 	 	 	 	 	 	 	 	 	 d fdZ xZS )BindMetaMixina  Metaclass mixin that sets a model's ``metadata`` based on its ``__bind_key__``.

    If the model sets ``metadata`` or ``__table__`` directly, ``__bind_key__`` is
    ignored. If the ``metadata`` is the same as the parent model, it will not be set
    directly on the child model.
    r   r   sa.MetaDatametadatac                    d| j                   v sNd| j                   v s@t        | dd       }t        | dd       }| j                  j                  |      }||ur|| _        t        |   |||fi | y )Nr2   	__table____bind_key__)__dict__getattrr   _make_metadatar2   super__init__)	r   namebasesdkwargsbind_keyparent_metadatar2   	__class__s	           r   r:   zBindMetaMixin.__init__Q   sq     cll*kS\\.IsND9H%c:t<O{{11(;H.'ua262r   
r;   r(   r<   ztuple[type, ...]r=   zdict[str, t.Any]r>   t.Anyr   None)r   r   r   r   r.   r:   __classcell__rA   s   @r   r0   r0   F   sH     33/34D3PU3	3 3r   r0   c                  D     e Zd ZU dZded<   ded<   ed fd       Z xZS )	BindMixina  DeclarativeBase mixin to set a model's ``metadata`` based on ``__bind_key__``.

    If no ``__bind_key__`` is specified, the model will use the default metadata
    provided by ``DeclarativeBase`` or ``DeclarativeBaseNoMeta``.
    If the model doesn't set ``metadata`` or ``__table__`` directly
    and does set ``__bind_key__``, the model will use the metadata
    for the specified bind key.
    If the ``metadata`` is the same as the parent model, it will not be set
    directly on the child model.

    .. versionchanged:: 3.1.0
    r   r   r1   r2   c                    d| j                   v sZd| j                   v sLt        | d      r@t        | dd       }t        | dd       }| j                  j	                  |      }||ur|| _        t        |   di | y )Nr2   r4   r5   r   )r6   hasattrr7   r   r8   r2   r9   __init_subclass__)r   r>   r?   r@   r2   rA   s        r   rK   zBindMixin.__init_subclass__p   sx    cll*kS\\.IwP
 sND9H%c:t<O{{11(;H.'!+F+r   )r   zt.Type[BindMixin]r>   t.Dict[str, t.Any]r   rD   )r   r   r   r   r.   classmethodrK   rE   rF   s   @r   rH   rH   _   s(     , ,r   rH   c                  `     e Zd ZU dZded<   ded<   ded<   	 	 	 	 	 	 	 	 	 	 d
 fdZdd	Z xZS )NameMetaMixinaP  Metaclass mixin that sets a model's ``__tablename__`` by converting the
    ``CamelCase`` class name to ``snake_case``. A name is set for non-abstract models
    that do not otherwise define ``__tablename__``. If a model does not define a primary
    key, it will not generate a name or ``__table__``, for single-table inheritance.
    r1   r2   r(   __tablename__sa.Tabler4   c                    t        |       rt        | j                        | _        t	        |   |||fi | d| j                  vr"d| j                  v r| j                  d   | `y y y y )NrP   r4   )should_set_tablenamecamel_to_snake_caser   rP   r9   r:   r6   r4   )r   r;   r<   r=   r>   rA   s        r   r:   zNameMetaMixin.__init__   sq      $ 3CLL ACua262 3<</s||+[)1 2 , 0r   c                   |j                  d      }||d   }n
| d|d    }|| j                  j                  v rt        j                  |i |S |D ]Y  }t        |t        j                        r|j                  st        |t        j                        sDt        j                  |i |c S  | j                  dd D ]  }d|j                  v s n t        j                  |i |S d| j                  v r| `y	a  This is called by SQLAlchemy during mapper setup. It determines the final
        table object that the model will use.

        If no primary key is found, that indicates single-table inheritance, so no table
        will be created and ``__tablename__`` will be unset.
        schemaNr   .r   r4   rP   getr2   tablesr!   Table
isinstanceColumnprimary_keyPrimaryKeyConstraint__mro__r6   rP   r   argsr>   rW   keyargbases          r   __table_cls__zNameMetaMixin.__table_cls__   s     H%>q'CHAd1gY'C #,,%%%88T,V,, C3		*s:R,,D xx000	  KK"%Ddmm+ & 88T,V,, cll*!r   rB   rd   rC   r>   rC   r   zsa.Table | None)r   r   r   r   r.   r:   rh   rE   rF   s   @r   rO   rO      sN     /4DPU	 'r   rO   c                  `     e Zd ZU dZded<   ded<   ded<   ed
 fd       Zedd	       Z xZS )	NameMixinau  DeclarativeBase mixin that sets a model's ``__tablename__`` by converting the
    ``CamelCase`` class name to ``snake_case``. A name is set for non-abstract models
    that do not otherwise define ``__tablename__``. If a model does not define a primary
    key, it will not generate a name or ``__table__``, for single-table inheritance.

    .. versionchanged:: 3.1.0
    r1   r2   r(   rP   rQ   r4   c                    t        |       rt        | j                        | _        t	        |   di | d| j                  vr"d| j                  v r| j                  d   | `y y y y )NrP   r4   r   )rS   rT   r   rP   r9   rK   r6   r4   )r   r>   rA   s     r   rK   zNameMixin.__init_subclass__   si    $ 3CLL AC!+F+ 3<</s||+[)1 2 , 0r   c                   |j                  d      }||d   }n
| d|d    }|| j                  j                  v rt        j                  |i |S |D ]Y  }t        |t        j                        r|j                  st        |t        j                        sDt        j                  |i |c S  | j                  dd D ]  }d|j                  v s n t        j                  |i |S d| j                  v r| `yrV   rZ   rc   s          r   rh   zNameMixin.__table_cls__   s     H%>q'CHAd1gY'C #,,%%%88T,V,, C3		*s:R,,D xx000	  KK"%Ddmm+ & 88T,V,, cll*!r   )r   zt.Type[NameMixin]r>   rL   r   rD   ri   )	r   r   r   r   r.   rM   rK   rh   rE   rF   s   @r   rk   rk      sB       ' 'r   rk   c                   | j                   j                  dd      set        | t        j                  t        j
                  f      st        d | j                  dd D              rt        d | j                  D              ry| j                  D ]  }d|j                   vrt        |j                   d   t        j                        r y|| u xs{ |j                   j                  dd      xs] t        |t        j                        xs@ t        |t        j                  j                        xs t        |t        j
                          c S  y)	a  Determine whether ``__tablename__`` should be generated for a model.

    -   If no class in the MRO sets a name, one should be generated.
    -   If a declared attr is found, it should be used instead.
    -   If a name is found, it should be used if the class is a mixin, otherwise one
        should be generated.
    -   Abstract models should not have one generated.

    Later, ``__table_cls__`` will determine if the model looks like single or
    joined-table inheritance. If no primary key is found, the name will be unset.
    __abstract__Fc              3  P   K   | ]  }t        |t        j                           y wN)r^   sa_ormDeclarativeMeta.0bs     r   	<genexpr>z'should_set_tablename.<locals>.<genexpr>  s     W!
1f&<&<=s   $&r   Nc              3  h   K   | ]*  }|t         j                  u xs |t         j                  u  , y wrq   )rr   DeclarativeBaseDeclarativeBaseNoMetart   s     r   rw   z'should_set_tablename.<locals>.<genexpr>  s6      
" &(((MA1M1M,MM"s   02rP   T)r6   r[   
issubclassrr   ry   rz   anyrb   	__bases__r^   declared_attrrs   decl_apiDeclarativeAttributeIntercept)r   rg   s     r   rS   rS     s#    	/3!7!79U9U VWWs{{STSUWW 
]]
 

 $--/dmmO4f6J6JK CK 	}}  7	 4!7!78 BdFOO$Q$QRB dF$@$@A
 	
 ( r   c                n    t        j                  dd|       } | j                         j                  d      S )z/Convert a ``CamelCase`` name to ``snake_case``.z(((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))z_\1_)resublowerlstrip)r;   s    r   rT   rT   ;  s,    66=vtLD::<s##r   c                      e Zd ZdZy)DefaultMetagSQLAlchemy declarative metaclass that provides ``__bind_key__`` and
    ``__tablename__`` support.
    Nr   r   r   r   r   r   r   r   r   A      r   r   c                      e Zd ZdZy)DefaultMetaNoNamer   Nr   r   r   r   r   r   G  r   r   r   )r   r*   r   bool)r;   r(   r   r(   )
__future__r   r   typingt
sqlalchemyr!   sqlalchemy.ormormrr   r   r   TYPE_CHECKING	extensionr   r   r   r*   r0   rH   rO   rk   rS   rT   rs   r   r   r   r   r   <module>r      s    " 	    ??%	
 	
(/ (/V3D 32, ,@BD BJD DN-`$-0F0F v'='= r   