moobius.database.storage#

Module-level functions#

get_engine#

Signature:

  • **get_engine**(implementation)

Parameters:

  • __implementation:__ N implementation string.

Returns:

  • The engine’s Class.

Last-minute-imports the module so that no pip package is needed for unused engines.

Raises:

  • (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.

Signature:

  • **CachedDict.load**(self)

Parameters:

  • __(this class constructor accepts no arguments):__

Returns:

  • None.

Raises:

  • (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.

Signature:

  • **CachedDict.save**(self, key)

Parameters:

  • __key:__ String-valued key.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

CachedDict.pop#

Overrides “v = d.pop(k)” to get and delete k from the database..

Signature:

  • **CachedDict.pop**(self, key, default)

Parameters:

  • __key:__ Key.

  • __default=’__unspecified__’:__ An optional default value.

Returns:

  • The value.

Raises:

  • (this function does not raise any notable errors)

CachedDict.clear#

Overrides “d.clear()” to clear the database.

Signature:

  • **CachedDict.clear**(self)

Parameters:

  • __(this class constructor accepts no arguments):__

Returns:

  • None.

Raises:

  • (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.

Signature:

  • **MoobiusStorage.put**(self, attr_name, database, load, clear)

Parameters:

  • __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).

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

MoobiusStorage.add_container#

Adds a database using the config dict.

Signature:

  • **MoobiusStorage.add_container**(self, implementation, settings, name, load, clear)

Parameters:

  • __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.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

Example:

Note: This is a hidden function, you don't need to call it directly. >>> storage = MoobiusStorage(service_id='1', channel_id='1') >>> storage.add_container(implementation='json', settings={'root_dir': 'data'}, name='character', load=True, clear=False)

Class attributes#

Internals#