コード例 #1
0
ファイル: revision.py プロジェクト: hetida/hetida-designer
def select_multiple_transformation_revisions(
    category: Optional[str] = None,
    revision_group_id: Optional[UUID] = None,
    type: Optional[Type] = None,
    state: Optional[State] = None,
) -> List[TransformationRevision]:
    """Filterable selection of transformation revisions from db"""
    with Session() as session, session.begin():
        selection = select(TransformationRevisionDBModel)

        if category is not None:
            selection = selection.where(
                TransformationRevisionDBModel.category == category)
        if revision_group_id is not None:
            selection = selection.where(TransformationRevisionDBModel.
                                        revision_group_id == revision_group_id)
        if type is not None:
            selection = selection.where(
                TransformationRevisionDBModel.type == type)
        if state is not None:
            selection = selection.where(
                TransformationRevisionDBModel.state == state)

        results = session.execute(selection).scalars().all()

        return [
            TransformationRevision.from_orm_model(result) for result in results
        ]
コード例 #2
0
ファイル: revision.py プロジェクト: hetida/hetida-designer
def select_tr_by_id(session: SQLAlchemySession,
                    id: UUID,
                    log_error: bool = True) -> TransformationRevision:

    result = session.execute(
        select(TransformationRevisionDBModel).where(
            TransformationRevisionDBModel.id == id)).scalar_one_or_none()

    if result is None:
        msg = f"Found no transformation revision in database with id {id}"
        if log_error:
            logger.error(msg)
        raise DBNotFoundError(msg)

    return TransformationRevision.from_orm_model(result)