Files
Nexus/server/infrastructure/database/rdp_host_repo.py
T
Nexus Agent f127f07ab2 feat(rdp): 3389 页独立管理 RDP 主机
rdp_hosts 表与专用 API,在 3389远程页添加/连接,不再依赖子机列表。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-10 20:58:46 +08:00

47 lines
1.5 KiB
Python

"""RDP host repository (standalone 3389 endpoints)."""
from __future__ import annotations
from typing import List, Optional
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from server.domain.models import RdpHost
class RdpHostRepositoryImpl:
def __init__(self, session: AsyncSession):
self.session = session
async def get_by_id(self, host_id: int) -> Optional[RdpHost]:
result = await self.session.execute(select(RdpHost).where(RdpHost.id == host_id))
return result.scalar_one_or_none()
async def get_by_name(self, name: str) -> Optional[RdpHost]:
result = await self.session.execute(select(RdpHost).where(RdpHost.name == name))
return result.scalar_one_or_none()
async def list_all(self) -> List[RdpHost]:
result = await self.session.execute(select(RdpHost).order_by(RdpHost.name))
return list(result.scalars().all())
async def create(self, row: RdpHost) -> RdpHost:
self.session.add(row)
await self.session.commit()
await self.session.refresh(row)
return row
async def update(self, row: RdpHost) -> RdpHost:
await self.session.commit()
await self.session.refresh(row)
return row
async def delete(self, host_id: int) -> bool:
row = await self.get_by_id(host_id)
if not row:
return False
await self.session.delete(row)
await self.session.commit()
return True