apexdevkit 1.9.6__tar.gz → 1.9.8__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.
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/PKG-INFO +1 -1
- apexdevkit-1.9.8/apexdevkit/repository/decorator.py +36 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/mongo.py +29 -53
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/pyproject.toml +1 -1
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/LICENSE +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/README.md +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/error.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.9.6 → apexdevkit-1.9.8}/apexdevkit/testing/rest.py +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Generic, Iterator, TypeVar
|
|
3
|
+
|
|
4
|
+
from apexdevkit.repository import Repository
|
|
5
|
+
|
|
6
|
+
ItemT = TypeVar("ItemT")
|
|
7
|
+
IdT = TypeVar("IdT", contravariant=True)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class RepositoryDecorator(Generic[IdT, ItemT]):
|
|
12
|
+
inner: Repository[IdT, ItemT]
|
|
13
|
+
|
|
14
|
+
def create(self, item: ItemT) -> ItemT:
|
|
15
|
+
return self.inner.create(item)
|
|
16
|
+
|
|
17
|
+
def create_many(self, items: list[ItemT]) -> list[ItemT]:
|
|
18
|
+
return self.inner.create_many(items)
|
|
19
|
+
|
|
20
|
+
def read(self, item_id: IdT) -> ItemT:
|
|
21
|
+
return self.inner.read(item_id)
|
|
22
|
+
|
|
23
|
+
def update(self, item: ItemT) -> None:
|
|
24
|
+
self.inner.update(item)
|
|
25
|
+
|
|
26
|
+
def update_many(self, items: list[ItemT]) -> None:
|
|
27
|
+
self.inner.update_many(items)
|
|
28
|
+
|
|
29
|
+
def delete(self, item_id: IdT) -> None:
|
|
30
|
+
self.inner.delete(item_id)
|
|
31
|
+
|
|
32
|
+
def __iter__(self) -> Iterator[ItemT]:
|
|
33
|
+
return self.inner.__iter__()
|
|
34
|
+
|
|
35
|
+
def __len__(self) -> int:
|
|
36
|
+
return self.inner.__len__()
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, ContextManager,
|
|
4
|
+
from typing import Any, ContextManager, Generic, Iterator, Protocol, TypeVar
|
|
5
5
|
|
|
6
6
|
from pymongo import MongoClient, ReturnDocument
|
|
7
7
|
from pymongo.collection import Collection
|
|
8
|
-
from pymongo.results import DeleteResult, InsertOneResult
|
|
9
8
|
|
|
10
9
|
from apexdevkit.error import DoesNotExistError, ExistsError
|
|
11
10
|
from apexdevkit.formatter import Formatter
|
|
@@ -22,15 +21,22 @@ ItemT = TypeVar("ItemT", bound=_Item)
|
|
|
22
21
|
|
|
23
22
|
@dataclass
|
|
24
23
|
class MongoRepository(Generic[ItemT]):
|
|
25
|
-
|
|
24
|
+
connector: MongoConnector
|
|
25
|
+
database_name: str
|
|
26
|
+
collection_name: str
|
|
26
27
|
formatter: Formatter[dict[str, Any], ItemT]
|
|
27
28
|
|
|
29
|
+
def collection(self, client: MongoClient[Any]) -> Collection[Any]:
|
|
30
|
+
return client[self.database_name][self.collection_name]
|
|
31
|
+
|
|
28
32
|
def __iter__(self) -> Iterator[ItemT]:
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
with self.connector.connect() as client:
|
|
34
|
+
for raw in self.collection(client).find():
|
|
35
|
+
yield self.formatter.load(raw)
|
|
31
36
|
|
|
32
37
|
def __len__(self) -> int:
|
|
33
|
-
|
|
38
|
+
with self.connector.connect() as client:
|
|
39
|
+
return self.collection(client).count_documents({})
|
|
34
40
|
|
|
35
41
|
def create(self, item: ItemT) -> ItemT:
|
|
36
42
|
try:
|
|
@@ -39,70 +45,40 @@ class MongoRepository(Generic[ItemT]):
|
|
|
39
45
|
lambda i: f"_Item with id<{i.id}> already exists."
|
|
40
46
|
)
|
|
41
47
|
except DoesNotExistError:
|
|
42
|
-
self.
|
|
43
|
-
|
|
48
|
+
with self.connector.connect() as client:
|
|
49
|
+
self.collection(client).insert_one(self.formatter.dump(item))
|
|
50
|
+
return item
|
|
44
51
|
|
|
45
52
|
def create_many(self, items: list[ItemT]) -> list[ItemT]:
|
|
46
53
|
return [self.create(item) for item in items]
|
|
47
54
|
|
|
48
55
|
def read(self, item_id: str) -> ItemT:
|
|
49
|
-
|
|
56
|
+
with self.connector.connect() as client:
|
|
57
|
+
raw = self.collection(client).find_one({"id": item_id})
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
if not raw:
|
|
60
|
+
raise DoesNotExistError(item_id)
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
return self.formatter.load(dict(raw))
|
|
55
63
|
|
|
56
64
|
def update(self, item: ItemT) -> None:
|
|
57
|
-
|
|
65
|
+
with self.connector.connect() as client:
|
|
66
|
+
self.collection(client).find_one_and_update(
|
|
67
|
+
{"id": item.id},
|
|
68
|
+
{"$set": self.formatter.dump(item)},
|
|
69
|
+
return_document=ReturnDocument.AFTER,
|
|
70
|
+
)
|
|
58
71
|
|
|
59
72
|
def update_many(self, items: list[ItemT]) -> None:
|
|
60
73
|
for item in items:
|
|
61
74
|
self.update(item)
|
|
62
75
|
|
|
63
76
|
def delete(self, item_id: str) -> None:
|
|
64
|
-
result = self.database.delete(item_id)
|
|
65
|
-
if result.deleted_count == 0:
|
|
66
|
-
raise DoesNotExistError(item_id)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@dataclass
|
|
70
|
-
class MongoDatabase:
|
|
71
|
-
connector: MongoConnector
|
|
72
|
-
database_name: str
|
|
73
|
-
collection_name: str
|
|
74
|
-
|
|
75
|
-
def collection(self, client: MongoClient[Any]) -> Collection[Any]:
|
|
76
|
-
return client[self.database_name][self.collection_name]
|
|
77
|
-
|
|
78
|
-
def __iter__(self) -> Iterator[Any]:
|
|
79
77
|
with self.connector.connect() as client:
|
|
80
|
-
|
|
81
|
-
yield raw
|
|
82
|
-
|
|
83
|
-
def __len__(self) -> int:
|
|
84
|
-
with self.connector.connect() as client:
|
|
85
|
-
return self.collection(client).count_documents({})
|
|
78
|
+
result = self.collection(client).delete_one({"id": item_id})
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return self.collection(client).insert_one(item)
|
|
90
|
-
|
|
91
|
-
def read(self, item_id: str) -> Dict[str, Any] | None:
|
|
92
|
-
with self.connector.connect() as client:
|
|
93
|
-
return self.collection(client).find_one({"id": item_id})
|
|
94
|
-
|
|
95
|
-
def update(self, item_id: str, item: Dict[str, Any]) -> Any:
|
|
96
|
-
with self.connector.connect() as client:
|
|
97
|
-
return self.collection(client).find_one_and_update(
|
|
98
|
-
{"id": item_id},
|
|
99
|
-
{"$set": item},
|
|
100
|
-
return_document=ReturnDocument.AFTER,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
def delete(self, item_id: str) -> DeleteResult:
|
|
104
|
-
with self.connector.connect() as client:
|
|
105
|
-
return self.collection(client).delete_one({"id": item_id})
|
|
80
|
+
if result.deleted_count == 0:
|
|
81
|
+
raise DoesNotExistError(item_id)
|
|
106
82
|
|
|
107
83
|
|
|
108
84
|
class MongoConnector(Protocol): # pragma: no cover
|
|
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
|
|
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
|
|
File without changes
|