from chitai.config import settings

from advanced_alchemy.extensions.litestar import (
    SQLAlchemyAsyncConfig,
    AsyncSessionConfig,
    SQLAlchemyPlugin,
)
from sqlalchemy.ext.asyncio import create_async_engine
from chitai.database import models

DATABASE_URL = str(settings.postgres_uri)

session_config = AsyncSessionConfig(expire_on_commit=False)

config = SQLAlchemyAsyncConfig(
    engine_instance=create_async_engine(DATABASE_URL, echo=settings.postgres_echo),
    session_config=session_config,
    before_send_handler="autocommit",
    create_all=True,
    
)

alchemy = SQLAlchemyPlugin(config=config)
