minos.aggregate.events.repositories.pg module¶
- class minos.aggregate.events.repositories.pg.PostgreSqlEventRepository(host, port, database, user, password, *args, **kwargs)[source]¶
Bases:
minos.common.database.abc.PostgreSqlMinosDatabase
,minos.aggregate.events.repositories.abc.EventRepository
PostgreSQL-based implementation of the event repository class in
Minos
.- __init__(host, port, database, user, password, *args, **kwargs)¶
- property already_destroyed: bool¶
Already Destroy getter.
- Return type
bool
- Returns
A boolean value.
- property already_setup: bool¶
Already Setup getter.
- Return type
bool
- Returns
A boolean value.
- async create(entry)¶
Store new creation entry into the repository.
- Parameters
entry (
typing.Union
[minos.aggregate.models.diffs.aggregates.AggregateDiff
,minos.aggregate.events.entries.EventEntry
]) – Entry to be stored.- Return type
- Returns
The repository entry containing the stored information.
- cursor(*args, **kwargs)¶
Get a new cursor.
- Parameters
args – Additional positional arguments.
kwargs – Additional named arguments.
- Return type
typing.AsyncContextManager
[aiopg.connection.Cursor
]- Returns
A Cursor wrapped into an asynchronous context manager.
- async delete(entry)¶
Store new deletion entry into the repository.
- Parameters
entry (
typing.Union
[minos.aggregate.models.diffs.aggregates.AggregateDiff
,minos.aggregate.events.entries.EventEntry
]) – Entry to be stored.- Return type
- Returns
The repository entry containing the stored information.
- async destroy()¶
Destroy miscellaneous repository things.
- Return type
None
- Returns
This method does not return anything.
- classmethod from_config(config=None, **kwargs)¶
Build a new instance from config.
- Parameters
config (
typing.Union
[minos.common.configuration.config.MinosConfig
,pathlib.Path
,None
]) – Config instance. If None is provided, default config is chosen.kwargs – Additional named arguments.
- Return type
~S
- Returns
A instance of the called class.
- locked_cursor(key, *args, **kwargs)¶
Get a new locked cursor.
- Parameters
key (
collections.abc.Hashable
) – The key to be used for locking.args – Additional positional arguments.
kwargs – Additional named arguments.
- Return type
typing.AsyncContextManager
[aiopg.connection.Cursor
]- Returns
A Cursor wrapped into an asynchronous context manager.
- property offset: Awaitable[int]¶
Get the current repository offset.
- Return type
typing.Awaitable
[int
]- Returns
An awaitable containing an integer value.
- property pool: minos.common.database.pools.PostgreSqlPool¶
Get the connections pool.
- Return type
minos.common.database.pools.PostgreSqlPool
- Returns
A
Pool
object.
- async select(aggregate_uuid=None, aggregate_name=None, version=None, version_lt=None, version_gt=None, version_le=None, version_ge=None, id=None, id_lt=None, id_gt=None, id_le=None, id_ge=None, transaction_uuid=None, transaction_uuid_ne=None, transaction_uuid_in=None, **kwargs)¶
Perform a selection query of entries stored in to the repository.
- Parameters
aggregate_uuid (
typing.Optional
[uuid.UUID
]) – Aggregate identifier.aggregate_name (
typing.Optional
[str
]) – Aggregate name.version (
typing.Optional
[int
]) – Aggregate version.version_lt (
typing.Optional
[int
]) – Aggregate version lower than the given value.version_gt (
typing.Optional
[int
]) – Aggregate version greater than the given value.version_le (
typing.Optional
[int
]) – Aggregate version lower or equal to the given value.version_ge (
typing.Optional
[int
]) – Aggregate version greater or equal to the given value.id (
typing.Optional
[int
]) – Entry identifier.id_lt (
typing.Optional
[int
]) – Entry identifier lower than the given value.id_gt (
typing.Optional
[int
]) – Entry identifier greater than the given value.id_le (
typing.Optional
[int
]) – Entry identifier lower or equal to the given value.id_ge (
typing.Optional
[int
]) – Entry identifier greater or equal to the given value.transaction_uuid (
typing.Optional
[uuid.UUID
]) – Transaction identifier.transaction_uuid_ne (
typing.Optional
[uuid.UUID
]) – Transaction identifier distinct of the given value.transaction_uuid_in (
typing.Optional
[tuple
[uuid.UUID
, …]]) – Destination Transaction identifier equal to one of the given values.
- Return type
typing.AsyncIterator
[minos.aggregate.events.entries.EventEntry
]- Returns
A list of entries.
- async setup()¶
Setup miscellaneous repository things.
- Return type
None
- Returns
This method does not return anything.
- async submit(entry, **kwargs)¶
Store new entry into the repository.
- Parameters
entry (
typing.Union
[minos.aggregate.models.diffs.aggregates.AggregateDiff
,minos.aggregate.events.entries.EventEntry
]) – The entry to be stored.kwargs – Additional named arguments.
- Return type
- Returns
The repository entry containing the stored information.
- async submit_query(operation, parameters=None, *, timeout=None, lock=None, **kwargs)¶
Submit a SQL query.
- Parameters
operation (
typing.Any
) – Query to be executed.parameters (
typing.Optional
[typing.Any
]) – Parameters to be projected into the query.timeout (
typing.Optional
[float
]) – An optional timeout.lock (
typing.Optional
[typing.Any
]) – Optional key to perform the query with locking. If not set, the query is performed without any lock.kwargs – Additional named arguments.
- Return type
None
- Returns
This method does not return anything.
- async submit_query_and_fetchone(*args, **kwargs)¶
Submit a SQL query and gets the first response.
- Parameters
args – Additional positional arguments.
kwargs – Additional named arguments.
- Return type
tuple
- Returns
This method does not return anything.
- async submit_query_and_iter(operation, parameters=None, *, timeout=None, lock=None, streaming_mode=False, **kwargs)¶
Submit a SQL query and return an asynchronous iterator.
- Parameters
operation (
typing.Any
) – Query to be executed.parameters (
typing.Optional
[typing.Any
]) – Parameters to be projected into the query.timeout (
typing.Optional
[float
]) – An optional timeout.lock (
typing.Optional
[int
]) – Optional key to perform the query with locking. If not set, the query is performed without any lock.streaming_mode (
bool
) – IfTrue
the data fetching is performed in streaming mode, that is iterating over the cursor and yielding once a time (requires an opening connection to do that). Otherwise, all the data is fetched and keep in memory before yielding it.kwargs – Additional named arguments.
- Return type
typing.AsyncIterator
[tuple
]- Returns
This method does not return anything.
- transaction(**kwargs)¶
Build a transaction instance related to the repository.
- Parameters
kwargs – Additional named arguments.
- Return type
- Returns
A new
TransactionEntry
instance.
- async update(entry)¶
Store new update entry into the repository.
- Parameters
entry (
typing.Union
[minos.aggregate.models.diffs.aggregates.AggregateDiff
,minos.aggregate.events.entries.EventEntry
]) – Entry to be stored.- Return type
- Returns
The repository entry containing the stored information.
- async validate(entry, transaction_uuid_ne=None, **kwargs)¶
Check if it is able to submit the given entry.
- Parameters
entry (
minos.aggregate.events.entries.EventEntry
) – The entry to be validated.transaction_uuid_ne (
typing.Optional
[uuid.UUID
]) – Optional transaction identifier to skip it from the validation.kwargs – Additional named arguments.
- Return type
bool
- Returns
True
if the entry can be submitted orFalse
otherwise.
- write_lock()¶
Get a write lock.
- Return type
minos.common.locks.Lock
- Returns
An asynchronous context manager.