Add database and FUSE mapping

This commit is contained in:
Andrew Mulbrook 2026-03-16 22:45:27 -05:00
parent 96c9e62354
commit 2cfe32b333
5 changed files with 425 additions and 3 deletions

View file

@ -86,6 +86,13 @@ class Sqlite3Trove:
# CRUD operations
# ------------------------------------------------------------------
def get_object_type(self, object_id: int) -> str | None:
"""Return the type column for an object, or None if not found."""
row = self._con.execute(
"SELECT type FROM objects WHERE id = ?", (object_id,)
).fetchone()
return row["type"] if row else None
def read_object(self, object_id: int) -> bytes | None:
"""Return raw data for a blob object, or None if not found."""
row = self._con.execute(
@ -104,6 +111,14 @@ class Sqlite3Trove:
return None
return bytes(row["value"]) if row["value"] is not None else b""
def write_metadata(self, object_id: int, key: str, value: bytes) -> None:
"""Upsert a metadata row. db.py has no write_metadata, so we go direct."""
self._con.execute(
"INSERT OR REPLACE INTO metadata (id, key, value) VALUES (?, ?, ?)",
(object_id, key, value),
)
self._con.commit()
def _write_object(self, data: bytes, dtype: str, object_id: int | None = None) -> int:
"""
Insert or replace an object. Returns the id.
@ -117,6 +132,7 @@ class Sqlite3Trove:
(dtype, data, modified)
)
self._con.commit()
assert cur.lastrowid is not None
return cur.lastrowid
else:
self._con.execute(
@ -126,12 +142,16 @@ class Sqlite3Trove:
self._con.commit()
return object_id
def write_blob(self, data: bytes, existing_id: int | None = None) -> int:
def write_blob(self, data: bytes, object_id: int | None = None) -> int:
"""
Insert or replace a blob. Returns the id.
Pass existing_id to update an existing object.
Pass object_id to update an existing object.
"""
return self._write_object(data, "blob", existing_id)
return self._write_object(data, "blob", object_id)
def write_tree(self, data: bytes, object_id: int | None = None) -> int:
"""Write a tree-typed object. Returns the assigned id."""
return self._write_object(data, "tree", object_id)
def delete_object(self, object_id: int) -> bool:
"""