first commit
This commit is contained in:
26
app/media/repository.py
Normal file
26
app/media/repository.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user