Skip to content

Commit e6e931e

Browse files
author
Sergio García Prado
authored
Merge pull request #372 from minos-framework/issue-371-add-database-operation
#371 - Add `DatabaseOperation`
2 parents 54774ca + 7c6bab9 commit e6e931e

File tree

126 files changed

+3558
-2198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3558
-2198
lines changed

packages/core/minos-microservice-aggregate/minos/aggregate/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
RootEntity,
3030
)
3131
from .events import (
32+
AiopgEventDatabaseOperationFactory,
33+
DatabaseEventRepository,
3234
Event,
35+
EventDatabaseOperationFactory,
3336
EventEntry,
3437
EventRepository,
3538
FieldDiff,
3639
FieldDiffContainer,
3740
IncrementalFieldDiff,
3841
InMemoryEventRepository,
39-
PostgreSqlEventRepository,
4042
)
4143
from .exceptions import (
4244
AggregateException,
@@ -57,20 +59,24 @@
5759
Ordering,
5860
)
5961
from .snapshots import (
62+
AiopgSnapshotDatabaseOperationFactory,
63+
AiopgSnapshotQueryDatabaseOperationBuilder,
64+
DatabaseSnapshotReader,
65+
DatabaseSnapshotRepository,
66+
DatabaseSnapshotSetup,
67+
DatabaseSnapshotWriter,
6068
InMemorySnapshotRepository,
61-
PostgreSqlSnapshotQueryBuilder,
62-
PostgreSqlSnapshotReader,
63-
PostgreSqlSnapshotRepository,
64-
PostgreSqlSnapshotSetup,
65-
PostgreSqlSnapshotWriter,
69+
SnapshotDatabaseOperationFactory,
6670
SnapshotEntry,
6771
SnapshotRepository,
6872
SnapshotService,
6973
)
7074
from .transactions import (
7175
TRANSACTION_CONTEXT_VAR,
76+
AiopgTransactionDatabaseOperationFactory,
77+
DatabaseTransactionRepository,
7278
InMemoryTransactionRepository,
73-
PostgreSqlTransactionRepository,
79+
TransactionDatabaseOperationFactory,
7480
TransactionEntry,
7581
TransactionRepository,
7682
TransactionService,

packages/core/minos-microservice-aggregate/minos/aggregate/events/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
Event,
1111
)
1212
from .repositories import (
13+
AiopgEventDatabaseOperationFactory,
14+
DatabaseEventRepository,
15+
EventDatabaseOperationFactory,
1316
EventRepository,
1417
InMemoryEventRepository,
15-
PostgreSqlEventRepository,
1618
)

packages/core/minos-microservice-aggregate/minos/aggregate/events/repositories/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from .abc import (
22
EventRepository,
33
)
4+
from .database import (
5+
AiopgEventDatabaseOperationFactory,
6+
DatabaseEventRepository,
7+
EventDatabaseOperationFactory,
8+
)
49
from .memory import (
510
InMemoryEventRepository,
611
)
7-
from .pg import (
8-
PostgreSqlEventRepository,
9-
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .factories import (
2+
AiopgEventDatabaseOperationFactory,
3+
EventDatabaseOperationFactory,
4+
)
5+
from .impl import (
6+
DatabaseEventRepository,
7+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .abc import (
2+
EventDatabaseOperationFactory,
3+
)
4+
from .aiopg import (
5+
AiopgEventDatabaseOperationFactory,
6+
)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from abc import (
2+
ABC,
3+
abstractmethod,
4+
)
5+
from datetime import (
6+
datetime,
7+
)
8+
from typing import (
9+
Optional,
10+
)
11+
from uuid import (
12+
UUID,
13+
)
14+
15+
from minos.common import (
16+
DatabaseOperation,
17+
DatabaseOperationFactory,
18+
)
19+
20+
from .....actions import (
21+
Action,
22+
)
23+
24+
25+
class EventDatabaseOperationFactory(DatabaseOperationFactory, ABC):
26+
"""Event Database Operation Factory base class."""
27+
28+
@abstractmethod
29+
def build_create_table(self) -> DatabaseOperation:
30+
"""Build the database operation to create the event table.
31+
32+
:return: A ``DatabaseOperation`` instance.s
33+
"""
34+
35+
@abstractmethod
36+
def build_submit_row(
37+
self,
38+
transaction_uuids: tuple[UUID],
39+
uuid: UUID,
40+
action: Action,
41+
name: str,
42+
version: int,
43+
data: bytes,
44+
created_at: datetime,
45+
transaction_uuid: UUID,
46+
lock: Optional[int],
47+
**kwargs,
48+
) -> DatabaseOperation:
49+
"""Build the database operation to submit a row into the event table.
50+
51+
:param transaction_uuids: The sequence of nested transaction in on top of the current event's transaction.
52+
:param uuid: The identifier of the entity.
53+
:param action: The action of the event.
54+
:param name: The name of the entity.
55+
:param version: The version of the entity
56+
:param data: The data of the event.
57+
:param created_at: The creation datetime.
58+
:param transaction_uuid: The identifier of the transaction.
59+
:param lock: The lock identifier.
60+
:param kwargs: Additional named arguments.
61+
:return: A ``DatabaseOperation`` instance.
62+
"""
63+
64+
# noinspection PyShadowingBuiltins
65+
@abstractmethod
66+
def build_select_rows(
67+
self,
68+
uuid: Optional[UUID] = None,
69+
name: Optional[str] = None,
70+
version: Optional[int] = None,
71+
version_lt: Optional[int] = None,
72+
version_gt: Optional[int] = None,
73+
version_le: Optional[int] = None,
74+
version_ge: Optional[int] = None,
75+
id: Optional[int] = None,
76+
id_lt: Optional[int] = None,
77+
id_gt: Optional[int] = None,
78+
id_le: Optional[int] = None,
79+
id_ge: Optional[int] = None,
80+
transaction_uuid: Optional[UUID] = None,
81+
transaction_uuid_ne: Optional[UUID] = None,
82+
transaction_uuid_in: Optional[tuple[UUID, ...]] = None,
83+
**kwargs,
84+
) -> DatabaseOperation:
85+
"""Build the database operation to select rows.
86+
87+
:param uuid: The identifier must be equal to the given value.
88+
:param name: The classname must be equal to the given value.
89+
:param version: The version must be equal to the given value.
90+
:param version_lt: The version must be lower than the given value.
91+
:param version_gt: The version must be greater than the given value.
92+
:param version_le: The version must be lower or equal to the given value.
93+
:param version_ge: The version must be greater or equal to the given value.
94+
:param id: The entry identifier must be equal to the given value.
95+
:param id_lt: The entry identifier must be lower than the given value.
96+
:param id_gt: The entry identifier must be greater than the given value.
97+
:param id_le: The entry identifier must be lower or equal to the given value.
98+
:param id_ge: The entry identifier must be greater or equal to the given value.
99+
:param transaction_uuid: The transaction identifier must be equal to the given value.
100+
:param transaction_uuid_ne: The transaction identifier must be distinct of the given value.
101+
:param transaction_uuid_in: The destination transaction identifier must be equal to one of the given values.
102+
103+
:return: A ``DatabaseOperation`` instance.
104+
"""
105+
106+
@abstractmethod
107+
def build_select_max_id(self) -> DatabaseOperation:
108+
"""Build the database operation to get the maximum identifier.
109+
110+
:return: A ``DatabaseOperation`` instance.
111+
"""

0 commit comments

Comments
 (0)