27 lines
607 B
Python
27 lines
607 B
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.media.models import Attachment
|
|
|
|
|
|
async def create_attachment(
|
|
db: AsyncSession,
|
|
*,
|
|
message_id: int,
|
|
file_url: str,
|
|
file_type: str,
|
|
file_size: int,
|
|
) -> Attachment:
|
|
attachment = Attachment(
|
|
message_id=message_id,
|
|
file_url=file_url,
|
|
file_type=file_type,
|
|
file_size=file_size,
|
|
)
|
|
db.add(attachment)
|
|
await db.flush()
|
|
return attachment
|
|
|
|
|
|
async def get_attachment_by_id(db: AsyncSession, attachment_id: int) -> Attachment | None:
|
|
return await db.get(Attachment, attachment_id)
|