Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /pbylicki_rfhub2 /rfhub2 /db /model /base_class.py
| from collections import OrderedDict | |
| from sqlalchemy import Column | |
| from sqlalchemy.ext.declarative import declarative_base, declared_attr | |
| from typing import Dict, List | |
| from rfhub2.db.repository.ordering import OrderingItem | |
| class CustomBase(object): | |
| # Generate __tablename__ automatically | |
| def __tablename__(cls): | |
| return cls.__name__.lower() | |
| def column_mapping(cls): | |
| return {col.name: col for col in cls.columns()} | |
| def columns(cls): | |
| return cls.__table__._columns | |
| def default_ordering(cls) -> List[OrderingItem]: | |
| return [] | |
| def ordering_criteria( | |
| cls, items: List[OrderingItem], custom_columns: Dict[str, Column] = dict() | |
| ): | |
| def criterion(col: Column, ordering_item: OrderingItem) -> Column: | |
| return col if ordering_item.asc else col.desc() | |
| if not items: | |
| items = cls.default_ordering() | |
| mapping = {**cls.column_mapping(), **custom_columns} | |
| return OrderedDict( | |
| (item.field, criterion(mapping[item.field], item)) | |
| for item in items | |
| if item.field in mapping | |
| ).values() | |
| Base = declarative_base(cls=CustomBase) | |
Xet Storage Details
- Size:
- 1.26 kB
- Xet hash:
- 971d4f72d482965e1847d576c70f530d82a43db776320518a3947c5329eee929
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.