Skip to content

Commit

Permalink
database:column - allow to ignore field in database
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Oct 30, 2023
1 parent 5065d2d commit aa55639
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions acacore/database/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")])
Expand Down Expand Up @@ -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]):
Expand Down

0 comments on commit aa55639

Please sign in to comment.