moobius.database.storage#
Module-level functions#
get_engine#
**get_engine**(implementation)
__implementation:__ N implementation string.
The engine’s Class.
Last-minute-imports the module so that no pip package is needed for unused engines.
(this function does not raise any notable errors)
Class CachedDict#
CachedDict is a custom dictionary-like class that inherits from the built-in dict class. The MagicalStorage class manages the creation of CachedDict instances with different attribute names, allowing users to cache and retrieve data in a structured way, with optional database interaction.
CachedDict.load#
Loads all keys from the database to the cache.
**CachedDict.load**(self)
__(this class constructor accepts no arguments):__
None.
(this function does not raise any notable errors)
CachedDict.save#
Saves a key to the database.. For a JSONDatabase, this will create a new json file named after the database’s domain and key.
**CachedDict.save**(self, key)
__key:__ String-valued key.
None.
(this function does not raise any notable errors)
CachedDict.pop#
Overrides “v = d.pop(k)” to get and delete k from the database..
**CachedDict.pop**(self, key, default)
__key:__ Key.
__default=’__unspecified__’:__ An optional default value.
The value.
(this function does not raise any notable errors)
CachedDict.clear#
Overrides “d.clear()” to clear the database.
**CachedDict.clear**(self)
__(this class constructor accepts no arguments):__
None.
(this function does not raise any notable errors)
Class attributes#
CachedDict.dict
Class MoobiusStorage#
MoobiusStorage combines multiple databases together. Each database becomes one attribute using dynamic attribute creation.
MoobiusStorage.put#
Sets self.attr_name to database (a DatabaseInterface object) for later retrieval. load (default True) to load the dict immediatly, clear (default False) to clear the dict and skip loading it.
**MoobiusStorage.put**(self, attr_name, database, load, clear)
__attr_name:__ The attr name to add dynamically to self, setting it to a CachedDict.
__database:__ The database.
__load=True:__ Whether to load the dict in full at startup instead of gradually.
__clear=False:__ Whether to clear the dict (which deletes the files).
None.
(this function does not raise any notable errors)
MoobiusStorage.add_container#
Adds a database using the config dict.
**MoobiusStorage.add_container**(self, implementation, settings, name, load, clear)
__implementation:__ The engine of the database.
__settings:__ Contains “root_dir” of the json files, for example.
__name:__ The attribute that will be added to self for later use.
__load=True:__ Whether to load the database when initializing the database.
__clear=False:__ Whether to clear the database when initializing the database.
None.
(this function does not raise any notable errors)