
import asyncio
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import AsyncSessionLocal
from app.models.models import Customer
from sqlalchemy import select
from fastapi.templating import Jinja2Templates
import os
import traceback

async def diag():
    try:
        async with AsyncSessionLocal() as session:
            result = await session.execute(select(Customer))
            customers = result.scalars().all()
            BASE_DIR = r"C:/Users/MF Sangadji/bestweb"
            templates = Jinja2Templates(directory=os.path.join(BASE_DIR, "app/templates"))
            # Panggil dengan dict konteks yang benar untuk Starlette/FastAPI
            print(templates.TemplateResponse("customers.html", {"request": None, "customers": customers}))
    except Exception:
        traceback.print_exc()

asyncio.run(diag())

