MambuPy.orm.schema_orm

SQLAlchemy ORM for a Mambu Database backup.

This is the basic module that holds a default session (and a default Session maker and a connected engine) which is used on every ORM module on MambuPy.

The default engine is connected to a database according to what you configured on mambuconfig module.

This module also holds the Base declarative_base used for every ORM on MambuPy.

Every ORM module on MambuPy (named schema_*.py) should ideally get the default session, Base and etc. from here, allowing the user to use the same session and etc. for the day-to-day work. If you chose to use another session, please mind that you should replace the session on every schema_*.py you need.

This last requirement also applies for the Base, or for the engine and the sessionmaker for that matter.

Module Attributes

engine

Database engine, connecting with default parameters by default.

session_factory

Sessionmaker object, create factory sessions.

Session

Scoped session object.

session

Default session created here.

Base(**kwargs)

The base class of the class hierarchy.

Functions

connect_db([engine, user, password, host, ...])

Connect to database utility function.

class MambuPy.orm.schema_orm.Base(**kwargs)

Bases: object

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.

__dict__ = mappingproxy({'_decl_class_registry': <WeakValueDictionary>, 'metadata': MetaData(bind=None), '__doc__': 'The base class of the class hierarchy.\n\nWhen called, it accepts no arguments and returns a new featureless\ninstance that has no instance attributes and cannot be given any.\n', '__init__': <function _declarative_constructor>, '__module__': 'sqlalchemy.ext.declarative.api', '__dict__': <attribute '__dict__' of 'Base' objects>, '__weakref__': <attribute '__weakref__' of 'Base' objects>, '__annotations__': {}})
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

__module__ = 'sqlalchemy.ext.declarative.api'
__weakref__

list of weak references to the object (if defined)

_decl_class_registry = <WeakValueDictionary>
metadata = MetaData(bind=None)
MambuPy.orm.schema_orm.Session = <sqlalchemy.orm.scoping.scoped_session object>

Scoped session object.

MambuPy.orm.schema_orm.connect_db(engine='mysql', user='mambu_db_user', password='mambu_db_pwd', host='localhost', port='3306', database='mambu_db', params='?charset=utf8&use_unicode=1', echoopt=False)[source]

Connect to database utility function.

Uses SQLAlchemy ORM library.

Useful when using schema modules in MambuPy

MambuPy.orm.schema_orm.engine = Engine(mysql://mambu_db_user:***@localhost:3306/mambu_db?charset=utf8&use_unicode=1)

Database engine, connecting with default parameters by default.

MambuPy.orm.schema_orm.session = <sqlalchemy.orm.session.Session object>

Default session created here.

MambuPy.orm.schema_orm.session_factory = sessionmaker(class_='Session', bind=Engine(mysql://mambu_db_user:***@localhost:3306/mambu_db?charset=utf8&use_unicode=1), autoflush=True, autocommit=False, expire_on_commit=True)

Sessionmaker object, create factory sessions.