import hashlib from abc import ABCMeta, abstractmethod from contextlib import contextmanager from os import makedirs, path import lmdb from lakesuperior import env class BaseLmdbStore(metaclass=ABCMeta): """ Generic LMDB store abstract class. This class contains convenience method to create an LMDB store for any purpose and provides some convenience methods to wrap cursors and transactions into contexts. This interface can be subclassed for specific storage back ends. It is *not* used for :py:class:`~lakesuperior.store.ldp_rs.lmdb_store.LmdbStore` which has a more complex lifecycle and setup. Example usage:: >>> class MyStore(BaseLmdbStore): ... path = '/base/store/path' ... db_labels = ('db1', 'db2') ... >>> ms = MyStore() >>> # "with" wraps the operation in a transaction. >>> with ms.cur(index='db1', write=True): ... cur.put(b'key1', b'val1') True """ path = None """ Filesystem path where the database environment is stored. This is a mandatory value for implementations. :rtype: str """ db_labels = None """ List of databases in the DB environment by label. If the environment has only one database, do not override this value (i.e. leave it to ``None``). :rtype: tuple(str) """ options = {} """ LMDB environment option overrides. Setting this is not required. See `LMDB documentation