� ���g� ��ddlmZmZmZmZmZmZddlmZddl m Z m Z m Z ddl mZmZddlmZddlmZmZddlZddlZddlmZmZdd lmZdd lmZmZdd lm Z Gd �d e ��Z!Gd�dee��Z"Gd�de��Z#e��Z$Gd�dej%��Z& ddej'j(de)dee)eedfffd�Z*dS)�)�Any�Optional�Sequence�Tuple�Type�Union)� TracebackType)�Protocol�Self�Literal)�ABC�abstractmethod)�local)�override�EnforceOverridesN)�System� Component)�UUID)�islice�count)�SeqIdc ���eZdZdZd dedeeedfdefd�Z dedefd �Z d dedee eedfdefd �Z deedffd �Z de eedffd �ZdS)�CursorzFReifies methods we use from a DBAPI2 Cursor since DBAPI2 is not typed.N�sql�params.�returnc��dS�N���selfrrs �`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/chromadb/db/base.py�executezCursor.execute��� ���scriptc��dSrr)r!r&s r"� executescriptzCursor.executescriptr$r%c��dSrrr s r"� executemanyzCursor.executemanys �� �r%c��dSrr�r!s r"�fetchonezCursor.fetchoner$r%c��dSrrr,s r"�fetchallzCursor.fetchall r$r%r)�__name__� __module__� __qualname__�__doc__�strrrrr r#r(rr*r-r/rr%r"rrs ������P�P� � �3� ���s�C�x��(A� �T� � � � � �C� �D� � � � �GK� � �� � (��%��S��/�)B� C� � � � � � �  �%��S��/� � � � � �(�5��c��?�3� � � � � � r%rc ��eZdZdZedefd���Zedeee dee dee de dfd���Z d S) � TxWrapperaFWrapper class for DBAPI 2.0 Connection objects, with which clients can implement transactions. Makes two guarantees that basic DBAPI 2.0 connections do not: - __enter__ returns a Cursor object consistently (instead of a Connection like some do) - Always re-raises an exception if one was thrown from the body rc��dSrrr,s r"� __enter__zTxWrapper.__enter__,s�� �r%�exc_type� exc_value� tracebackFc��dSrr)r!r9r:r;s r"�__exit__zTxWrapper.__exit__0� �� �r%N) r0r1r2r3rrr8rr� BaseExceptionr r r=rr%r"r6r6$s���������� �6� � � ��^� �� ��4� �.�/� ��M�*� ��M�*�  � ���  � � ��^� � � r%r6c����eZdZdZdef�fd� Zedefd���Ze ede e j fd�����Z e edefd�����Ze edeedeefd �����Ze ed eedeefd �����Ze ede efd �����Zd ede jfd�Ze deeefdefd���Ze dedefd���Z�xZS)�SqlDBzQDBAPI 2.0 interface wrapper to ensure consistent behavior between implementations�systemc�J��t���|��dSr)�super�__init__)r!rB� __class__s �r"rEzSqlDB.__init__=s!��� ������ � � � � r%rc��dS)zReturn a transaction wrapperNrr,s r"�txzSqlDB.tx@s �� �r%c��dS)z�Return a PyPika Query builder of an appropriate subtype for this database implementation (see https://pypika.readthedocs.io/en/latest/3_advanced.html#handling-different-database-platforms) Nrrr%r"� querybuilderzSqlDB.querybuilderEr>r%c��dS)z�Return the appropriate parameter format for this database implementation. Will be called with str.format(i) where i is the numeric index of the parameter. Nrrr%r"�parameter_formatzSqlDB.parameter_formatNs �� �r%�uuidc��dS)z=Convert a UUID to a value that can be passed to the DB driverNr)rMs r"� uuid_to_dbzSqlDB.uuid_to_dbV� �� �r%�valuec��dS)z,Convert a value from the DB driver to a UUIDNr�rQs r"� uuid_from_dbzSqlDB.uuid_from_db\rPr%c��dS)zYReturn the exception type that the DB raises when a unique constraint is violatedNrrr%r"�unique_constraint_errorzSqlDB.unique_constraint_errorbs �� �r%�idxc�t�tj|����|����S)z4Return a PyPika Parameter object for the given index)�pypika� ParameterrL�format)r!rWs r"�paramz SqlDB.paramis-����� 5� 5� 7� 7� >� >�s� C� C�D�D�Dr%� seq_id_bytesc�&�t|t��r|St|��dkrt�|d��St|��dkrt�|d��St dt|�������)z Decode a byte array into a SeqID��big�zUnknown SeqID type with length )� isinstance�int�len� from_bytes� ValueError)r]s r"� decode_seq_idzSqlDB.decode_seq_idms��� �l�C� (� (� �� � �|� � �� !� !��>�>�,��6�6� 6� �� � �"� $� $��>�>�,��6�6� 6��R�s�<�?P�?P�R�R�S�S� Sr%�seq_idc���|���dkrt�|dd��S|���dkrt�|dd��Std|�����)z Encode a SeqID into a byte array�@r_r`��razUnsupported SeqID: )� bit_lengthrc�to_bytesrf)rhs r"� encode_seq_idzSqlDB.encode_seq_idzsu�� � � � � �"� $� $��<�<���5�1�1� 1� � � � � �C� '� '��<�<���E�2�2� 2��;�6�;�;�<�<� <r%) r0r1r2r3rrErr6rH� staticmethodrrY�QueryrJr4rLrrrrOrTr?rVrcrZr\r�bytesrrgrn� __classcell__)rFs@r"rArA:s&�������[�[�!�v�!�!�!�!�!�!�� �I� � � ��^� ��� �$�v�|�,� � � ��^��\� ��� �c� � � ��^��\� � �� ��$�� �H�S�M� � � ��^��\� ��� �H�S�M� �h�t�n� � � ��^��\� ��� �T�-�%8� � � ��^��\� � E��E��!1�E�E�E�E�� T�E�%��*�$5� T�%� T� T� T��\� T��=�e�=��=�=�=��\�=�=�=�=�=r%rAc�>�eZdZdZdefd�Zededefd���ZdS)�ParameterValuez� Wrapper class for PyPika paramters that allows the values for Parameters to be expressed inline while building a query. See get_sql() for detailed usage information. rQc��||_dSrrS)r!rQs r"rEzParameterValue.__init__�s ���� � � r%�kwargsrc ��t|jttf��rvtj�|j��ttjt|j����}d� d�|D����}d|�d�}nZtj� |j��tj � ttj����}t|��S)Nz, c3�TK�|]#}tj�|��V��$dSr)�_context� formatstrr[)�.0�is r"� <genexpr>z)ParameterValue.get_sql.<locals>.<genexpr>�s3����$S�$S�a�X�%7�%>�%>�q�%A�%A�$S�$S�$S�$S�$S�$Sr%�(�))rbrQ�list�tuplery�values�extendr� generatorrd�join�appendrzr[�nextr4)r!rv�indexes� placeholders�vals r"�get_sqlzParameterValue.get_sql�s��� �d�j�4��-� 0� 0� F� �O� "� "�4�:� .� .� .��X�/��T�Z���A�A�G��9�9�$S�$S�7�$S�$S�$S�S�S�L�%�l�%�%�%�C�C� �O� "� "�4�:� .� .� .��$�+�+�D��1C�,D�,D�E�E�C��3�x�x�r%N) r0r1r2r3rrErr4r�rr%r"rtrt�sg�������� �c������ �� �� � � ��X� � � r%rt�?�queryrzr.c���gt_td��t_|t_|���}t tj��}||fS)af Wrapper for pypika's get_sql method that allows the values for Parameters to be expressed inline while building a query, and that returns a tuple of the SQL string and parameters. This makes it easier to construct complex queries programmatically and automatically matches up the generated SQL with the required parameter vector. Doing so requires using the ParameterValue class defined in this module instead of the base pypika.Parameter class. Usage Example: q = ( pypika.Query().from_("table") .select("col1") .where("col2"==ParameterValue("foo")) .where("col3"==ParameterValue("bar")) ) sql, params = get_sql(q) cursor.execute(sql, params) Note how it is not necessary to construct the parameter vector manually... it will always be generated with the parameter values in the same order as emitted SQL string. The format string should match the parameter format for the database being used. It will be called with str.format(i) where i is the numeric index of the parameter. For example, Postgres requires parameters like `:1`, `:2`, etc. so the format string should be `":{}"`. See https://pypika.readthedocs.io/en/latest/2_tutorial.html#parametrized-queries for more information on parameterized queries in PyPika. �)ryr�rr�rzr�r�)r�rzrrs r"r�r��sH��N�H�O��q���H��"�H�� �-�-�/�/�C� �8�?� #� #�F� ��;�r%)r�)+�typingrrrrrr�typesr �typing_extensionsr r r �abcr r� threadingr� overridesrrrY�pypika.queries�chromadb.configrrrMr� itertoolsrr�chromadb.typesrrr6rAryrZrt�queries� QueryBuilderr4r�rr%r"�<module>r�s+��>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�������5�5�5�5�5�5�5�5�5�5�#�#�#�#�#�#�#�#�������0�0�0�0�0�0�0�0� � � � �����-�-�-�-�-�-�-�-�������#�#�#�#�#�#�#�#� � � � � � � � � � � �X� � � �* � � � � ��%� � � �,H=�H=�H=�H=�H=�I�H=�H=�H=�V �5�7�7�������V�%����2:=�,�,� �>� &�,�36�,� �3��c�3�h�� � �,�,�,�,�,�,r%
Memory