harp_apps.storage.services

class SqlStorage[source]

Bases: IStorage

Storage implementation using SQLAlchemy (async).

Currently supported/tested database drivers:

  • asyncpg (postgresql+asyncpg://…)

  • aiomysql (mysql+aiomysql://…)

  • asyncmy (mysql+asyncmy://…)

And also, for development/testing purposes:

  • aiosqlite (sqlite+aiosqlite://…)

Other async postgresql drivers may work, but as they’re not included in the test suite, you may have surprises. Contributions welcome.

__init__(engine, blob_storage, settings)[source]
Parameters:
begin()[source]
async create_users(users)[source]
Parameters:

users (Iterable[str])

async create_users_once_ready(users)[source]

Sets the list of users to be created once the database is ready.

Parameters:

users (Iterable[str])

async finalize()[source]

Coroutine function to finalize the instance. Should release resources, close files etc… The caller should make sure to call finalize on all cases where the instance is not needed anymore to get a clean shutdown.

async get_facet_meta(name)[source]

Retrieve a facet’s metadata, by name.

async get_transaction(id, /, *, username)[source]

Find a transaction, by id.

Parameters:
Return type:

Transaction | None

async get_transaction_list(*, username, with_messages=False, filters=None, page=1, cursor='', text_search='')[source]

Implements Storage.find_transactions.

Parameters:
async get_usage()[source]

Get storage usage.

async initialize()[source]

Initialize database.

install_debugging_instrumentation(*, echo=False)[source]
async ready()[source]
async set_user_flag(*, transaction_id, username, flag, value=True)[source]

Sets or unsets a user flag on a transaction.

Parameters:
  • transaction_id (str)

  • username (str)

  • flag (int)

async transactions_grouped_by_time_bucket(*, endpoint=None, time_bucket='day', start_datetime=None)[source]
Parameters:
  • endpoint (str | None)

  • time_bucket (str)

  • start_datetime (datetime | None)

Return type:

list[TransactionsGroupedByTimeBucket]

engine: AsyncEngine

Reference to the sqlalchemy async engine, which is a gateway to the database connectivity, able to provide a connection used to execute queries.

property worker

Submodules