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 |
|
DatabaseBenchmarkScoreFields |
|
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
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 217 218 219 | |
__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
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 862 863 864 865 866 867 868 869 870 871 872 | |
BenchmarkFields
#
Bases: HasBenchmarkIdPK
Source code in sc_crawler/table_bases.py
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | |
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
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 | |
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).
Source code in sc_crawler/table_bases.py
DatabaseBenchmarkScoreFields
#
Bases: HasBenchmarkPKFK, HasDatabasePK, 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
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | |
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).