table_bases
sc_crawler.table_bases
#
Tiny helper classes for the most commonly used fields to be inherited by sc_crawler.tables.
Classes:
| Name | Description |
|---|---|
ScMetaModel |
Custom class factory to auto-update table models. |
ScModel |
Custom extensions to SQLModel objects and tables. |
MetaColumns |
Helper class to add the |
HasPriceFieldsBase |
|
ServerFields |
|
BenchmarkScoreFields |
|
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.
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
Attributessection of the docstring.
Methods:
| Name | Description |
|---|---|
__tablename__ |
Override tables names using all-lowercase snake_case. |
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. |
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
HasPriceFieldsBase
#
Bases: ScModel
Methods:
| Name | Description |
|---|---|
serialize_price_tiers |
Serialize price_tiered field, converting dicts to PriceTier instances first. |
Source code in sc_crawler/table_bases.py
serialize_price_tiers
classmethod
#
Serialize price_tiered field, converting dicts to PriceTier instances first.
Source code in sc_crawler/table_bases.py
ServerFields
#
Bases: HasDescription, HasDisplayName, HasApiReference, HasName, HasServerIdPK, HasVendorPKFK
Methods:
| Name | Description |
|---|---|
serialize_cpus |
Serialize cpus field, converting dicts to Cpu instances first. |
serialize_gpus |
Serialize gpus field, converting dicts to Gpu instances first. |
serialize_storages |
Serialize storages field, converting dicts to Disk instances first. |
Source code in sc_crawler/table_bases.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
serialize_cpus
classmethod
#
Serialize cpus field, converting dicts to Cpu instances first.
Source code in sc_crawler/table_bases.py
serialize_gpus
classmethod
#
Serialize gpus field, converting dicts to Gpu instances first.
Source code in sc_crawler/table_bases.py
serialize_storages
classmethod
#
Serialize storages field, converting dicts to Disk instances first.
Source code in sc_crawler/table_bases.py
BenchmarkScoreFields
#
Bases: HasBenchmarkPKFK, HasServerPK, HasVendorPKFK
Methods:
| Name | Description |
|---|---|
update_config_to_hashable |
We need a hashable column for the primary key. |
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).