minos.aggregate.snapshots.repositories.database.impl

Classes

DatabaseSnapshotRepository

Database Snapshot Repository class.

class DatabaseSnapshotRepository[source]

Bases: SnapshotRepository, DatabaseMixin[SnapshotDatabaseOperationFactory]

Database Snapshot Repository class.

The snapshot provides a direct accessor to the RootEntity instances stored as events by the event repository class.

__init__()[source]
Parameters
async is_synced(name, **kwargs)[source]

Check if the snapshot has the latest version of a RootEntity instance.

Parameters

name (str) – Class name of the RootEntity to be checked.

Returns

True if it has the latest version for the identifier or False otherwise.

Return type

bool

property already_destroyed: bool

Already Destroy getter.

Returns

A boolean value.

property already_setup: bool

Already Setup getter.

Returns

A boolean value.

property database_client_cls: type[minos.common.database.clients.abc.DatabaseClient]

Get the client’s class.

Returns

A type instance that is subclass of DatabaseClient.

property database_operation_factory: Optional[minos.common.database.mixins.GenericDatabaseOperationFactory]

Get the operation factory if any.

Returns

A OperationFactory if it has been set or None otherwise.

property database_pool: minos.common.database.pools.DatabaseClientPool

Get the database pool.

Returns

A DatabaseClientPool object.

async destroy()

Destroy miscellaneous repository things.

Returns

This method does not return anything.

Return type

None

async execute_on_database(operation)

Submit an Operation.

Parameters

operation (DatabaseOperation) – The operation to be executed.

Returns

This method does not return anything.

Return type

None

async execute_on_database_and_fetch_all(operation, streaming_mode=None)

Submit an Operation and return an asynchronous iterator.

Parameters
  • operation (DatabaseOperation) – The operation to be executed.

  • streaming_mode (Optional[bool]) – If True return the values in streaming directly from the database (keep an open database connection), otherwise preloads the full set of values on memory and then retrieves them.

Returns

This method does not return anything.

Return type

AsyncIterator[tuple]

async execute_on_database_and_fetch_one(operation)

Submit an Operation and get the first response.

Parameters

operation (DatabaseOperation) – The operation to be executed.

Returns

This method does not return anything.

Return type

Any

async find(name, condition, ordering=None, limit=None, streaming_mode=False, transaction=None, **kwargs)

Find a collection of RootEntity instances based on a Condition.

Parameters
  • name (Union[str, type[RootEntity]]) – Class name of the RootEntity.

  • condition (_Condition) – The condition that must be satisfied by the RootEntity instances.

  • ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.

  • limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.

  • streaming_mode (bool) – If True return the values in streaming directly from the database (keep an open database connection), otherwise preloads the full set of values on memory and then retrieves them.

  • transaction (Optional[TransactionEntry]) – The transaction within the operation is performed. If not any value is provided, then the transaction is extracted from the context var. If not any transaction is being scoped then the query is performed to the global snapshot.

  • kwargs – Additional named arguments.

Returns

An asynchronous iterator that containing the RootEntity instances.

Return type

AsyncIterator[RootEntity]

async find_entries(name, condition, ordering=None, limit=None, streaming_mode=False, transaction=None, exclude_deleted=True, synchronize=True, **kwargs)

Find a collection of SnapshotEntry instances based on a Condition.

Parameters
  • name (str) – Class name of the RootEntity.

  • condition (_Condition) – The condition that must be satisfied by the RootEntity instances.

  • ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.

  • limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.

  • streaming_mode (bool) – If True return the values in streaming directly from the database (keep an open database connection), otherwise preloads the full set of values on memory and then retrieves them.

  • transaction (Optional[TransactionEntry]) – The transaction within the operation is performed. If not any value is provided, then the transaction is extracted from the context var. If not any transaction is being scoped then the query is performed to the global snapshot.

  • exclude_deleted (bool) – If True, deleted RootEntity entries are included, otherwise deleted RootEntity entries are filtered.

  • synchronize (bool) – If True a synchronization is performed before processing the query, otherwise the query is performed without any synchronization step.

  • kwargs – Additional named arguments.

Returns

An asynchronous iterator that containing the RootEntity instances.

Return type

AsyncIterator[SnapshotEntry]

classmethod from_config(config=None, **kwargs)

Build a new instance from config.

Parameters
  • config (Optional[Union[Config, Path]]) – Config instance. If None is provided, default config is chosen.

  • kwargs – Additional named arguments.

Returns

A instance of the called class.

Return type

S

async get(name, uuid, transaction=None, **kwargs)

Get a RootEntity instance from its identifier.

Parameters
  • name (Union[str, type[RootEntity]]) – Class name of the RootEntity.

  • uuid (UUID) – Identifier of the RootEntity.

  • transaction (Optional[TransactionEntry]) – The transaction within the operation is performed. If not any value is provided, then the transaction is extracted from the context var. If not any transaction is being scoped then the query is performed to the global snapshot.

  • kwargs – Additional named arguments.

Returns

The RootEntity instance.

Return type

RootEntity

get_all(name, ordering=None, limit=None, streaming_mode=False, transaction=None, **kwargs)

Get all RootEntity instances.

Parameters
  • name (str) – Class name of the RootEntity.

  • ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.

  • limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.

  • streaming_mode (bool) – If True return the values in streaming directly from the database (keep an open database connection), otherwise preloads the full set of values on memory and then retrieves them.

  • transaction (Optional[TransactionEntry]) – The transaction within the operation is performed. If not any value is provided, then the transaction is extracted from the context var. If not any transaction is being scoped then the query is performed to the global snapshot.

  • kwargs – Additional named arguments.

Returns

An asynchronous iterator that containing the RootEntity instances.

Return type

AsyncIterator[RootEntity]

async get_entry(name, uuid, **kwargs)

Get a SnapshotEntry from its identifier.

Parameters
  • name (str) – Class name of the RootEntity.

  • uuid (UUID) – Identifier of the RootEntity.

  • kwargs – Additional named arguments.

Returns

The SnapshotEntry instance.

Return type

SnapshotEntry

classmethod get_injectable_name()

Get the injectable name.

Returns

A str value.

Return type

str

async setup()

Setup miscellaneous repository things.

Returns

This method does not return anything.

Return type

None

synchronize(**kwargs)

Synchronize the snapshot to the latest available version.

Parameters

kwargs – Additional named arguments.

Returns

This method does not return anything.

Return type

Awaitable[None]