from databases import Database
from sqlalchemy import MetaData
from sqlalchemy.orm import declarative_base
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine

from backend.config import settings

metadata = MetaData()
Base = declarative_base(metadata=metadata)

# async engine for use with run_sync and sessionmaker
engine = create_async_engine(
    settings.database_url,
    echo=(settings.environment == "dev"),
    future=True,
)

# asyncpg connection used by `databases` package
database = Database(settings.database_url)
