Skip to content

Commit

Permalink
database:columns - if the schema is empty, set the column to text and…
Browse files Browse the repository at this point in the history
… use json dumps/loads
  • Loading branch information
MatteoCampinoti94 committed Oct 17, 2023
1 parent 4d5c712 commit 6b9e78b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions acacore/database/column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import datetime
from json import dumps
from json import loads
from pathlib import Path
from typing import Callable
from typing import Generic
Expand Down Expand Up @@ -59,9 +61,12 @@ def _schema_to_column(name: str, schema: dict, defs: Optional[dict[str, dict]] =
else:
raise TypeError(f"Cannot recognize type from schema {schema!r}")
elif schema_any_of:
if (schema_any_of[-1].get("type", None) != "null" and len(schema_any_of) > 1) or len(schema_any_of) > 2:
if not schema_any_of[0]:
sql_type, to_entry, from_entry = "text", lambda x: dumps(x, default=str), lambda x: loads(x, default=str)
elif (schema_any_of[-1].get("type", None) != "null" and len(schema_any_of) > 1) or len(schema_any_of) > 2:
raise TypeError(f"Cannot recognize type from schema {schema!r}")
return _schema_to_column(name, {**schema_any_of[0], **schema}, defs)
else:
return _schema_to_column(name, {**schema_any_of[0], **schema}, defs)
else:
raise TypeError(f"Cannot recognize type from schema {schema!r}")

Expand Down

0 comments on commit 6b9e78b

Please sign in to comment.