async def add_workspace(target: str, desc: str, *, async_session: "AsyncSession") -> None: async with async_session() as session: async with session.begin(): workspace = Workspace(name=target, description=desc) session.add(workspace) await session.commit()
async def all_workspaces( *, async_session: "AsyncSession") -> "ChunkedIteratorResult": async with async_session() as session: async with session.begin(): stmt = select(Workspace) result = await session.execute(stmt) return result
async def is_workspace_exists(target: str, *, async_session: "AsyncSession") -> bool: async with async_session() as session: async with session.begin(): stmt = select(Workspace).where(Workspace.name == target) result = await session.execute(stmt) workspace = result.scalar_one_or_none() return bool(workspace)
async def insert_default_rows(session: "AsyncSession") -> None: async with async_session() as session: async with session.begin(): stmt = select(Workspace).where(Workspace.name == "default") result = await session.execute(stmt) workspace = result.scalar_one_or_none() if not workspace: default_workspace = Workspace(name="default", description="Default workspace") session.add(default_workspace) await session.commit() else: console.log("Found default workspace, skipping")
async def delete_workspace(target: str, *, async_session: "AsyncSession") -> None: async with async_session() as session: async with session.begin(): stmt = delete(Workspace).where(Workspace.name == target) await session.execute(stmt)