maleo-database 0.0.4__py3-none-any.whl → 0.0.5__py3-none-any.whl
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/config/__init__.py +188 -15
- maleo/database/config/connection.py +46 -30
- maleo/database/config/pooling.py +171 -83
- maleo/database/dtos.py +6 -0
- maleo/database/managers/__init__.py +427 -0
- maleo/database/managers/client.py +82 -0
- maleo/database/managers/engine.py +64 -0
- maleo/database/managers/session.py +413 -137
- {maleo_database-0.0.4.dist-info → maleo_database-0.0.5.dist-info}/METADATA +23 -8
- maleo_database-0.0.5.dist-info/RECORD +26 -0
- maleo/database/managers/clients/__init__.py +0 -0
- maleo/database/managers/clients/elasticsearch.py +0 -66
- maleo/database/managers/clients/mongodb.py +0 -53
- maleo/database/managers/clients/redis.py +0 -57
- maleo/database/managers/engines/__init__.py +0 -0
- maleo/database/managers/engines/mysql.py +0 -56
- maleo/database/managers/engines/postgresql.py +0 -58
- maleo/database/managers/engines/sqlite.py +0 -55
- maleo/database/managers/engines/sqlserver.py +0 -63
- maleo_database-0.0.4.dist-info/RECORD +0 -32
- {maleo_database-0.0.4.dist-info → maleo_database-0.0.5.dist-info}/WHEEL +0 -0
- {maleo_database-0.0.4.dist-info → maleo_database-0.0.5.dist-info}/licenses/LICENSE +0 -0
- {maleo_database-0.0.4.dist-info → maleo_database-0.0.5.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: maleo-database
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
4
4
|
Summary: Database package for MaleoSuite
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
6
6
|
License: Proprietary
|
@@ -18,7 +18,7 @@ Requires-Dist: cffi>=1.17.1
|
|
18
18
|
Requires-Dist: cfgv>=3.4.0
|
19
19
|
Requires-Dist: charset-normalizer>=3.4.3
|
20
20
|
Requires-Dist: click>=8.2.1
|
21
|
-
Requires-Dist: cryptography>=45.0.
|
21
|
+
Requires-Dist: cryptography>=45.0.7
|
22
22
|
Requires-Dist: distlib>=0.4.0
|
23
23
|
Requires-Dist: dnspython>=2.7.0
|
24
24
|
Requires-Dist: elastic-transport>=9.1.0
|
@@ -31,25 +31,35 @@ Requires-Dist: google-cloud-appengine-logging>=1.6.2
|
|
31
31
|
Requires-Dist: google-cloud-audit-log>=0.3.2
|
32
32
|
Requires-Dist: google-cloud-core>=2.4.3
|
33
33
|
Requires-Dist: google-cloud-logging>=3.12.1
|
34
|
+
Requires-Dist: google-cloud-pubsub>=2.31.1
|
34
35
|
Requires-Dist: googleapis-common-protos>=1.70.0
|
35
36
|
Requires-Dist: greenlet>=3.2.4
|
36
37
|
Requires-Dist: grpc-google-iam-v1>=0.14.2
|
37
38
|
Requires-Dist: grpcio>=1.74.0
|
38
39
|
Requires-Dist: grpcio-status>=1.74.0
|
40
|
+
Requires-Dist: h11>=0.16.0
|
41
|
+
Requires-Dist: httpcore>=1.0.9
|
42
|
+
Requires-Dist: httpx>=0.28.1
|
39
43
|
Requires-Dist: identify>=2.6.13
|
40
44
|
Requires-Dist: idna>=3.10
|
41
45
|
Requires-Dist: importlib_metadata>=8.7.0
|
42
|
-
Requires-Dist: maleo-constants>=0.0.
|
43
|
-
Requires-Dist: maleo-
|
44
|
-
Requires-Dist: maleo-
|
45
|
-
Requires-Dist: maleo-
|
46
|
+
Requires-Dist: maleo-constants>=0.0.6
|
47
|
+
Requires-Dist: maleo-dtos>=0.0.10
|
48
|
+
Requires-Dist: maleo-enums>=0.0.6
|
49
|
+
Requires-Dist: maleo-exceptions>=0.0.11
|
50
|
+
Requires-Dist: maleo-logging>=0.0.5
|
51
|
+
Requires-Dist: maleo-mixins>=0.0.12
|
52
|
+
Requires-Dist: maleo-schemas>=0.0.13
|
46
53
|
Requires-Dist: maleo-types-base>=0.0.2
|
47
|
-
Requires-Dist: maleo-types-
|
48
|
-
Requires-Dist: maleo-
|
54
|
+
Requires-Dist: maleo-types-controllers>=0.0.1
|
55
|
+
Requires-Dist: maleo-types-enums>=0.0.4
|
56
|
+
Requires-Dist: maleo-utils>=0.0.4
|
49
57
|
Requires-Dist: motor>=3.7.1
|
50
58
|
Requires-Dist: mypy_extensions>=1.1.0
|
51
59
|
Requires-Dist: nodeenv>=1.9.1
|
52
60
|
Requires-Dist: opentelemetry-api>=1.36.0
|
61
|
+
Requires-Dist: opentelemetry-sdk>=1.36.0
|
62
|
+
Requires-Dist: opentelemetry-semantic-conventions>=0.57b0
|
53
63
|
Requires-Dist: packaging>=25.0
|
54
64
|
Requires-Dist: pathspec>=0.12.1
|
55
65
|
Requires-Dist: platformdirs>=4.4.0
|
@@ -61,9 +71,11 @@ Requires-Dist: pyasn1_modules>=0.4.2
|
|
61
71
|
Requires-Dist: pycparser>=2.22
|
62
72
|
Requires-Dist: pycryptodome>=3.23.0
|
63
73
|
Requires-Dist: pydantic>=2.11.7
|
74
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
64
75
|
Requires-Dist: pydantic_core>=2.33.2
|
65
76
|
Requires-Dist: pymongo>=4.14.1
|
66
77
|
Requires-Dist: python-dateutil>=2.9.0.post0
|
78
|
+
Requires-Dist: python-dotenv>=1.1.1
|
67
79
|
Requires-Dist: PyYAML>=6.0.2
|
68
80
|
Requires-Dist: redis>=6.4.0
|
69
81
|
Requires-Dist: requests>=2.32.5
|
@@ -74,7 +86,10 @@ Requires-Dist: SQLAlchemy>=2.0.43
|
|
74
86
|
Requires-Dist: starlette>=0.47.3
|
75
87
|
Requires-Dist: typing-inspection>=0.4.1
|
76
88
|
Requires-Dist: typing_extensions>=4.15.0
|
89
|
+
Requires-Dist: ua-parser>=1.0.1
|
90
|
+
Requires-Dist: ua-parser-builtins>=0.18.0.post1
|
77
91
|
Requires-Dist: urllib3>=2.5.0
|
92
|
+
Requires-Dist: user-agents>=2.2.0
|
78
93
|
Requires-Dist: virtualenv>=20.34.0
|
79
94
|
Requires-Dist: zipp>=3.23.0
|
80
95
|
Dynamic: license-file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
maleo/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
maleo/database/dtos.py,sha256=DArPtSXzPJd896i-t4OmoqBP1mW-it8NVxvfWq7wq8Y,220
|
3
|
+
maleo/database/enums.py,sha256=vUPlePELTC30el9rUglQpc7ZYBVMKp3SiRHCZre9oQE,1693
|
4
|
+
maleo/database/config/__init__.py,sha256=6OK2FPbBiZdaEqhQ_Uu8g3h0jfwOvtwjoU8jZVdR70c,8607
|
5
|
+
maleo/database/config/additional.py,sha256=kCamg5Z_FfbZBq_06QwGOjee8wOrL1wTIVlO60xNqWU,1060
|
6
|
+
maleo/database/config/connection.py,sha256=oMHIaom9PsGW0BpXW90bhuoFLNPsgQU4Fb8BateYjR4,22903
|
7
|
+
maleo/database/config/identifier.py,sha256=b1MjhoKl3h7xJe1eVIj1wjvYH9BrjHzKnjzdjaEaTeQ,626
|
8
|
+
maleo/database/config/pooling.py,sha256=Ms_7HjTrYathov2ef91L2rL7Ldgpr1p-7Fqg-1hv7m4,11556
|
9
|
+
maleo/database/managers/__init__.py,sha256=0sswamrwJzaRZ3iINaC5tS83GaNoZ2kDtUk7aLoY1-8,14774
|
10
|
+
maleo/database/managers/client.py,sha256=7C3PvOmWVvKJJdC81XK7q9pL9ZnvE02LRET46TR3Ojo,2272
|
11
|
+
maleo/database/managers/engine.py,sha256=OYXxDhldbSevXDqod9joqXWaYgQ-NgF4YKPfUR5o9rM,1789
|
12
|
+
maleo/database/managers/session.py,sha256=lSPegZ1DazaHeTLMN1Qx9kQVFrbtzk8-GX_AERDJ7-E,21146
|
13
|
+
maleo/database/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
+
maleo/database/orm/base.py,sha256=qdRK_TQqDoZ1hANvm1mJDiblqFr77J1IhBnlENr7RK8,229
|
15
|
+
maleo/database/orm/queries.py,sha256=NX9PYT6GZgwIhtRc7WSTS9EUzqTZCb-ib99ccYjmUkM,7643
|
16
|
+
maleo/database/orm/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
maleo/database/orm/models/table.py,sha256=UhEH7WN1lrNY3uTb4a5VWO4l9UaYhnRQK_0Z7R0lMNA,457
|
18
|
+
maleo/database/orm/models/mixins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
+
maleo/database/orm/models/mixins/identifier.py,sha256=jICVsLUFw_f7TV_aX4KTTs_ycH35MRtRj5boTqctmZo,425
|
20
|
+
maleo/database/orm/models/mixins/status.py,sha256=Jzithn-Hl2ct1AqboGZSXrA35aaQEDvqtaB8oL7KIyo,376
|
21
|
+
maleo/database/orm/models/mixins/timestamp.py,sha256=TWqBTBvgSxcPsK0m7ggVrkHqzlqCM-2Zox7TAwCxd0I,1500
|
22
|
+
maleo_database-0.0.5.dist-info/licenses/LICENSE,sha256=aftGsecnk7TWVX-7KW94FqK4Syy6YSZ8PZEF7EcIp3M,2621
|
23
|
+
maleo_database-0.0.5.dist-info/METADATA,sha256=jJA0Q6OB2E4HLojFg_lrvGHRyHQhYH4YFmWsKuUplEo,3836
|
24
|
+
maleo_database-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
25
|
+
maleo_database-0.0.5.dist-info/top_level.txt,sha256=3Tpd1siVsfYoeI9FEOJNYnffx_shzZ3wsPpTvz5bljc,6
|
26
|
+
maleo_database-0.0.5.dist-info/RECORD,,
|
File without changes
|
@@ -1,66 +0,0 @@
|
|
1
|
-
from elasticsearch import AsyncElasticsearch, Elasticsearch
|
2
|
-
from typing import Literal, Union, overload
|
3
|
-
from ...config import ElasticsearchDatabaseConfig
|
4
|
-
from ...enums import Connection
|
5
|
-
|
6
|
-
|
7
|
-
class ElasticsearchClientManager:
|
8
|
-
def __init__(self, config: ElasticsearchDatabaseConfig) -> None:
|
9
|
-
self.config = config
|
10
|
-
self._async_client: AsyncElasticsearch = self._init(Connection.ASYNC)
|
11
|
-
self._sync_client: Elasticsearch = self._init(Connection.SYNC)
|
12
|
-
|
13
|
-
@overload
|
14
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncElasticsearch: ...
|
15
|
-
@overload
|
16
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> Elasticsearch: ...
|
17
|
-
def _init(
|
18
|
-
self, connection: Connection = Connection.ASYNC
|
19
|
-
) -> Union[AsyncElasticsearch, Elasticsearch]:
|
20
|
-
hosts = [
|
21
|
-
{"host": self.config.connection.host, "port": self.config.connection.port}
|
22
|
-
]
|
23
|
-
|
24
|
-
# Build auth and pooling params properly
|
25
|
-
client_kwargs = {}
|
26
|
-
|
27
|
-
if self.config.connection.username and self.config.connection.password:
|
28
|
-
client_kwargs["http_auth"] = (
|
29
|
-
self.config.connection.username,
|
30
|
-
self.config.connection.password,
|
31
|
-
)
|
32
|
-
|
33
|
-
# Use pooling config directly
|
34
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
35
|
-
exclude={
|
36
|
-
"connections_per_node",
|
37
|
-
"block",
|
38
|
-
"headers",
|
39
|
-
"dead_timeout",
|
40
|
-
}, # ES-specific excludes
|
41
|
-
exclude_none=True,
|
42
|
-
)
|
43
|
-
client_kwargs.update(pooling_kwargs)
|
44
|
-
|
45
|
-
if connection is Connection.ASYNC:
|
46
|
-
self._async_client = AsyncElasticsearch(hosts, **client_kwargs)
|
47
|
-
return self._async_client
|
48
|
-
else:
|
49
|
-
self._sync_client = Elasticsearch(hosts, **client_kwargs)
|
50
|
-
return self._sync_client
|
51
|
-
|
52
|
-
@overload
|
53
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncElasticsearch: ...
|
54
|
-
@overload
|
55
|
-
def get(self, connection: Literal[Connection.SYNC]) -> Elasticsearch: ...
|
56
|
-
def get(
|
57
|
-
self, connection: Connection = Connection.ASYNC
|
58
|
-
) -> Union[AsyncElasticsearch, Elasticsearch]:
|
59
|
-
if connection is Connection.ASYNC:
|
60
|
-
return self._async_client or self._init(Connection.ASYNC)
|
61
|
-
else:
|
62
|
-
return self._sync_client or self._init(Connection.SYNC)
|
63
|
-
|
64
|
-
async def dispose(self):
|
65
|
-
await self._async_client.close()
|
66
|
-
self._sync_client.close()
|
@@ -1,53 +0,0 @@
|
|
1
|
-
from motor.motor_asyncio import AsyncIOMotorClient
|
2
|
-
from pymongo import MongoClient
|
3
|
-
from typing import Literal, Union, overload
|
4
|
-
from ...config import MongoDBDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class MongoDBClientManager:
|
9
|
-
def __init__(self, config: MongoDBDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_client: AsyncIOMotorClient = self._init(Connection.ASYNC)
|
12
|
-
self._sync_client: MongoClient = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncIOMotorClient: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> MongoClient: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncIOMotorClient, MongoClient]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
24
|
-
by_alias=True, exclude_none=True
|
25
|
-
)
|
26
|
-
|
27
|
-
if connection is Connection.ASYNC:
|
28
|
-
self._async_client = AsyncIOMotorClient(url, **pooling_kwargs)
|
29
|
-
return self._async_client
|
30
|
-
else:
|
31
|
-
self._sync_client = MongoClient(url, **pooling_kwargs)
|
32
|
-
return self._sync_client
|
33
|
-
|
34
|
-
@overload
|
35
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncIOMotorClient: ...
|
36
|
-
@overload
|
37
|
-
def get(self, connection: Literal[Connection.SYNC]) -> MongoClient: ...
|
38
|
-
def get(
|
39
|
-
self, connection: Connection = Connection.ASYNC
|
40
|
-
) -> Union[AsyncIOMotorClient, MongoClient]:
|
41
|
-
if connection is Connection.ASYNC:
|
42
|
-
return self._async_client
|
43
|
-
elif connection is Connection.SYNC:
|
44
|
-
return self._sync_client
|
45
|
-
|
46
|
-
def get_database(self, connection: Connection = Connection.ASYNC):
|
47
|
-
"""Get the specific database object."""
|
48
|
-
client = self.get(connection)
|
49
|
-
return client[self.config.connection.database]
|
50
|
-
|
51
|
-
async def dispose(self):
|
52
|
-
self._async_client.close()
|
53
|
-
self._sync_client.close()
|
@@ -1,57 +0,0 @@
|
|
1
|
-
from redis.asyncio import Redis as AsyncRedis
|
2
|
-
from redis import Redis as SyncRedis
|
3
|
-
from typing import Literal, Union, overload
|
4
|
-
from ...config import RedisDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class RedisClientManager:
|
9
|
-
def __init__(self, config: RedisDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_client: AsyncRedis = self._init(Connection.ASYNC)
|
12
|
-
self._sync_client: SyncRedis = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncRedis: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> SyncRedis: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncRedis, SyncRedis]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
# Redis clients expect different parameter names
|
24
|
-
pooling_config = self.config.pooling.model_dump(exclude_none=True)
|
25
|
-
redis_kwargs = {
|
26
|
-
"max_connections": pooling_config.get("max_connections"),
|
27
|
-
"retry_on_timeout": pooling_config.get("retry_on_timeout"),
|
28
|
-
"connection_timeout": pooling_config.get("connection_timeout"),
|
29
|
-
"socket_timeout": pooling_config.get("socket_timeout"),
|
30
|
-
"socket_keepalive": pooling_config.get("socket_keepalive"),
|
31
|
-
"decode_responses": pooling_config.get("decode_responses"),
|
32
|
-
# health_check_interval doesn't apply to from_url method
|
33
|
-
}
|
34
|
-
redis_kwargs = {k: v for k, v in redis_kwargs.items() if v is not None}
|
35
|
-
|
36
|
-
if connection is Connection.ASYNC:
|
37
|
-
self._async_client = AsyncRedis.from_url(url, **redis_kwargs)
|
38
|
-
return self._async_client
|
39
|
-
else:
|
40
|
-
self._sync_client = SyncRedis.from_url(url, **redis_kwargs)
|
41
|
-
return self._sync_client
|
42
|
-
|
43
|
-
@overload
|
44
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncRedis: ...
|
45
|
-
@overload
|
46
|
-
def get(self, connection: Literal[Connection.SYNC]) -> SyncRedis: ...
|
47
|
-
def get(
|
48
|
-
self, connection: Connection = Connection.ASYNC
|
49
|
-
) -> Union[AsyncRedis, SyncRedis]:
|
50
|
-
if connection is Connection.ASYNC:
|
51
|
-
return self._async_client
|
52
|
-
elif connection is Connection.SYNC:
|
53
|
-
return self._sync_client
|
54
|
-
|
55
|
-
async def dispose(self):
|
56
|
-
await self._async_client.close()
|
57
|
-
self._sync_client.close()
|
File without changes
|
@@ -1,56 +0,0 @@
|
|
1
|
-
from sqlalchemy.engine import create_engine, Engine
|
2
|
-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
3
|
-
from typing import Literal, Tuple, Union, overload
|
4
|
-
from ...config import MySQLDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class MySQLEngineManager:
|
9
|
-
def __init__(self, config: MySQLDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_engine: AsyncEngine = self._init(Connection.ASYNC)
|
12
|
-
self._sync_engine: Engine = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncEngine, Engine]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
24
|
-
exclude={
|
25
|
-
"strategy"
|
26
|
-
}, # autocommit and connect_timeout are valid SQLAlchemy params
|
27
|
-
exclude_none=True,
|
28
|
-
)
|
29
|
-
|
30
|
-
engine_kwargs = {"echo": self.config.connection.echo, **pooling_kwargs}
|
31
|
-
|
32
|
-
if connection is Connection.ASYNC:
|
33
|
-
self._async_engine = create_async_engine(url, **engine_kwargs)
|
34
|
-
return self._async_engine
|
35
|
-
elif connection is Connection.SYNC:
|
36
|
-
self._sync_engine = create_engine(url, **engine_kwargs)
|
37
|
-
return self._sync_engine
|
38
|
-
|
39
|
-
@overload
|
40
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
41
|
-
@overload
|
42
|
-
def get(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
43
|
-
def get(
|
44
|
-
self, connection: Connection = Connection.ASYNC
|
45
|
-
) -> Union[AsyncEngine, Engine]:
|
46
|
-
if connection is Connection.ASYNC:
|
47
|
-
return self._async_engine
|
48
|
-
elif connection is Connection.SYNC:
|
49
|
-
return self._sync_engine
|
50
|
-
|
51
|
-
def get_all(self) -> Tuple[AsyncEngine, Engine]:
|
52
|
-
return (self._async_engine, self._sync_engine)
|
53
|
-
|
54
|
-
async def dispose(self):
|
55
|
-
await self._async_engine.dispose()
|
56
|
-
self._sync_engine.dispose()
|
@@ -1,58 +0,0 @@
|
|
1
|
-
from sqlalchemy.engine import create_engine, Engine
|
2
|
-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
3
|
-
from typing import Literal, Tuple, Union, overload
|
4
|
-
from ...config import PostgreSQLDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class PostgreSQLEngineManager:
|
9
|
-
def __init__(self, config: PostgreSQLDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_engine: AsyncEngine = self._init(Connection.ASYNC)
|
12
|
-
self._sync_engine: Engine = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncEngine, Engine]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
24
|
-
exclude={
|
25
|
-
"strategy",
|
26
|
-
"prepared_statement_cache_size",
|
27
|
-
"pool_reset_on_return",
|
28
|
-
},
|
29
|
-
exclude_none=True,
|
30
|
-
)
|
31
|
-
|
32
|
-
engine_kwargs = {"echo": self.config.connection.echo, **pooling_kwargs}
|
33
|
-
|
34
|
-
if connection is Connection.ASYNC:
|
35
|
-
self._async_engine = create_async_engine(url, **engine_kwargs)
|
36
|
-
return self._async_engine
|
37
|
-
elif connection is Connection.SYNC:
|
38
|
-
self._sync_engine = create_engine(url, **engine_kwargs)
|
39
|
-
return self._sync_engine
|
40
|
-
|
41
|
-
@overload
|
42
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
43
|
-
@overload
|
44
|
-
def get(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
45
|
-
def get(
|
46
|
-
self, connection: Connection = Connection.ASYNC
|
47
|
-
) -> Union[AsyncEngine, Engine]:
|
48
|
-
if connection is Connection.ASYNC:
|
49
|
-
return self._async_engine
|
50
|
-
elif connection is Connection.SYNC:
|
51
|
-
return self._sync_engine
|
52
|
-
|
53
|
-
def get_all(self) -> Tuple[AsyncEngine, Engine]:
|
54
|
-
return (self._async_engine, self._sync_engine)
|
55
|
-
|
56
|
-
async def dispose(self):
|
57
|
-
await self._async_engine.dispose()
|
58
|
-
self._sync_engine.dispose()
|
@@ -1,55 +0,0 @@
|
|
1
|
-
from sqlalchemy.engine import create_engine, Engine
|
2
|
-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
3
|
-
from typing import Literal, Tuple, Union, overload
|
4
|
-
from ...config import SQLiteDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class SQLiteEngineManager:
|
9
|
-
def __init__(self, config: SQLiteDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_engine: AsyncEngine = self._init(Connection.ASYNC)
|
12
|
-
self._sync_engine: Engine = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncEngine, Engine]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
# SQLite pooling is limited, most params don't apply
|
24
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
25
|
-
exclude={"wal_mode", "busy_timeout"}, # These go in URL options
|
26
|
-
exclude_none=True,
|
27
|
-
)
|
28
|
-
|
29
|
-
engine_kwargs = {"echo": self.config.connection.echo, **pooling_kwargs}
|
30
|
-
|
31
|
-
if connection is Connection.ASYNC:
|
32
|
-
self._async_engine = create_async_engine(url, **engine_kwargs)
|
33
|
-
return self._async_engine
|
34
|
-
elif connection is Connection.SYNC:
|
35
|
-
self._sync_engine = create_engine(url, **engine_kwargs)
|
36
|
-
return self._sync_engine
|
37
|
-
|
38
|
-
@overload
|
39
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
40
|
-
@overload
|
41
|
-
def get(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
42
|
-
def get(
|
43
|
-
self, connection: Connection = Connection.ASYNC
|
44
|
-
) -> Union[AsyncEngine, Engine]:
|
45
|
-
if connection is Connection.ASYNC:
|
46
|
-
return self._async_engine
|
47
|
-
elif connection is Connection.SYNC:
|
48
|
-
return self._sync_engine
|
49
|
-
|
50
|
-
def get_all(self) -> Tuple[AsyncEngine, Engine]:
|
51
|
-
return (self._async_engine, self._sync_engine)
|
52
|
-
|
53
|
-
async def dispose(self):
|
54
|
-
await self._async_engine.dispose()
|
55
|
-
self._sync_engine.dispose()
|
@@ -1,63 +0,0 @@
|
|
1
|
-
from sqlalchemy.engine import create_engine, Engine
|
2
|
-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
3
|
-
from typing import Literal, Tuple, Union, overload
|
4
|
-
from ...config import SQLServerDatabaseConfig
|
5
|
-
from ...enums import Connection
|
6
|
-
|
7
|
-
|
8
|
-
class SQLServerEngineManager:
|
9
|
-
def __init__(self, config: SQLServerDatabaseConfig) -> None:
|
10
|
-
self.config = config
|
11
|
-
self._async_engine: AsyncEngine = self._init(Connection.ASYNC)
|
12
|
-
self._sync_engine: Engine = self._init(Connection.SYNC)
|
13
|
-
|
14
|
-
@overload
|
15
|
-
def _init(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
16
|
-
@overload
|
17
|
-
def _init(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
18
|
-
def _init(
|
19
|
-
self, connection: Connection = Connection.ASYNC
|
20
|
-
) -> Union[AsyncEngine, Engine]:
|
21
|
-
url = self.config.connection.make_url(connection)
|
22
|
-
|
23
|
-
pooling_kwargs = self.config.pooling.model_dump(
|
24
|
-
exclude={
|
25
|
-
"strategy",
|
26
|
-
"connection_timeout", # Goes in URL
|
27
|
-
"command_timeout", # Goes in URL
|
28
|
-
"packet_size", # Goes in URL
|
29
|
-
"trust_server_certificate", # Goes in URL
|
30
|
-
},
|
31
|
-
exclude_none=True,
|
32
|
-
)
|
33
|
-
|
34
|
-
engine_kwargs = {
|
35
|
-
"echo": self.config.connection.echo,
|
36
|
-
**pooling_kwargs, # This includes encrypt, which is valid
|
37
|
-
}
|
38
|
-
|
39
|
-
if connection is Connection.ASYNC:
|
40
|
-
self._async_engine = create_async_engine(url, **engine_kwargs)
|
41
|
-
return self._async_engine
|
42
|
-
elif connection is Connection.SYNC:
|
43
|
-
self._sync_engine = create_engine(url, **engine_kwargs)
|
44
|
-
return self._sync_engine
|
45
|
-
|
46
|
-
@overload
|
47
|
-
def get(self, connection: Literal[Connection.ASYNC]) -> AsyncEngine: ...
|
48
|
-
@overload
|
49
|
-
def get(self, connection: Literal[Connection.SYNC]) -> Engine: ...
|
50
|
-
def get(
|
51
|
-
self, connection: Connection = Connection.ASYNC
|
52
|
-
) -> Union[AsyncEngine, Engine]:
|
53
|
-
if connection is Connection.ASYNC:
|
54
|
-
return self._async_engine
|
55
|
-
elif connection is Connection.SYNC:
|
56
|
-
return self._sync_engine
|
57
|
-
|
58
|
-
def get_all(self) -> Tuple[AsyncEngine, Engine]:
|
59
|
-
return (self._async_engine, self._sync_engine)
|
60
|
-
|
61
|
-
async def dispose(self):
|
62
|
-
await self._async_engine.dispose()
|
63
|
-
self._sync_engine.dispose()
|
@@ -1,32 +0,0 @@
|
|
1
|
-
maleo/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
maleo/database/enums.py,sha256=vUPlePELTC30el9rUglQpc7ZYBVMKp3SiRHCZre9oQE,1693
|
3
|
-
maleo/database/config/__init__.py,sha256=IMRroPb10eWaWHbsl7Lr2ObS0v-5I7D1srqQ6y_0CIM,2416
|
4
|
-
maleo/database/config/additional.py,sha256=kCamg5Z_FfbZBq_06QwGOjee8wOrL1wTIVlO60xNqWU,1060
|
5
|
-
maleo/database/config/connection.py,sha256=lfnEE69355CNtPVlfoXaIu-IWiw4VPEkiY9tfqV6oZA,22379
|
6
|
-
maleo/database/config/identifier.py,sha256=b1MjhoKl3h7xJe1eVIj1wjvYH9BrjHzKnjzdjaEaTeQ,626
|
7
|
-
maleo/database/config/pooling.py,sha256=tVJTxFV-fSEp4xJEVVLkTHFhhKEClSTGDQw5_pqLZgo,9246
|
8
|
-
maleo/database/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
maleo/database/managers/session.py,sha256=2kfHOziwnjyQVNAskQ2LLx2xbrCcnxb760T5yP1xXM0,10054
|
10
|
-
maleo/database/managers/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
maleo/database/managers/clients/elasticsearch.py,sha256=2US-S26N2o61iGwZZ8L0baYU7cXzJ8yFKmYFCHZ9sg0,2471
|
12
|
-
maleo/database/managers/clients/mongodb.py,sha256=h20IW1BDvZWBH-XH1U_8quoNMBDV44uyg3AAS2vIXoA,2012
|
13
|
-
maleo/database/managers/clients/redis.py,sha256=_l_4Y5sivpRwquK_qA37cTNirld6zc_YkLKJEDo-p3c,2387
|
14
|
-
maleo/database/managers/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
maleo/database/managers/engines/mysql.py,sha256=_Fp7K04ZO3Wacr4ItyPBUFnk0TGT0qTIn6kBYA_p6xw,2120
|
16
|
-
maleo/database/managers/engines/postgresql.py,sha256=3JS4tqYtu3IIrGpKdMbGoHoUPuUxIm71lJqeL6vkICY,2163
|
17
|
-
maleo/database/managers/engines/sqlite.py,sha256=YDDMzP47yIICPqEnNJjkFr1w5WJyB1TQswT-FGyKLoE,2135
|
18
|
-
maleo/database/managers/engines/sqlserver.py,sha256=FX8bJYd3XSvAM5bnjmkcL84-V4DjLXQvPmZh_oJazNM,2355
|
19
|
-
maleo/database/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
|
-
maleo/database/orm/base.py,sha256=qdRK_TQqDoZ1hANvm1mJDiblqFr77J1IhBnlENr7RK8,229
|
21
|
-
maleo/database/orm/queries.py,sha256=NX9PYT6GZgwIhtRc7WSTS9EUzqTZCb-ib99ccYjmUkM,7643
|
22
|
-
maleo/database/orm/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
|
-
maleo/database/orm/models/table.py,sha256=UhEH7WN1lrNY3uTb4a5VWO4l9UaYhnRQK_0Z7R0lMNA,457
|
24
|
-
maleo/database/orm/models/mixins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
|
-
maleo/database/orm/models/mixins/identifier.py,sha256=jICVsLUFw_f7TV_aX4KTTs_ycH35MRtRj5boTqctmZo,425
|
26
|
-
maleo/database/orm/models/mixins/status.py,sha256=Jzithn-Hl2ct1AqboGZSXrA35aaQEDvqtaB8oL7KIyo,376
|
27
|
-
maleo/database/orm/models/mixins/timestamp.py,sha256=TWqBTBvgSxcPsK0m7ggVrkHqzlqCM-2Zox7TAwCxd0I,1500
|
28
|
-
maleo_database-0.0.4.dist-info/licenses/LICENSE,sha256=aftGsecnk7TWVX-7KW94FqK4Syy6YSZ8PZEF7EcIp3M,2621
|
29
|
-
maleo_database-0.0.4.dist-info/METADATA,sha256=6572NXBgpEfF0HPa84hhEa9kwkYIrGnc3k8SKfLLcjk,3258
|
30
|
-
maleo_database-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
31
|
-
maleo_database-0.0.4.dist-info/top_level.txt,sha256=3Tpd1siVsfYoeI9FEOJNYnffx_shzZ3wsPpTvz5bljc,6
|
32
|
-
maleo_database-0.0.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|