minos.aggregate.models.aggregates module

class minos.aggregate.models.aggregates.Aggregate(*args, uuid=UUID('00000000-0000-0000-0000-000000000000'), version=0, created_at=datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc), _repository=<dependency_injector.wiring.Provide object>, _snapshot=<dependency_injector.wiring.Provide object>, **kwargs)[source]

Bases: minos.aggregate.models.entities.Entity

Base aggregate class.

__init__(*args, uuid=UUID('00000000-0000-0000-0000-000000000000'), version=0, created_at=datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc), _repository=<dependency_injector.wiring.Provide object>, _snapshot=<dependency_injector.wiring.Provide object>, **kwargs)[source]

Class constructor.

Parameters

kwargs – Named arguments to be set as model attributes.

apply_diff(aggregate_diff)[source]

Apply the differences over the instance.

Parameters

aggregate_diff (minos.aggregate.models.diffs.aggregates.AggregateDiff) – The FieldDiffContainer containing the values to be set.

Return type

None

Returns

This method does not return anything.

property avro_bytes: bytes

Generate bytes representation of the current instance.

Return type

bytes

Returns

A bytes object.

property avro_data: dict[str, typing.Any]

Compute the avro data of the model.

Return type

dict[str, typing.Any]

Returns

A dictionary object.

avro_schema = [{'name': 'Aggregate', 'namespace': 'minos.aggregate.models.aggregates.17d5ebc9-eb75-4c98-a52d-c5a1fabcdc4b', 'type': 'record', 'fields': [{'name': 'uuid', 'type': {'type': 'string', 'logicalType': 'uuid'}}, {'name': 'version', 'type': 'int'}, {'name': 'created_at', 'type': {'type': 'long', 'logicalType': 'timestamp-micros'}}, {'name': 'updated_at', 'type': {'type': 'long', 'logicalType': 'timestamp-micros'}}]}]
property avro_str: str

Generate bytes representation of the current instance.

Return type

str

Returns

A bytes object.

classname = 'minos.aggregate.models.aggregates.Aggregate'
async classmethod create(*args, **kwargs)[source]

Create a new Aggregate instance.

Parameters
  • args – Additional positional arguments.

  • kwargs – Additional named arguments.

Return type

~T

Returns

A new Aggregate instance.

created_at: datetime
classmethod decode_data(decoder, target, type_, **kwargs)

Decode data with the given decoder.

Parameters
  • decoder (minos.common.model.serializers.abc.DataDecoder) – The decoder instance.

  • target (typing.Any) – The data to be decoded.

  • type – The data type.

  • kwargs – Additional named arguments.

Return type

typing.Any

Returns

A decoded instance.

classmethod decode_schema(decoder, target, **kwargs)

Decode schema with the given encoder.

Parameters
  • decoder (minos.common.model.serializers.abc.SchemaDecoder) – The decoder instance.

  • target (typing.Any) – The schema to be decoded.

  • kwargs – Additional named arguments.

Return type

typing.Any

Returns

The decoded schema as a type.

async delete()[source]

Delete the given aggregate instance.

Return type

None

Returns

This method does not return anything.

diff(another)[source]

Compute the difference with another aggregate.

Both Aggregate instances (self and another) must share the same uuid value.

Parameters

another (minos.aggregate.models.aggregates.Aggregate) – Another Aggregate instance.

Return type

minos.aggregate.models.diffs.aggregates.AggregateDiff

Returns

An FieldDiffContainer instance.

encode_data(encoder, target, **kwargs)

Encode data with the given encoder.

Parameters
  • encoder (minos.common.model.serializers.abc.DataEncoder) – The encoder instance.

  • target (typing.Any) – An optional pre-encoded data.

  • kwargs – Additional named arguments.

Return type

typing.Any

Returns

The encoded data of the instance.

classmethod encode_schema(encoder, target, **kwargs)

Encode schema with the given encoder.

Parameters
  • encoder (minos.common.model.serializers.abc.SchemaEncoder) – The encoder instance.

  • target (typing.Any) – An optional pre-encoded schema.

  • kwargs – Additional named arguments.

Return type

typing.Any

Returns

The encoded schema of the instance.

property fields: dict[str, minos.common.model.fields.Field]

Fields getter

Return type

dict[str, minos.common.model.fields.Field]

classmethod find(cls, condition, ordering=None, limit=None, _snapshot=<dependency_injector.wiring.Provide object>, **kwargs)[source]

Find a collection of instances based on a given Condition.

Parameters
  • condition (minos.aggregate.queries._Condition) – The Condition that must be satisfied by all the instances.

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

  • limit (typing.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.

  • _snapshot (minos.aggregate.snapshots.abc.SnapshotRepository) – Snapshot to be set to the aggregate.

Returns

A list of aggregate instances.

Return type

typing.AsyncIterator[~T]

Returns

An aggregate instance.

classmethod from_avro(schema, data)

Build a new instance from the avro schema and data.

Parameters
  • schema (typing.Any) – The avro schema of the model.

  • data (typing.Any) – The avro data of the model.

Return type

~T

Returns

A new DynamicModel instance.

classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)

Build a single instance or a sequence of instances from bytes

Parameters
  • raw (bytes) – A bytes representation of the model.

  • batch_mode (bool) – If True the data is processed as a list of models, otherwise the data is processed as a

single model. :param kwargs: Additional named arguments. :rtype: typing.Union[~T, list[~T]] :return: A single instance or a sequence of instances.

classmethod from_avro_str(raw, **kwargs)

Build a single instance or a sequence of instances from bytes

Parameters

raw (str) – A str representation of the model.

Return type

typing.Union[~T, list[~T]]

Returns

A single instance or a sequence of instances.

classmethod from_diff(aggregate_diff, *args, **kwargs)[source]

Build a new instance from an AggregateDiff.

Parameters
Return type

~T

Returns

A new Aggregate instance.

classmethod from_model_type(model_type, *args, **kwargs)

Build a DeclarativeModel from a ModelType.

Parameters
  • model_type (minos.common.model.types.model_types.ModelType) – ModelType object containing the model structure.

  • args – Positional arguments to be passed to the model constructor.

  • kwargs – Named arguments to be passed to the model constructor.

Return type

~T

Returns

A new DeclarativeModel instance.

classmethod from_typed_dict(typed_dict, *args, **kwargs)

Build a Model from a TypeDict and data.

Parameters
  • typed_dict (typing.TypedDict) – TypeDict object containing the DTO’s structure

  • args – Positional arguments to be passed to the model constructor.

  • kwargs – Named arguments to be passed to the model constructor.

Return type

~T

Returns

A new DataTransferObject instance.

async classmethod get(cls, uuid, _snapshot=<dependency_injector.wiring.Provide object>, **kwargs)[source]

Get one instance from the database based on its identifier.

Parameters
Return type

~T

Returns

A list of aggregate instances.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
async refresh()[source]

Refresh the state of the given instance.

Return type

None

Returns

This method does not return anything.

async save()[source]

Store the current instance on the repository.

If didn’t exist previously creates a new one, otherwise updates the existing one.

Return type

None

classmethod to_avro_bytes(models)

Create a bytes representation of the given object instances.

Parameters

models (list[~T]) – A sequence of minos models.

Return type

bytes

Returns

A bytes object.

classmethod to_avro_str(models)

Build the avro string representation of the given object instances.

Parameters

models (list[~T]) – A sequence of minos models.

Return type

str

Returns

A bytes object.

type_hints
type_hints_parameters = ()
async update(**kwargs)[source]

Update an existing Aggregate instance.

Parameters

kwargs – Additional named arguments.

Return type

~T

Returns

An updated Aggregate instance.

updated_at: datetime
uuid: UUID
values() an object providing a view on D's values
version: int