o
    ޭh                     @  s   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 ej
dkr*d dlmZ nd dlmZ d"ddZer=d dlmZ d#ddZd$ddZd%d&d d!ZdS )'    )annotationsN)Iterable)TYPE_CHECKINGAny)logger)      batched)isliceiterableIterable[Any]nintreturnIterable[tuple[Any]]c                 c  s<    t | }tt|| }r|V  tt|| }sd S d S N)itertupler   )r   r   itbatch r   S/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/tortoise/utils.pyr
      s
   r
   )BaseDBAsyncClientclientr   safeboolstrc                 C  s   |  | }||S )z
    Generates the SQL schema for the given client.

    :param client: The DB client to generate Schema SQL for
    :param safe: When set to true, creates the table only when it does not already exist.
    )schema_generatorget_create_schema_sql)r   r   	generatorr   r   r   get_schema_sql   s   

r!   Nonec                   s>   |  | }t| |}td| |r||I dH  dS dS )z
    Generates and applies the SQL schema directly to the given client.

    :param client: The DB client to generate Schema SQL for
    :param safe: When set to true, creates the table only when it does not already exist.
    zCreating schema: %sN)r   r!   r   debuggenerate_from_string)r   r   r    schemar   r   r   generate_schema_for_client#   s   

r&   	instances
batch_size
int | NoneIterable[Iterable[Any]]c                 c  s$    |s| V  dS t | |E dH  dS )zB
    Generate iterable chunk by batch_size
    # noqa: DAR301
    Nr	   )r'   r(   r   r   r   chunk1   s   
r+   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r"   r   )r'   r   r(   r)   r   r*   )
__future__r   syscollections.abcr   typingr   r   tortoise.logr   version_info	itertoolsr
   r   tortoise.backends.base.clientr   r!   r&   r+   r   r   r   r   <module>   s    



