文件版本管理-初步优化
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import uuid
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.version_workflow import VersionWorkflow
|
||||
|
||||
|
||||
async def create(db: AsyncSession, workflow: VersionWorkflow, *, commit: bool = True) -> VersionWorkflow:
|
||||
db.add(workflow)
|
||||
if commit:
|
||||
await db.commit()
|
||||
await db.refresh(workflow)
|
||||
return workflow
|
||||
|
||||
|
||||
async def get(db: AsyncSession, workflow_id: uuid.UUID) -> VersionWorkflow | None:
|
||||
result = await db.execute(select(VersionWorkflow).where(VersionWorkflow.id == workflow_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_by_version(db: AsyncSession, version_id: uuid.UUID) -> VersionWorkflow | None:
|
||||
result = await db.execute(select(VersionWorkflow).where(VersionWorkflow.version_id == version_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def list_by_document(db: AsyncSession, document_id: uuid.UUID) -> Sequence[VersionWorkflow]:
|
||||
result = await db.execute(select(VersionWorkflow).where(VersionWorkflow.document_id == document_id))
|
||||
return result.scalars().all()
|
||||
Reference in New Issue
Block a user