
from fastapi import Depends,Request
from app.db.session import get_tenant_db
from app.core import tenantCacheService
from app.db.session import tenantdb

def get_db(request: Request,tenant:str = "1",tenantdb = Depends(get_tenant_db)):
    database = tenantCacheService.get_tenant_db(tenantdb,tenant)
    try:
        db = database.get_db()
        request.state.tenant = tenant
        request.state.db = db 
        yield db  
    finally:
        db.close() 


def get_log_db():
    db =  tenantdb.get_db()
    return db