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 LDP resource graphs, indicated in the key by
  19. their UID, and their cryptographic hashes.
  20. """
  21. def get_checksum(self, uri):
  22. """
  23. Get the checksum of a resource.
  24. :param str uri: Resource URI (``info:fcres...``).
  25. :rtype: bytes
  26. """
  27. with self.txn_ctx():
  28. return self.get_data(uri.encode(), 'checksums')
  29. def update_checksum(self, uri, cksum):
  30. """
  31. Update the stored checksum of a resource.
  32. :param str uri: Resource URI (``info:fcres...``).
  33. :param bytes cksum: Checksum bytestring.
  34. """
  35. with self.txn_ctx(True):
  36. self.put(uri.encode(), cksum, 'checksums')
  37. def delete_checksum(self, uri):
  38. """
  39. Delete the stored checksum of a resource.
  40. :param str uri: Resource URI (``info:fcres...``).
  41. """
  42. with self.txn_ctx(True):
  43. self.delete(uri.encode(), 'checksums')