更新历史记录相关API,支持异步操作

This commit is contained in:
jxxghp
2025-07-30 14:27:38 +08:00
parent f14f4e1e9b
commit 21541bc468
4 changed files with 153 additions and 30 deletions
+11 -2
View File
@@ -1,10 +1,11 @@
import time
from typing import Optional
from sqlalchemy import Column, Integer, String, Sequence, JSON
from sqlalchemy import Column, Integer, String, Sequence, JSON, select
from sqlalchemy.orm import Session
from sqlalchemy.ext.asyncio import AsyncSession
from app.db import db_query, db_update, Base
from app.db import db_query, db_update, Base, async_db_query
class DownloadHistory(Base):
@@ -76,6 +77,14 @@ class DownloadHistory(Base):
def list_by_page(db: Session, page: Optional[int] = 1, count: Optional[int] = 30):
return db.query(DownloadHistory).offset((page - 1) * count).limit(count).all()
@classmethod
@async_db_query
async def async_list_by_page(cls, db: AsyncSession, page: Optional[int] = 1, count: Optional[int] = 30):
result = await db.execute(
select(cls).offset((page - 1) * count).limit(count)
)
return result.scalars().all()
@staticmethod
@db_query
def get_by_path(db: Session, path: str):