impl#

acore_df.code_gen.impl.to_class_name(s: str) str[source]#

Convert snake case to camel case.

Example:

>>> to_class_name("item_template_class")
"ItemTemplateClass"
class acore_df.code_gen.impl.Dataset(tab: str, include: ~typing.Optional[~typing.List[str]] = None, exclude: ~typing.Optional[~typing.List[str]] = None, mapping: ~typing.Dict[str, str] = <factory>, id_col: str = 'id')[source]#

Define how you want to extract dataset from excel file.

Parameters:
  • tab – sheet name in excel file.

  • include – list of column names to include. You can either specify include or exclude, but not both.

  • exclude – list of column names to exclude. You can either specify include or exclude, but not both.

  • mapping – map excel column name to ORM class attribute name

  • id_col – column name that is the primary key. 注意, 这个 id 是 mapping 之后的 id (如果有的话).

property class_name: str#

Convert snake case to camel case.

Example:

>>> to_class_name("item_template_class")
"ItemTemplateClass"
class acore_df.code_gen.impl.TypeSpec(pl_type: Any, sa_type: Any, dc_type: Any)[source]#

Map from polars type to sqlalchemy type and dataclasses type.

Parameters:
  • pl_type – Polars type

  • sa_type – Sqlalchemy type

  • dc_type – dataclasses type

class acore_df.code_gen.impl.DatasetMetadata(dataset: Dataset, df: DataFrame, schema: Dict[str, TypeSpec], orm_class: Type[Base], id_col_type_spec: TypeSpec)[source]#

Container for dataset metadata.

Parameters:
  • datasetDataset

  • dfpolars.DataFrame

  • schema – T.Dict[str, :class`TypeSpec`]

  • orm_class – sqlachemy ORM class

acore_df.code_gen.impl.load_dataset(path_xlsx: Path, dataset: Dataset) DatasetMetadata[source]#

Load dataset dataframe from excel file, extract type spec, and generate ORM class definition,

acore_df.code_gen.impl.generate_code(path_xlsx: Path, dataset_list: List[Dataset], path_sqlite: Path = PosixPath('/home/docs/acore_df.sqlite'), path_model_py: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/acore-df/envs/stable/lib/python3.10/site-packages/acore_df/model.py'))[source]#

Generate the model.py module for lookup table.

Parameters:
  • path_xlsx – path to the excel file, this is the source of truth.

  • dataset_list – list of Dataset, define how you want to load data from excel file.

  • path_sqlite – path to the sqlite database file. excel data will be stored in this database.

  • path_model_py – path to the generated ORM class definition file.