diff --git a/arkindex/documents/export/__init__.py b/arkindex/documents/export/__init__.py index f14d16ca03076cecb15649385fc1f30a877ee145..7f5207d14160668393734ee97da88205aeee86ea 100644 --- a/arkindex/documents/export/__init__.py +++ b/arkindex/documents/export/__init__.py @@ -1,3 +1,4 @@ +import json import logging import sqlite3 import tempfile @@ -50,13 +51,19 @@ def save_sqlite(rows, table, cursor): """ Write a chunk of rows into an SQLite table """ + def _serialize(value): + # Serialize UUID as string + if isinstance(value, uuid.UUID): + return str(value) + + # Serialize list and dicts as json + if isinstance(value, (list, dict)): + return json.dumps(value) + + return value - # Serialize UUID and lists as strings rows = [ - [ - str(value) if isinstance(value, (uuid.UUID, list)) else value - for value in row - ] + list(map(_serialize, row)) for row in rows ]