mafw.db.db_wizard
The module allows to generate a DB model structure starting from an existing DB.
It is strongly based on the peewee playhouse module pwiz.
Functions
|
Dumps all the ORM models in the output file. |
Classes
|
Placeholder class for an Unknown Field. |
- class mafw.db.db_wizard.UnknownField(*_: Any, **__: Any)[source]
Bases:
objectPlaceholder class for an Unknown Field.
- mafw.db.db_wizard.dump_models(output_file: TextIO, introspector: Introspector, tables: list[str] | tuple[str, ...] | None = None, preserve_order: bool = True, include_views: bool = False, ignore_unknown: bool = False, snake_case: bool = True) None[source]
Dumps all the ORM models in the output file.
This function will write to the output stream a fully functional python module with all the models that the introspector class can access. The user has the possibility to pre-select a subset of tables to be dumped and also to optionally include views.
See also
This function is the core of the db wizard.
- Parameters:
output_file (TextIO) – The output file. It must be open in text/write mode.
introspector (Introspector) – A database introspector from the reflection module.
tables (list | None, Optional) – A list of table names to be dumped. If None, then all tables in the DB will be dumped. Defaults to None.
preserve_order (bool, Optional) – Preserve the order of the columns in the model. Defaults to True.
include_views (bool, Optional) – Include saved views to be dumped. Views can be obtained joining tables. Defaults to False.
ignore_unknown (bool, Optional) – Ignore unknown fields. If True, then an UnknownField type will be used as a placeholder. Defaults to False.
snake_case (bool, Optional) – Use snake case for column and table name. Defaults to True.