maleo-database 0.0.21__tar.gz → 0.0.24__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maleo_database-0.0.21 → maleo_database-0.0.24}/PKG-INFO +1 -1
- {maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/PKG-INFO +1 -1
- {maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/SOURCES.txt +1 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/pyproject.toml +1 -1
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/handlers.py +20 -36
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/managers/__init__.py +19 -10
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/orm/queries.py +37 -34
- maleo_database-0.0.24/src/types.py +5 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/LICENSE +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/README.md +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/dependency_links.txt +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/requires.txt +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/top_level.txt +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/setup.cfg +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/__init__.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/config/__init__.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/config/additional.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/config/connection.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/config/identifier.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/config/pooling.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/dtos.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/enums.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/managers/client.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/managers/engine.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/managers/session.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/orm/__init__.py +0 -0
- {maleo_database-0.0.21 → maleo_database-0.0.24}/src/orm/mixins.py +0 -0
@@ -1,8 +1,5 @@
|
|
1
1
|
from pydantic import BaseModel, ConfigDict, Field
|
2
|
-
from sqlalchemy import MetaData
|
3
2
|
from typing import Generic, Optional, TypeVar
|
4
|
-
from maleo.dtos.contexts.service import ServiceContext
|
5
|
-
from maleo.logging.logger import Database
|
6
3
|
from .config import (
|
7
4
|
ElasticsearchConfig,
|
8
5
|
MongoConfig,
|
@@ -23,6 +20,7 @@ from .managers import (
|
|
23
20
|
SQLServerManager,
|
24
21
|
ManagerT,
|
25
22
|
)
|
23
|
+
from .types import DeclarativeBaseT
|
26
24
|
|
27
25
|
|
28
26
|
class Handler(
|
@@ -42,17 +40,7 @@ HandlerT = TypeVar("HandlerT", bound=Handler)
|
|
42
40
|
|
43
41
|
|
44
42
|
class ElasticsearchHandler(Handler[ElasticsearchConfig, ElasticsearchManager]):
|
45
|
-
|
46
|
-
def new(
|
47
|
-
cls,
|
48
|
-
config: ElasticsearchConfig,
|
49
|
-
logger: Database,
|
50
|
-
service_context: Optional[ServiceContext] = None,
|
51
|
-
) -> "ElasticsearchHandler":
|
52
|
-
manager = ElasticsearchManager(
|
53
|
-
config=config, logger=logger, service_context=service_context
|
54
|
-
)
|
55
|
-
return cls(config=config, manager=manager)
|
43
|
+
pass
|
56
44
|
|
57
45
|
|
58
46
|
class MongoHandler(Handler[MongoConfig, MongoManager]):
|
@@ -63,33 +51,29 @@ class RedisHandler(Handler[RedisConfig, RedisManager]):
|
|
63
51
|
pass
|
64
52
|
|
65
53
|
|
66
|
-
class MySQLHandler(
|
54
|
+
class MySQLHandler(
|
55
|
+
Handler[MySQLConfig, MySQLManager[DeclarativeBaseT]], Generic[DeclarativeBaseT]
|
56
|
+
):
|
57
|
+
pass
|
58
|
+
|
59
|
+
|
60
|
+
class PostgreSQLHandler(
|
61
|
+
Handler[PostgreSQLConfig, PostgreSQLManager[DeclarativeBaseT]],
|
62
|
+
Generic[DeclarativeBaseT],
|
63
|
+
):
|
67
64
|
pass
|
68
65
|
|
69
66
|
|
70
|
-
class
|
71
|
-
|
72
|
-
|
73
|
-
cls,
|
74
|
-
config: PostgreSQLConfig,
|
75
|
-
logger: Database,
|
76
|
-
metadata: MetaData,
|
77
|
-
service_context: Optional[ServiceContext] = None,
|
78
|
-
) -> "PostgreSQLHandler":
|
79
|
-
manager = PostgreSQLManager(
|
80
|
-
config=config,
|
81
|
-
logger=logger,
|
82
|
-
metadata=metadata,
|
83
|
-
service_context=service_context,
|
84
|
-
)
|
85
|
-
return cls(config=config, manager=manager)
|
86
|
-
|
87
|
-
|
88
|
-
class SQLiteHandler(Handler[SQLiteConfig, SQLiteManager]):
|
67
|
+
class SQLiteHandler(
|
68
|
+
Handler[SQLiteConfig, SQLiteManager[DeclarativeBaseT]], Generic[DeclarativeBaseT]
|
69
|
+
):
|
89
70
|
pass
|
90
71
|
|
91
72
|
|
92
|
-
class SQLServerHandler(
|
73
|
+
class SQLServerHandler(
|
74
|
+
Handler[SQLServerConfig, SQLServerManager[DeclarativeBaseT]],
|
75
|
+
Generic[DeclarativeBaseT],
|
76
|
+
):
|
93
77
|
pass
|
94
78
|
|
95
79
|
|
@@ -190,7 +174,7 @@ class Handlers(
|
|
190
174
|
],
|
191
175
|
):
|
192
176
|
nosql: NoSQLHandlersT = Field(..., description="NoSQL handlers")
|
193
|
-
sql:
|
177
|
+
sql: SQLHandlersT = Field(..., description="SQL handlers")
|
194
178
|
|
195
179
|
|
196
180
|
HandlersT = TypeVar("HandlersT", bound=Optional[Handlers])
|
@@ -6,8 +6,8 @@ from motor.motor_asyncio import AsyncIOMotorClient
|
|
6
6
|
from pymongo import MongoClient
|
7
7
|
from redis.asyncio import Redis as AsyncRedis
|
8
8
|
from redis import Redis as SyncRedis
|
9
|
-
from sqlalchemy import
|
10
|
-
from typing import Generic, Optional, TypeVar
|
9
|
+
from sqlalchemy import text
|
10
|
+
from typing import Generic, Optional, Type, TypeVar
|
11
11
|
from uuid import uuid4
|
12
12
|
from maleo.dtos.authentication import GenericAuthentication
|
13
13
|
from maleo.dtos.contexts.operation import generate_operation_context
|
@@ -43,6 +43,7 @@ from ..config import (
|
|
43
43
|
ConfigT,
|
44
44
|
)
|
45
45
|
from ..enums import Connection
|
46
|
+
from ..types import DeclarativeBaseT
|
46
47
|
from .client import (
|
47
48
|
AsyncClientT,
|
48
49
|
SyncClientT,
|
@@ -96,16 +97,15 @@ class Manager(ABC, Generic[ConfigT]):
|
|
96
97
|
pass
|
97
98
|
|
98
99
|
|
99
|
-
class SQLManager(Manager[SQLConfigT], Generic[SQLConfigT]):
|
100
|
+
class SQLManager(Manager[SQLConfigT], Generic[SQLConfigT, DeclarativeBaseT]):
|
100
101
|
def __init__(
|
101
102
|
self,
|
103
|
+
Base: Type[DeclarativeBaseT],
|
102
104
|
config: SQLConfigT,
|
103
105
|
logger: Database,
|
104
|
-
metadata: MetaData,
|
105
106
|
service_context: Optional[ServiceContext] = None,
|
106
107
|
) -> None:
|
107
108
|
super().__init__(config, logger, service_context)
|
108
|
-
self._metadata = metadata
|
109
109
|
self._operation_context.target.details = self._config.model_dump()
|
110
110
|
self._engine_manager = EngineManager[SQLConfigT](config)
|
111
111
|
self._session_manager = SessionManager(
|
@@ -114,7 +114,8 @@ class SQLManager(Manager[SQLConfigT], Generic[SQLConfigT]):
|
|
114
114
|
logger=self._logger,
|
115
115
|
service_context=self._service_context,
|
116
116
|
)
|
117
|
-
self.
|
117
|
+
self.Base = Base
|
118
|
+
self.Base.metadata.create_all(bind=self._engine_manager.get(Connection.SYNC))
|
118
119
|
|
119
120
|
@property
|
120
121
|
def engine(self) -> EngineManager[SQLConfigT]:
|
@@ -251,19 +252,27 @@ class SQLManager(Manager[SQLConfigT], Generic[SQLConfigT]):
|
|
251
252
|
await self._engine_manager.dispose()
|
252
253
|
|
253
254
|
|
254
|
-
class MySQLManager(
|
255
|
+
class MySQLManager(
|
256
|
+
SQLManager[MySQLConfig, DeclarativeBaseT], Generic[DeclarativeBaseT]
|
257
|
+
):
|
255
258
|
pass
|
256
259
|
|
257
260
|
|
258
|
-
class PostgreSQLManager(
|
261
|
+
class PostgreSQLManager(
|
262
|
+
SQLManager[PostgreSQLConfig, DeclarativeBaseT], Generic[DeclarativeBaseT]
|
263
|
+
):
|
259
264
|
pass
|
260
265
|
|
261
266
|
|
262
|
-
class SQLiteManager(
|
267
|
+
class SQLiteManager(
|
268
|
+
SQLManager[SQLiteConfig, DeclarativeBaseT], Generic[DeclarativeBaseT]
|
269
|
+
):
|
263
270
|
pass
|
264
271
|
|
265
272
|
|
266
|
-
class SQLServerManager(
|
273
|
+
class SQLServerManager(
|
274
|
+
SQLManager[SQLServerConfig, DeclarativeBaseT], Generic[DeclarativeBaseT]
|
275
|
+
):
|
267
276
|
pass
|
268
277
|
|
269
278
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from sqlalchemy import asc, cast, desc, or_, select
|
2
|
-
from sqlalchemy.orm import
|
2
|
+
from sqlalchemy.orm import Session, aliased
|
3
3
|
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
4
4
|
from sqlalchemy.sql import Select
|
5
5
|
from sqlalchemy.types import DATE, String, TEXT, TIMESTAMP
|
6
|
-
from typing import Sequence, Type, TypeVar
|
6
|
+
from typing import Any, Sequence, Tuple, Type, TypeVar
|
7
7
|
from maleo.enums.sort import Order
|
8
8
|
from maleo.mixins.general import DateFilter, SortColumn
|
9
9
|
from maleo.types.base.any import OptionalAny
|
@@ -11,18 +11,21 @@ from maleo.types.base.boolean import OptionalBoolean
|
|
11
11
|
from maleo.types.base.integer import OptionalListOfIntegers
|
12
12
|
from maleo.types.base.string import OptionalListOfStrings, OptionalString
|
13
13
|
from maleo.types.enums.status import OptionalListOfDataStatuses
|
14
|
+
from ..types import DeclarativeBaseT
|
14
15
|
|
15
16
|
|
16
|
-
|
17
|
+
R = TypeVar(
|
18
|
+
"R", bound=Tuple[Any, ...]
|
19
|
+
) # result shape inferred from Select (tuple[...])
|
17
20
|
|
18
21
|
|
19
22
|
def filter_column(
|
20
|
-
stmt: Select,
|
21
|
-
table: Type[
|
23
|
+
stmt: Select[R],
|
24
|
+
table: Type[DeclarativeBaseT],
|
22
25
|
column: str,
|
23
26
|
value: OptionalAny = None,
|
24
27
|
include_null: bool = False,
|
25
|
-
) -> Select:
|
28
|
+
) -> Select[R]:
|
26
29
|
column_attr = getattr(table, column, None)
|
27
30
|
if column_attr is None or not isinstance(column_attr, InstrumentedAttribute):
|
28
31
|
return stmt
|
@@ -40,12 +43,12 @@ def filter_column(
|
|
40
43
|
|
41
44
|
|
42
45
|
def filter_ids(
|
43
|
-
stmt: Select,
|
44
|
-
table: Type[
|
46
|
+
stmt: Select[R],
|
47
|
+
table: Type[DeclarativeBaseT],
|
45
48
|
column: str,
|
46
49
|
ids: OptionalListOfIntegers = None,
|
47
50
|
include_null: bool = False,
|
48
|
-
) -> Select:
|
51
|
+
) -> Select[R]:
|
49
52
|
column_attr = getattr(table, column, None)
|
50
53
|
if column_attr is None or not isinstance(column_attr, InstrumentedAttribute):
|
51
54
|
return stmt
|
@@ -63,10 +66,10 @@ def filter_ids(
|
|
63
66
|
|
64
67
|
|
65
68
|
def filter_timestamps(
|
66
|
-
stmt: Select,
|
67
|
-
table: Type[
|
69
|
+
stmt: Select[R],
|
70
|
+
table: Type[DeclarativeBaseT],
|
68
71
|
date_filters: Sequence[DateFilter],
|
69
|
-
) -> Select:
|
72
|
+
) -> Select[R]:
|
70
73
|
if date_filters:
|
71
74
|
for date_filter in date_filters:
|
72
75
|
try:
|
@@ -90,10 +93,10 @@ def filter_timestamps(
|
|
90
93
|
|
91
94
|
|
92
95
|
def filter_statuses(
|
93
|
-
stmt: Select,
|
94
|
-
table: Type[
|
96
|
+
stmt: Select[R],
|
97
|
+
table: Type[DeclarativeBaseT],
|
95
98
|
statuses: OptionalListOfDataStatuses,
|
96
|
-
) -> Select:
|
99
|
+
) -> Select[R]:
|
97
100
|
if statuses is not None:
|
98
101
|
status_filters = [table.status == status for status in statuses] # type: ignore
|
99
102
|
stmt = stmt.filter(or_(*status_filters))
|
@@ -101,11 +104,11 @@ def filter_statuses(
|
|
101
104
|
|
102
105
|
|
103
106
|
def filter_is_root(
|
104
|
-
stmt: Select,
|
105
|
-
table: Type[
|
107
|
+
stmt: Select[R],
|
108
|
+
table: Type[DeclarativeBaseT],
|
106
109
|
parent_column: str = "parent_id",
|
107
110
|
is_root: OptionalBoolean = None,
|
108
|
-
) -> Select:
|
111
|
+
) -> Select[R]:
|
109
112
|
parent_attr = getattr(table, parent_column, None)
|
110
113
|
if parent_attr is None or not isinstance(parent_attr, InstrumentedAttribute):
|
111
114
|
return stmt
|
@@ -118,12 +121,12 @@ def filter_is_root(
|
|
118
121
|
|
119
122
|
def filter_is_parent(
|
120
123
|
session: Session,
|
121
|
-
stmt: Select,
|
122
|
-
table: Type[
|
124
|
+
stmt: Select[R],
|
125
|
+
table: Type[DeclarativeBaseT],
|
123
126
|
id_column: str = "id",
|
124
127
|
parent_column: str = "parent_id",
|
125
128
|
is_parent: OptionalBoolean = None,
|
126
|
-
) -> Select:
|
129
|
+
) -> Select[R]:
|
127
130
|
id_attr = getattr(table, id_column, None)
|
128
131
|
if id_attr is None or not isinstance(id_attr, InstrumentedAttribute):
|
129
132
|
return stmt
|
@@ -139,11 +142,11 @@ def filter_is_parent(
|
|
139
142
|
|
140
143
|
|
141
144
|
def filter_is_child(
|
142
|
-
stmt: Select,
|
143
|
-
table: Type[
|
145
|
+
stmt: Select[R],
|
146
|
+
table: Type[DeclarativeBaseT],
|
144
147
|
parent_column: str = "parent_id",
|
145
148
|
is_child: OptionalBoolean = None,
|
146
|
-
) -> Select:
|
149
|
+
) -> Select[R]:
|
147
150
|
parent_attr = getattr(table, parent_column, None)
|
148
151
|
if parent_attr is None or not isinstance(parent_attr, InstrumentedAttribute):
|
149
152
|
return stmt
|
@@ -156,12 +159,12 @@ def filter_is_child(
|
|
156
159
|
|
157
160
|
def filter_is_leaf(
|
158
161
|
session: Session,
|
159
|
-
stmt: Select,
|
160
|
-
table: Type[
|
162
|
+
stmt: Select[R],
|
163
|
+
table: Type[DeclarativeBaseT],
|
161
164
|
id_column: str = "id",
|
162
165
|
parent_column: str = "parent_id",
|
163
166
|
is_leaf: OptionalBoolean = None,
|
164
|
-
) -> Select:
|
167
|
+
) -> Select[R]:
|
165
168
|
id_attr = getattr(table, id_column, None)
|
166
169
|
if id_attr is None or not isinstance(id_attr, InstrumentedAttribute):
|
167
170
|
return stmt
|
@@ -177,11 +180,11 @@ def filter_is_leaf(
|
|
177
180
|
|
178
181
|
|
179
182
|
def search(
|
180
|
-
stmt: Select,
|
181
|
-
table: Type[
|
183
|
+
stmt: Select[R],
|
184
|
+
table: Type[DeclarativeBaseT],
|
182
185
|
search: OptionalString = None,
|
183
186
|
columns: OptionalListOfStrings = None,
|
184
|
-
) -> Select:
|
187
|
+
) -> Select[R]:
|
185
188
|
if search is None:
|
186
189
|
return stmt
|
187
190
|
|
@@ -211,10 +214,10 @@ def search(
|
|
211
214
|
|
212
215
|
|
213
216
|
def sort(
|
214
|
-
stmt: Select,
|
215
|
-
table: Type[
|
217
|
+
stmt: Select[R],
|
218
|
+
table: Type[DeclarativeBaseT],
|
216
219
|
sort_columns: Sequence[SortColumn],
|
217
|
-
) -> Select:
|
220
|
+
) -> Select[R]:
|
218
221
|
for sort_column in sort_columns:
|
219
222
|
try:
|
220
223
|
sort_col = getattr(table, sort_column.name)
|
@@ -227,7 +230,7 @@ def sort(
|
|
227
230
|
return stmt
|
228
231
|
|
229
232
|
|
230
|
-
def paginate(stmt: Select, page: int, limit: int) -> Select:
|
233
|
+
def paginate(stmt: Select[R], page: int, limit: int) -> Select[R]:
|
231
234
|
offset: int = int((page - 1) * limit)
|
232
235
|
stmt = stmt.limit(limit).offset(offset)
|
233
236
|
return stmt
|
File without changes
|
File without changes
|
{maleo_database-0.0.21 → maleo_database-0.0.24}/maleo_database.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|