async_db

class mautrix.util.async_db.Database

Bases: abc.ABC

__init__(url, upgrade_table, db_args=None, log=None, owner_name=None, ignore_foreign_tables=True)
Parameters
Return type

None

abstract acquire()
Return type

AsyncContextManager[mautrix.util.async_db.LoggingConnection]

classmethod create(url, *, db_args=None, upgrade_table=None, log=None, owner_name=None, ignore_foreign_tables=True)
Parameters
Return type

mautrix.util.async_db.Database

async execute(query, *args, timeout=None)
Parameters
Return type

str | Cursor

async executemany(query, *args, timeout=None)
Parameters
Return type

str | Cursor

async fetch(query, *args, timeout=None)
Parameters
Return type

list[Record]

async fetchrow(query, *args, timeout=None)
Parameters
Return type

Record | None

async fetchval(query, *args, column=0, timeout=None)
Parameters
  • query (str) –

  • args (Any) –

  • column (int) –

  • timeout (Optional[float]) –

Return type

Any

override_pool(db)
Parameters

db (mautrix.util.async_db.Database) –

Return type

None

schemes: dict[str, Type[Database]] = {'cockroach': <class 'mautrix.util.async_db.PostgresDatabase'>, 'cockroachdb': <class 'mautrix.util.async_db.PostgresDatabase'>, 'postgres': <class 'mautrix.util.async_db.PostgresDatabase'>, 'postgresql': <class 'mautrix.util.async_db.PostgresDatabase'>, 'sqlite': <class 'mautrix.util.async_db.SQLiteDatabase'>, 'sqlite3': <class 'mautrix.util.async_db.SQLiteDatabase'>}
async start()
Return type

None

abstract async stop()
Return type

None

async table_exists(name)
Parameters

name (str) –

Return type

bool

log: TraceLogger
scheme: Scheme
url: URL
upgrade_table: UpgradeTable | None
owner_name: str | None
ignore_foreign_tables: bool
class mautrix.util.async_db.UpgradeTable

Bases: object

__init__(allow_unsupported=False, version_table_name='version', database_name='database', log=None)
Parameters
Return type

None

register(_outer_fn=None, *, index=- 1, description='', transaction=True, upgrades_to=None)
Parameters
  • _outer_fn (Optional[Union[Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]], Callable[[mautrix.util.async_db.LoggingConnection], Awaitable[Optional[int]]]]]) –

  • index (int) –

  • description (str) –

  • transaction (bool) –

  • upgrades_to (Optional[Union[int, Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]]]]) –

Return type

Union[Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]], Callable[[Union[Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]], Callable[[mautrix.util.async_db.LoggingConnection], Awaitable[Optional[int]]]]], Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]]]]

async upgrade(db)
Parameters

db (mautrix.util.async_db.Database) –

Return type

None

upgrades: list[Upgrade]
allow_unsupported: bool
database_name: str
version_table_name: str
log: TraceLogger
mautrix.util.async_db.register_upgrade(index=- 1, description='')
Parameters
  • index (int) –

  • description (str) –

Return type

Callable[[Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]]], Callable[[mautrix.util.async_db.LoggingConnection, mautrix.util.async_db.Scheme], Awaitable[Optional[int]]]]

class mautrix.util.async_db.PostgresDatabase

Bases: mautrix.util.async_db.Database

__init__(url, upgrade_table, db_args=None, log=None, owner_name=None, ignore_foreign_tables=True)
Parameters
Return type

None

acquire()
Return type

mautrix.util.async_db.LoggingConnection

override_pool(db)
Parameters

db (mautrix.util.async_db.PostgresDatabase) –

Return type

None

property pool: asyncpg.pool.Pool
scheme = 'postgres'
async start()
Return type

None

async stop()
Return type

None

class mautrix.util.async_db.SQLiteDatabase

Bases: mautrix.util.async_db.Database

__init__(url, upgrade_table, db_args=None, log=None, owner_name=None, ignore_foreign_tables=True)
Parameters
Return type

None

acquire()
Return type

AsyncContextManager[mautrix.util.async_db.LoggingConnection]

override_pool(db)
Parameters

db (mautrix.util.async_db.Database) –

Return type

None

scheme = 'sqlite'
async start()
Return type

None

async stop()
Return type

None

mautrix.util.async_db.SQLiteCursor

alias of mautrix.util.async_db.Cursor

mautrix.util.async_db.Connection

alias of mautrix.util.async_db.LoggingConnection

class mautrix.util.async_db.Scheme

Bases: enum.Enum

An enumeration.

POSTGRES = 'postgres'
COCKROACH = 'cockroach'
SQLITE = 'sqlite'
exception mautrix.util.async_db.DatabaseException

Bases: RuntimeError

property explanation: str | None
exception mautrix.util.async_db.DatabaseNotOwned

Bases: mautrix.util.async_db.DatabaseException

__init__(owner)
Parameters

owner (str) –

Return type

None

property explanation: str
exception mautrix.util.async_db.UnsupportedDatabaseVersion

Bases: mautrix.util.async_db.DatabaseException

__init__(name, version, latest)
Parameters
  • name (str) –

  • version (int) –

  • latest (int) –

Return type

None

property explanation: str
exception mautrix.util.async_db.ForeignTablesFound

Bases: mautrix.util.async_db.DatabaseException

__init__(explanation)
Parameters

explanation (str) –

Return type

None

property explanation: str