Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/model.py
Show All 20 Lines | |||||
import dataclasses | import dataclasses | ||||
import datetime | import datetime | ||||
from typing import Any, ClassVar, Dict, List, Optional, Tuple, Type, TypeVar | from typing import Any, ClassVar, Dict, List, Optional, Tuple, Type, TypeVar | ||||
from swh.model.model import Person, TimestampWithTimezone | from swh.model.model import Person, TimestampWithTimezone | ||||
MAGIC_NULL_PK = b"<null>" | |||||
""" | |||||
NULLs (or all-empty blobs) are not allowed in primary keys; instead we use a | |||||
special value that can't possibly be a valid hash. | |||||
""" | |||||
T = TypeVar("T", bound="BaseRow") | T = TypeVar("T", bound="BaseRow") | ||||
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, ...]] = () | ||||
Show All 33 Lines | class SkippedContentRow(BaseRow): | ||||
sha256: Optional[bytes] | sha256: Optional[bytes] | ||||
blake2s256: Optional[bytes] | blake2s256: Optional[bytes] | ||||
length: Optional[int] | length: Optional[int] | ||||
ctime: Optional[datetime.datetime] | ctime: Optional[datetime.datetime] | ||||
status: str | status: str | ||||
reason: str | reason: str | ||||
origin: str | origin: str | ||||
@classmethod | |||||
def from_dict(cls, d: Dict[str, Any]) -> "SkippedContentRow": | |||||
d = d.copy() | |||||
for k in ("sha1", "sha1_git", "sha256", "blake2s256"): | |||||
if d[k] == MAGIC_NULL_PK: | |||||
d[k] = None | |||||
return super().from_dict(d) | |||||
@dataclasses.dataclass | @dataclasses.dataclass | ||||
class DirectoryRow(BaseRow): | class DirectoryRow(BaseRow): | ||||
TABLE = "directory" | TABLE = "directory" | ||||
PARTITION_KEY = ("id",) | PARTITION_KEY = ("id",) | ||||
id: bytes | id: bytes | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |