from sqlalchemy import select, insert from app.database import async_session_maker from app.models import URLs class URLsDAO: @staticmethod async def add_new_url(original_url: str) -> int: async with async_session_maker() as session: query = insert(URLs).values(original_url=original_url).returning(URLs.url_hash) result = await session.execute(query) await session.commit() result = result.scalar() return result @staticmethod async def find_by_hash(url_hash: int) -> URLs: async with async_session_maker() as session: query = select(URLs).filter_by(url_hash=url_hash) result = await session.execute(query) return result.scalar_one_or_none()