e4e2595e70
- adapters: SQLAlchemy implementations for all 4 repositories (Project, AssetLibrary, Asset, IngestJob) - models: SQLAlchemy ORM models with proper schema - database: connection config and session management - tests: SQLAlchemy repository integration test (in-memory SQLite) - all 7 integration tests passing
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from sqlalchemy.orm import Session
|
|
|
|
from packages.domain import Project
|
|
from packages.adapters.sqlalchemy_impl.models import ProjectModel
|
|
|
|
|
|
class SQLAlchemyProjectRepository:
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def list_by_workspace(self, workspace_id: str) -> list[Project]:
|
|
models = self.session.query(ProjectModel).filter(ProjectModel.workspace_id == workspace_id).all()
|
|
return [
|
|
Project(
|
|
id=m.id,
|
|
workspace_id=m.workspace_id,
|
|
name=m.name,
|
|
description=m.description,
|
|
created_at=m.created_at,
|
|
)
|
|
for m in models
|
|
]
|
|
|
|
def create(self, project: Project) -> Project:
|
|
model = ProjectModel(
|
|
id=project.id,
|
|
workspace_id=project.workspace_id,
|
|
name=project.name,
|
|
description=project.description,
|
|
created_at=project.created_at,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
return project
|