mentat.services.sqlstorage module

Database storage abstraction layer. The current implementation is based on the awesome SQLAlchemy library.

Warning

Current implementation is for optimalization purposes using some advanced schema features provided by the PostgreSQL database and thus no other engines are currently supported.

class mentat.services.sqlstorage.StorageService(**enginecfg)[source]

Bases: object

Proxy object for working with persistent SQL storages. Maintains and provides access to database engine, session maker and session proxies.

close()[source]

Close current database connection.

database_create()[source]

Create database SQL schema.

database_drop()[source]

Drop database SQL schema.

session_new()[source]

Create new database session.

class mentat.services.sqlstorage.StorageServiceManager(core_config, updates=None)[source]

Bases: object

Class representing a custom _StorageServiceManager_ capable of understanding and parsing Mentat system core configurations and enabling easy access to preconfigured database collections via indirrect handles (identifiers).

close()[source]

Close internal storage connection.

service()[source]

Return handle to storage connection service according to internal configurations.

Returns

Reference to storage service.

Return type

mentat.services.sqlstorage.StorageService

mentat.services.sqlstorage.close()[source]

Close database connection on mentat.services.sqlstorage.StorageService instance from module level manager.

mentat.services.sqlstorage.init(core_config, updates=None)[source]

(Re-)Initialize mentat.services.sqlstorage.StorageServiceManager instance at module level and store the refence within module.

Parameters
  • core_config (dict) – Mentat core configuration structure.

  • updates (dict) – Optional configuration updates (same structure as core_config).

mentat.services.sqlstorage.manager()[source]

Obtain reference to mentat.services.sqlstorage.StorageServiceManager instance stored at module level.

Returns

Storage service manager reference.

Return type

mentat.services.sqlstorage.StorageServiceManager

mentat.services.sqlstorage.service()[source]

Obtain reference to mentat.services.sqlstorage.StorageService instance from module level manager.

Returns

Storage service reference.

Return type

mentat.services.sqlstorage.StorageServiceManager

mentat.services.sqlstorage.set_manager(manager)[source]

Set manager from outside of the module. This should be used only when you know exactly what you are doing.