def save(self, entity_id, entry: typing.Any): if isinstance(entry, AnnotaVO): vo = entry return AnnotationEntity.create(entry=vo.entry, label=vo.label, points=vo.points, kind=vo.kind) elif isinstance(entry, list): with db.atomic(): query = (AnnotationEntity.delete().where( AnnotationEntity.entry == entity_id)) query.execute() rows = [(vo.entry, vo.label, vo.points, vo.kind) for vo in entry] AnnotationEntity \ .insert_many(rows, fields=["entry", "label", "points", "kind"]) \ .execute()
def delete(self, entity_id: int): query = (AnnotationEntity.delete().where( AnnotationEntity.entry == entity_id)) return query.execute()