def fetch_all(self, entity_id: int): anns = AnnotationEntity.alias() lbl = LabelEntity.alias() query = ( anns.select( anns.id.alias("annot_id"), anns.entry.alias("annot_entry"), anns.kind.alias("annot_kind"), anns.points.alias("annot_points"), lbl.id.alias("label_id"), lbl.name.alias("label_name"), lbl.color.alias("label_color") ) .join(lbl, on=(anns.label == lbl.id), join_type="LEFT") .where(anns.entry == entity_id) ) cursor = query.dicts().execute() result = [] for row in cursor: ann_vo = AnnotaVO() ann_vo.id = row["annot_id"] ann_vo.entry = row["annot_entry"] ann_vo.kind = row["annot_kind"] ann_vo.points = row["annot_points"] ann_vo.label = None if row["label_id"]: label = LabelVO() label.id = row["label_id"] label.name = row["label_name"] label.color = row["label_color"] ann_vo.label = label result.append(ann_vo) return result
def save(self, vo: LabelVO): label = LabelEntity.create(name=vo.name, color=vo.color, dataset=vo.dataset) vo.id = label.get_id() return vo