Switch to UUID for sqlite db

This commit is contained in:
Andrew Mulbrook 2026-03-24 21:22:24 -05:00
parent 90b72ed678
commit 82c272990c
3 changed files with 59 additions and 55 deletions

View file

@ -9,6 +9,9 @@ only the data field — storage is the caller's concern.
import json
from .trove import ObjectId
class Tree:
def __init__(self, data: bytes | None = None):
"""
@ -16,7 +19,7 @@ class Tree:
An empty Tree is created if data is None.
"""
if not data:
self._entries: dict[str, int] = {}
self._entries: dict[str, ObjectId] = {}
else:
self._entries = json.loads(data.decode("utf-8"))
@ -24,11 +27,11 @@ class Tree:
"""Serialize the tree to UTF-8 JSON bytes."""
return json.dumps(self._entries).encode("utf-8")
def set_entry(self, name: str, object_id: int) -> None:
def set_entry(self, name: str, object_id: ObjectId) -> None:
"""Add or update an entry mapping name -> uuid."""
self._entries[name] = object_id
def get_entry(self, name: str) -> int:
def get_entry(self, name: str) -> ObjectId:
"""Get the uuid associated with a name, or raise KeyError if not found."""
return self._entries[name]
@ -36,6 +39,6 @@ class Tree:
"""Remove an entry by name. Raises KeyError if not found."""
del self._entries[name]
def list(self) -> dict[str, int]:
def list(self) -> dict[str, ObjectId]:
"""Return a shallow copy of all entries as {name: uuid}."""
return dict(self._entries)