metadata_store.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from os import path
  2. from lakesuperior.store.base_lmdb_store import BaseLmdbStore
  3. from lakesuperior import env
  4. class MetadataStore(BaseLmdbStore):
  5. """
  6. LMDB store for RDF metadata.
  7. Note that even though this store connector uses LMDB as the
  8. :py::class:`LmdbStore` class, it is separate because it is not part of the
  9. RDFLib store implementation and carries higher-level concepts such as LDP
  10. resource URIs.
  11. """
  12. dbi_labels = [
  13. 'checksums',
  14. 'event_queue'
  15. ]
  16. """
  17. Currently implemented:
  18. - ``checksums``: registry of
  19. LDP resource graphs, indicated in the key by their UID, and their
  20. cryptographic hashes.
  21. """
  22. def get_checksum(self, uri):
  23. """
  24. Get the checksum of a resource.
  25. :param str uri: Resource URI (``info:fcres...``).
  26. :rtype: bytes
  27. """
  28. with self.txn_ctx():
  29. return self.get_data(uri.encode(), 'checksums')
  30. def update_checksum(self, uri, cksum):
  31. """
  32. Update the stored checksum of a resource.
  33. :param str uri: Resource URI (``info:fcres...``).
  34. :param bytes cksum: Checksum bytestring.
  35. """
  36. with self.txn_ctx(True):
  37. self.put(uri.encode(), cksum, 'checksums')
  38. def delete_checksum(self, uri):
  39. """
  40. Delete the stored checksum of a resource.
  41. :param str uri: Resource URI (``info:fcres...``).
  42. """
  43. with self.txn_ctx(True):
  44. self.delete(uri.encode(), 'checksums')