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 |
|
BenchmarkFields |
|
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
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 205 206 207 208 209 210 211 212 213 214 215 216 | |
__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
Source code in sc_crawler/table_bases.py
ServerFields
#
Bases: HasDisplayName, HasApiReference, HasName, HasServerIdPK, HasVendorPKFK
Source code in sc_crawler/table_bases.py
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 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
BenchmarkFields
#
Bases: HasBenchmarkIdPK
Source code in sc_crawler/table_bases.py
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
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
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |
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).