sc_crawler.table_bases
Tiny helper classes for the most commonly used fields to be inherited by sc_crawler.tables.
Classes:
- ScMetaModel – Custom class factory to auto-update table models.
- ScModel – Custom extensions to SQLModel objects and tables.
- MetaColumns – Helper class to add the
statusandobserved_atcolumns. - HasPriceFieldsBase –
- ServerFields –
- BenchmarkFields –
- ResourceIdComparator – Compile server_id/database_id to CASE + typed filter.
- BenchmarkScoreFields –
class ScMetaModel
Bases: __class__
Custom class factory to auto-update table models.
-
Reuse description of the table and its fields as SQL comment.
Checking if the table and its fields have explicit comment set to be shown in the
CREATE TABLEstatements, and if not, reuse the optional table and field descriptions. Table docstrings are truncated to first line. -
Reuse description of the fields to dynamically append to the docstring in the Attributes section.
-
Set
__validator__to the parent Pydantic model withouttable=True, which is useful for running validations. The Pydantic model is found by the parent class' name ending in "Base". -
Auto-generate SCD table docs from the non-SCD table docs.
class ScModel
Bases: SQLModel
Custom extensions to SQLModel objects and tables.
Extra features:
- auto-generated table names using snake_case,
- support for hashing table rows,
- reuse description field of tables/columns as SQL comment,
- reuse description field of columns to extend the
Attributessection of the docstring.
Functions:
- get_columns – Return the table's column names in a dict for all, primary keys, and attributes.
- get_table_name – Return the SQLModel object's table name.
- get_validator – Return the parent Base Pydantic model (without a table definition).
- get_scd – Return the SCD version of the SQLModel table.
- hash – Hash the content of the rows.
meth ScModel.get_columns
ScModel.get_columnsget_columns()
Return the table's column names in a dict for all, primary keys, and attributes.
meth ScModel.get_table_name
ScModel.get_table_nameget_table_name()
Return the SQLModel object's table name.
meth ScModel.get_validator
ScModel.get_validatorget_validator()
Return the parent Base Pydantic model (without a table definition).
meth ScModel.get_scd
ScModel.get_scdget_scd()
Return the SCD version of the SQLModel table.
meth ScModel.hash
ScModel.hashhash(session, ignored=['observed_at'], progress=None)
Hash the content of the rows.
Parameters:
- session (
Session) – Database connection to use for object lookups. - ignored (
List[str]) – List of column names to exclude from hashing. - progress (
Optional[Progress]) – Optional progress bar to track the status of the hashing.
Returns:
dict– Dictionary of the row hashes keyed by the JSON dump of primary keys.
class MetaColumns
Bases: ScModel
Helper class to add the status and observed_at columns.
class HasPriceFieldsBase
Bases: ScModel
class ServerFields
Bases: HasDisplayName, HasApiReference, HasName, HasServerIdPK, HasVendorPKFK
class BenchmarkFields
Bases: HasBenchmarkIdPK
class ResourceIdComparator
Bases: Comparator
Compile server_id/database_id to CASE + typed filter.
class BenchmarkScoreFields
Bases: HasBenchmarkPKFK, HasVendorPKFK
Functions:
- update_config_to_hashable – Accept
server_id/database_idkeys; hashably sort config.
meth BenchmarkScoreFields.update_config_to_hashable
BenchmarkScoreFields.update_config_to_hashableupdate_config_to_hashable(values)
Accept server_id / database_id keys; hashably sort config.