o
    Xhh                     @   s   d dl mZmZ d dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZ e  edZee eedd	d
ZeeeddZdd Zde	edf fddZdS )    )create_async_engineAsyncSession)sessionmaker)BaseN)AsyncGenerator)load_dotenvDATABASE_URL
      )	pool_sizemax_overflowF)class_expire_on_commitc               	      sX   t  4 I dH } | tjjI dH  W d  I dH  dS 1 I dH s%w   Y  dS )u{   
    Initialize database tables by creating them if they don’t exist.
    This function runs at application startup.
    N)enginebeginrun_syncr   metadata
create_all)conn r   E/var/www/html/construction_image-detection-poc/src/config/database.pyinit_db   s   .r   returnc               	   C  sH   t  4 I dH } | V  W d  I dH  dS 1 I dH sw   Y  dS )z
    Dependency function to provide an async database session.
    Used in FastAPI route handlers to manage transactions efficiently.
    N)async_session)sessionr   r   r   get_db"   s   .r   )sqlalchemy.ext.asyncior   r   sqlalchemy.ormr   src.models.baser   ostypingr   dotenvr   getenvr   printr   r   r   r   r   r   r   r   <module>   s*    
