panoptes.utils.database package¶
Submodules¶
panoptes.utils.database.base module¶
- class panoptes.utils.database.base.AbstractPanDB(db_name=None, **kwargs)[source]¶
Bases:
objectAbstract base class for PANOPTES database implementations.
This class defines the interface that all database implementations must follow for storing and retrieving observational data.
- abstractmethod clear_current(type)[source]¶
Clear the current record of a certain type
- Parameters:
type (str) – The type of entry in the current collection that should be cleared.
- abstractmethod get_current(collection)[source]¶
Returns the most current record for the given collection
- abstractmethod insert(collection, obj)[source]¶
Insert an object into the collection provided.
The obj to be stored in a collection should include the type and date metadata as well as a data key that contains the actual object data. If these keys are not provided then obj will be wrapped in a corresponding object that does contain the metadata.
- abstractmethod insert_current(collection, obj, store_permanently=True)[source]¶
Insert an object into both the current collection and the collection provided.
- Parameters:
- Returns:
- identifier of inserted record. If store_permanently is True, will
be the identifier of the object in the collection, otherwise will be the identifier of object in the current collection. These may or may not be the same. Returns None if unable to insert into the collection.
- Return type:
- class panoptes.utils.database.base.PanDB(db_type='memory', db_name=None, *args, **kwargs)[source]¶
Bases:
objectSimple class to load the appropriate DB type based on the config.
We don’t actually create instances of this class, but instead create an instance of the ‘correct’ type of db.
- panoptes.utils.database.base.create_storage_obj(collection, data, obj_id)[source]¶
Wrap the data in a dict along with the id and a timestamp.
- panoptes.utils.database.base.get_db_class(module_name='file')[source]¶
Load the main DB class for the module of the given name.
Note
This is used by the PanDB constructor to determine the correct database type. Normal DB instantiation should be done via the PanDB() class with the desired db_type parameter set. See example in PanDB below.
panoptes.utils.database.file module¶
- class panoptes.utils.database.file.PanFileDB(db_name='panoptes', storage_dir='json_store', **kwargs)[source]¶
Bases:
AbstractPanDBStores collections as files of JSON records.
- clear_current(record_type)[source]¶
Clears the current record of the given type.
- Parameters:
record_type (str) – The record type, e.g. ‘weather’, ‘environment’, etc.
panoptes.utils.database.memory module¶
- class panoptes.utils.database.memory.PanMemoryDB(**kwargs)[source]¶
Bases:
AbstractPanDBIn-memory store of serialized objects.
We serialize the objects in order to test the same code path used when storing in an external database.
- active_dbs = <WeakValueDictionary>¶
- clear_current(entry_type)[source]¶
Clear current entry for specified type.
- Parameters:
entry_type (str) – Entry type to clear.
- classmethod get_or_create(db_name=None, **kwargs)[source]¶
Returns the named db, creating if needed.
This method exists because PanDB gets called multiple times for the same database name. With mongo or a file store where the storage is external from the instance, that is not a problem, but with PanMemoryDB the instance is the store, so the instance must be shared.