table_bases
sc_crawler.table_bases
#
Tiny helper classes for the most commonly used fields to be inherited by sc_crawler.tables.
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 TABLE
statements, 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.
Source code in sc_crawler/table_bases.py
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
Attributes
section of the docstring.
Source code in sc_crawler/table_bases.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
__tablename__
#
Override tables names using all-lowercase snake_case.
get_columns
classmethod
#
Return the table's column names in a dict for all, primary keys, and attributes.
Source code in sc_crawler/table_bases.py
get_table_name
classmethod
#
get_validator
classmethod
#
Return the parent Base Pydantic model (without a table definition).
get_scd
classmethod
#
Return the SCD version of the SQLModel table.
Source code in sc_crawler/table_bases.py
hash
classmethod
#
Hash the content of the rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
Session
|
Database connection to use for object lookups. |
required |
ignored |
List[str]
|
List of column names to exclude from hashing. |
['observed_at']
|
progress |
Optional[Progress]
|
Optional progress bar to track the status of the hashing. |
None
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary of the row hashes keyed by the JSON dump of primary keys. |
Source code in sc_crawler/table_bases.py
MetaColumns
#
Bases: ScModel
Helper class to add the status
and observed_at
columns.
Source code in sc_crawler/table_bases.py
BenchmarkScoreFields
#
Bases: HasBenchmarkPKFK
, HasServerPK
, HasVendorPKFK
Source code in sc_crawler/table_bases.py
update_config_to_hashable
#
We need a hashable column for the primary key.
Note that we also sort the keys, so that the resulting JSON can be compared as text as well (as some database engines do).