panoptes.utils.database package¶
Submodules¶
panoptes.utils.database.base module¶
- class panoptes.utils.database.base.AbstractPanDB(db_name=None, **kwargs)[source]¶
Bases:
object
- abstract 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.
- abstract 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.
- abstract 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:
object
Simple 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:
AbstractPanDB
Stores 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.
- 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.
- 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:
panoptes.utils.database.memory module¶
- class panoptes.utils.database.memory.PanMemoryDB(**kwargs)[source]¶
Bases:
AbstractPanDB
In-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 the current record of a certain type
- Parameters:
type (str) – The type of entry in the current collection that should be cleared.
- 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.
- 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.
- 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: