Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/model.py
Show All 36 Lines | |||||||||||
class BaseRow: | class BaseRow: | ||||||||||
TABLE: ClassVar[str] | TABLE: ClassVar[str] | ||||||||||
PARTITION_KEY: ClassVar[Tuple[str, ...]] | PARTITION_KEY: ClassVar[Tuple[str, ...]] | ||||||||||
CLUSTERING_KEY: ClassVar[Tuple[str, ...]] = () | CLUSTERING_KEY: ClassVar[Tuple[str, ...]] = () | ||||||||||
@classmethod | @classmethod | ||||||||||
def from_dict(cls: Type[T], d: Dict[str, Any]) -> T: | def from_dict(cls: Type[T], d: Dict[str, Any]) -> T: | ||||||||||
return cls(**d) # type: ignore | return cls(**d) # type: ignore | ||||||||||
olasdUnsubmitted Not Done Inline Actions
olasd: | |||||||||||
@classmethod | @classmethod | ||||||||||
def cols(cls) -> List[str]: | def cols(cls) -> List[str]: | ||||||||||
return [field.name for field in dataclasses.fields(cls)] | return [field.name for field in dataclasses.fields(cls)] | ||||||||||
def to_dict(self) -> Dict[str, Any]: | def to_dict(self) -> Dict[str, Any]: | ||||||||||
return dataclasses.asdict(self) | return dataclasses.asdict(self) | ||||||||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | class OriginVisitStatusRow(BaseRow): | ||||||||||
origin: str | origin: str | ||||||||||
visit: int | visit: int | ||||||||||
date: datetime.datetime | date: datetime.datetime | ||||||||||
status: str | status: str | ||||||||||
metadata: str | metadata: str | ||||||||||
snapshot: bytes | snapshot: bytes | ||||||||||
@classmethod | |||||||||||
def from_dict(cls: Type[T], d: Dict[str, Any]) -> T: | |||||||||||
d = d.copy() | |||||||||||
d.pop("type", None) | |||||||||||
return cls(**d) # type: ignore | |||||||||||
@dataclasses.dataclass | @dataclasses.dataclass | ||||||||||
class OriginRow(BaseRow): | class OriginRow(BaseRow): | ||||||||||
TABLE = "origin" | TABLE = "origin" | ||||||||||
PARTITION_KEY = ("sha1",) | PARTITION_KEY = ("sha1",) | ||||||||||
sha1: bytes | sha1: bytes | ||||||||||
url: str | url: str | ||||||||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |