db

Deprecated since version 0.15.0: The mautrix.util.async_db utility is now recommended over SQLAlchemy.

class mautrix.util.db.Base

Bases: mautrix.util.db.base.Base

Deprecated since version 0.15.0: The mautrix.util.async_db utility is now recommended over SQLAlchemy.

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

metadata = MetaData()
registry = <sqlalchemy.orm.decl_api.registry object>
class mautrix.util.db.BaseClass

Bases: object

Base class for SQLAlchemy models. Provides SQLAlchemy declarative base features and some additional utilities.

Deprecated since version 0.15.0: The mautrix.util.async_db utility is now recommended over SQLAlchemy.

classmethod bind(db_engine)
Parameters

db_engine (sqlalchemy.engine.base.Engine) –

Return type

None

classmethod copy(bind=None, rebase=None)
Parameters
  • bind (Optional[sqlalchemy.engine.base.Engine]) –

  • rebase (Optional[sqlalchemy.ext.declarative.declarative_base]) –

Return type

Type[mautrix.util.db.base.T]

delete()

Delete this row.

Parameters

self (mautrix.util.db.base.T) –

Return type

None

edit(*, _update_values=True, **values)

Edit this row.

Parameters
  • _update_values (bool) – Whether or not the values in memory should be updated as well as the values in the database.

  • **values – The values to change.

  • self (mautrix.util.db.base.T) –

Return type

None

edit_mode()

Edit this row in a fancy context manager way. This stores the current edit identity, then yields to the context manager and finally puts the new values into the row using the old edit identity in the WHERE clause.

>>> class TableClass(Base):
...     ...
>>> db_instance = TableClass(id="something")
>>> with db_instance.edit_mode():
...     db_instance.id = "new_id"
Parameters

self (mautrix.util.db.base.T) –

Return type

None

insert()
Return type

None

classmethod scan(row)

Read the data from a row into an object.

Parameters

row (RowProxy) – The RowProxy object.

Returns

An object containing the information in the row.

Return type

mautrix.util.db.base.T

upsert()
Parameters

self (mautrix.util.db.base.T) –

Return type

None

db: sqlalchemy.engine.base.Engine
t: sqlalchemy.sql.schema.Table
c: sqlalchemy.sql.base.ImmutableColumnCollection
column_names: List[str]