예제 #1
0
 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()
             for batch in chunked(rows,100):
                 AnnotationEntity \
                     .insert_many(batch, fields=["entry", "label", "points", "kind"]) \
                     .execute()
예제 #2
0
 def save(self, param: typing.Any):
     if isinstance(param, AnnotaVO):
         vo = param
         return AnnotationEntity.create(
             entry=vo.entry,
             label=vo.label,
             points=vo.points,
             kind=vo.kind
         )
     elif isinstance(param, list):
         with db.atomic():
             rows = [
                 (vo.entry,
                  vo.label,
                  vo.points,
                  vo.kind)
                 for vo in param]
             AnnotationEntity \
                 .insert_many(rows, fields=["entry", "label", "points", "kind"]) \
                 .execute()