Archived
Add formatting and type checks
This commit is contained in:
1 parent
c0d82eaf26
commit
24747866bc
38 files changed
+800
-265
No files matched your search
@@ -4,10 +4,11 @@ import sqlite3
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from ..models import UpdateResult
|
||||
from .types import UpdateEventRow
|
||||
from .base import StoreConnectionMixin
|
||||
from .types import RecordRow, UpdateEventRow, record_row, update_event_row
|
||||
|
||||
|
||||
class RecordsEventsMixin:
|
||||
class RecordsEventsMixin(StoreConnectionMixin):
|
||||
def upsert(
|
||||
self,
|
||||
hostname: str,
|
||||
@@ -84,10 +85,10 @@ class RecordsEventsMixin:
|
||||
update_ipv6=update_ipv6,
|
||||
)
|
||||
|
||||
def list_records(self) -> list[dict[str, str | None]]:
|
||||
def list_records(self) -> list[RecordRow]:
|
||||
return self.list_records_page(limit=10_000, offset=0)
|
||||
|
||||
def list_records_page(self, limit: int = 100, offset: int = 0) -> list[dict[str, str | None]]:
|
||||
def list_records_page(self, limit: int = 100, offset: int = 0) -> list[RecordRow]:
|
||||
with self.connect() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
@@ -98,7 +99,7 @@ class RecordsEventsMixin:
|
||||
""",
|
||||
(limit, offset),
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
return [record_row(row) for row in rows]
|
||||
|
||||
def count_records(self) -> int:
|
||||
with self.connect() as conn:
|
||||
@@ -167,7 +168,7 @@ class RecordsEventsMixin:
|
||||
""",
|
||||
(limit, offset),
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
return [update_event_row(row) for row in rows]
|
||||
|
||||
def list_update_events_before(self, limit: int = 100, before: str | None = None) -> list[UpdateEventRow]:
|
||||
where_clause = "WHERE created_at < ?" if before else ""
|
||||
@@ -189,7 +190,7 @@ class RecordsEventsMixin:
|
||||
""",
|
||||
params,
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
return [update_event_row(row) for row in rows]
|
||||
|
||||
def count_update_events(self) -> int:
|
||||
with self.connect() as conn:
|
||||
@@ -228,7 +229,7 @@ def _merge_event_rows(
|
||||
limit: int,
|
||||
offset: int,
|
||||
) -> list[UpdateEventRow]:
|
||||
rows = [dict(row) for row in event_rows]
|
||||
rows.extend(dict(row) for row in rollup_rows)
|
||||
rows = [update_event_row(row) for row in event_rows]
|
||||
rows.extend(update_event_row(row) for row in rollup_rows)
|
||||
rows.sort(key=lambda row: str(row["created_at"]), reverse=True)
|
||||
return rows[offset : offset + limit]
|
||||
Reference in new issue
Block a user