This commit is contained in:
jxxghp
2025-07-30 18:37:16 +08:00
parent cd8661abc1
commit edec18cacb
+1 -5
View File
@@ -1,7 +1,7 @@
import asyncio import asyncio
from typing import Any, Generator, List, Optional, Self, Tuple, AsyncGenerator, Sequence from typing import Any, Generator, List, Optional, Self, Tuple, AsyncGenerator, Sequence
from sqlalchemy import NullPool, QueuePool, and_, create_engine, inspect, text from sqlalchemy import NullPool, QueuePool, and_, create_engine, inspect, text, select, delete
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.orm import Session, as_declarative, declared_attr, scoped_session, sessionmaker from sqlalchemy.orm import Session, as_declarative, declared_attr, scoped_session, sessionmaker
@@ -362,7 +362,6 @@ class Base:
@classmethod @classmethod
@async_db_query @async_db_query
async def async_get(cls, db: AsyncSession, rid: int) -> Self: async def async_get(cls, db: AsyncSession, rid: int) -> Self:
from sqlalchemy import select
result = await db.execute(select(cls).where(and_(cls.id == rid))) result = await db.execute(select(cls).where(and_(cls.id == rid)))
return result.scalars().first() return result.scalars().first()
@@ -390,7 +389,6 @@ class Base:
@classmethod @classmethod
@async_db_update @async_db_update
async def async_delete(cls, db: AsyncSession, rid): async def async_delete(cls, db: AsyncSession, rid):
from sqlalchemy import select
result = await db.execute(select(cls).where(and_(cls.id == rid))) result = await db.execute(select(cls).where(and_(cls.id == rid)))
user = result.scalars().first() user = result.scalars().first()
if user: if user:
@@ -404,7 +402,6 @@ class Base:
@classmethod @classmethod
@async_db_update @async_db_update
async def async_truncate(cls, db: AsyncSession): async def async_truncate(cls, db: AsyncSession):
from sqlalchemy import delete
await db.execute(delete(cls)) await db.execute(delete(cls))
@classmethod @classmethod
@@ -415,7 +412,6 @@ class Base:
@classmethod @classmethod
@async_db_query @async_db_query
async def async_list(cls, db: AsyncSession) -> Sequence[Self]: async def async_list(cls, db: AsyncSession) -> Sequence[Self]:
from sqlalchemy import select
result = await db.execute(select(cls)) result = await db.execute(select(cls))
return result.scalars().all() return result.scalars().all()