apexdevkit 1.8.7__tar.gz → 1.8.9__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.8.7 → apexdevkit-1.8.9}/PKG-INFO +1 -1
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/sqlite.py +11 -3
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/testing/fake.py +20 -2
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/pyproject.toml +1 -1
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/LICENSE +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/README.md +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/error.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.8.7 → apexdevkit-1.8.9}/apexdevkit/testing/rest.py +0 -0
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from sqlite3 import IntegrityError
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Generic, Iterator, TypeVar
|
|
6
6
|
|
|
7
7
|
from apexdevkit.error import DoesNotExistError, ExistsError
|
|
8
8
|
from apexdevkit.repository import Database, DatabaseCommand
|
|
@@ -14,7 +14,6 @@ ItemT = TypeVar("ItemT")
|
|
|
14
14
|
class SqliteRepository(Generic[ItemT]):
|
|
15
15
|
db: Database
|
|
16
16
|
table: SqlTable[ItemT]
|
|
17
|
-
duplicate_criteria: Callable[[ItemT], str] = lambda i: "Unknown"
|
|
18
17
|
|
|
19
18
|
def __iter__(self) -> Iterator[ItemT]:
|
|
20
19
|
for raw in self.db.execute(self.table.select_all()).fetch_all():
|
|
@@ -32,7 +31,10 @@ class SqliteRepository(Generic[ItemT]):
|
|
|
32
31
|
try:
|
|
33
32
|
return self.table.load(self.db.execute(self.table.insert(item)).fetch_one())
|
|
34
33
|
except IntegrityError: # pragma: no cover
|
|
35
|
-
|
|
34
|
+
item = self.table.load(
|
|
35
|
+
self.db.execute(self.table.select_duplicate(item)).fetch_one()
|
|
36
|
+
)
|
|
37
|
+
self.table.duplicate(item).fire()
|
|
36
38
|
return item
|
|
37
39
|
|
|
38
40
|
def create_many(self, items: list[ItemT]) -> list[ItemT]:
|
|
@@ -70,6 +72,9 @@ class SqlTable(Generic[ItemT]): # pragma: no cover
|
|
|
70
72
|
def select(self, item_id: str) -> DatabaseCommand:
|
|
71
73
|
raise NotImplementedError("Not implemented")
|
|
72
74
|
|
|
75
|
+
def select_duplicate(self, item: ItemT) -> DatabaseCommand:
|
|
76
|
+
raise NotImplementedError("Not implemented")
|
|
77
|
+
|
|
73
78
|
def select_all(self) -> DatabaseCommand:
|
|
74
79
|
raise NotImplementedError("Not implemented")
|
|
75
80
|
|
|
@@ -85,6 +90,9 @@ class SqlTable(Generic[ItemT]): # pragma: no cover
|
|
|
85
90
|
def load(self, data: dict[str, Any]) -> ItemT:
|
|
86
91
|
raise NotImplementedError("Not implemented")
|
|
87
92
|
|
|
93
|
+
def duplicate(self, item: ItemT) -> ExistsError:
|
|
94
|
+
return ExistsError(item).with_duplicate(lambda i: "Unknown")
|
|
95
|
+
|
|
88
96
|
|
|
89
97
|
@dataclass
|
|
90
98
|
class UnknownError(Exception):
|
|
@@ -19,8 +19,8 @@ class Fake:
|
|
|
19
19
|
def text(self, *, length: int) -> str:
|
|
20
20
|
return "".join(self.faker.random_letters(length=length))
|
|
21
21
|
|
|
22
|
-
def number(self) -> int:
|
|
23
|
-
return int(self.faker.random.randint(0,
|
|
22
|
+
def number(self, top: int = 100000) -> int:
|
|
23
|
+
return int(self.faker.random.randint(0, top))
|
|
24
24
|
|
|
25
25
|
def timestamp(self) -> int:
|
|
26
26
|
return int(self.faker.unix_time())
|
|
@@ -31,6 +31,24 @@ class Fake:
|
|
|
31
31
|
def hour(self) -> int:
|
|
32
32
|
return int(self.faker.random_int(min=0, max=23))
|
|
33
33
|
|
|
34
|
+
def first_name(self) -> str:
|
|
35
|
+
return str(self.faker.first_name())
|
|
36
|
+
|
|
37
|
+
def last_name(self) -> str:
|
|
38
|
+
return str(self.faker.last_name())
|
|
39
|
+
|
|
40
|
+
def sentence(self, *, words: int) -> str:
|
|
41
|
+
return str(self.faker.sentence(nb_words=words))
|
|
42
|
+
|
|
43
|
+
def country(self) -> str:
|
|
44
|
+
return str(self.faker.country())
|
|
45
|
+
|
|
46
|
+
def address(self) -> str:
|
|
47
|
+
return str(self.faker.address())
|
|
48
|
+
|
|
49
|
+
def bool(self) -> bool:
|
|
50
|
+
return bool(self.faker.boolean())
|
|
51
|
+
|
|
34
52
|
|
|
35
53
|
@dataclass
|
|
36
54
|
class FakeResource(Generic[ItemT]):
|
|
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
|