From aa556399208aa8a3bef0a7d6436b2dc05058994e Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Mon, 30 Oct 2023 13:42:06 +0100 Subject: [PATCH] database:column - allow to ignore field in database --- acacore/database/column.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/acacore/database/column.py b/acacore/database/column.py index f22aea8..3cfbf62 100644 --- a/acacore/database/column.py +++ b/acacore/database/column.py @@ -40,7 +40,10 @@ } -def _schema_to_column(name: str, schema: dict, defs: Optional[dict[str, dict]] = None) -> "Column": +def _schema_to_column(name: str, schema: dict, defs: Optional[dict[str, dict]] = None) -> Optional["Column"]: + if schema.get("ignore"): + return None + defs = defs or {} if schema.get("$ref"): schema.update(defs[schema.get("$ref", "").removeprefix("#/$defs/")]) @@ -86,7 +89,8 @@ def _schema_to_column(name: str, schema: dict, defs: Optional[dict[str, dict]] = def model_to_columns(model: Type[BaseModel]) -> list["Column"]: schema: dict = model.model_json_schema() - return [_schema_to_column(p, s, schema.get("$defs")) for p, s in schema["properties"].items()] + columns = [_schema_to_column(p, s, schema.get("$defs")) for p, s in schema["properties"].items()] + return [c for c in columns if c] class Column(Generic[T]):