Improve performance and add type hints
This commit is contained in:
parent
1782db4840
commit
b7e10e766e
23 changed files with 745 additions and 178 deletions
|
|
@ -7,6 +7,7 @@ from compression import zstd
|
|||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Protocol
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
|
@ -19,6 +20,15 @@ if TYPE_CHECKING:
|
|||
from argparse import ArgumentParser
|
||||
|
||||
|
||||
class SupportsStr(Protocol):
|
||||
"""Protocol for values that provide a string representation."""
|
||||
|
||||
def __str__(self) -> str: ...
|
||||
|
||||
|
||||
type SqlSerializable = bool | int | float | bytes | SupportsStr | None
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""Create a compressed SQL dump of the Twitch and Kick dataset tables."""
|
||||
|
||||
|
|
@ -285,7 +295,7 @@ def _write_postgres_dump(output_path: Path, tables: list[str]) -> None:
|
|||
raise CommandError(msg)
|
||||
|
||||
|
||||
def _sql_literal(value: object) -> str:
|
||||
def _sql_literal(value: SqlSerializable) -> str:
|
||||
"""Convert a Python value to a SQL literal.
|
||||
|
||||
Args:
|
||||
|
|
@ -305,7 +315,7 @@ def _sql_literal(value: object) -> str:
|
|||
return "'" + str(value).replace("'", "''") + "'"
|
||||
|
||||
|
||||
def _json_default(value: object) -> str:
|
||||
def _json_default(value: bytes | SupportsStr) -> str:
|
||||
"""Convert non-serializable values to JSON-compatible strings.
|
||||
|
||||
Args:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue