SARepo 0.1.2__tar.gz → 0.1.3__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.
- {sarepo-0.1.2 → sarepo-0.1.3}/PKG-INFO +1 -1
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/repo.py +1 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/sa_repo.py +31 -1
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo.egg-info/PKG-INFO +1 -1
- {sarepo-0.1.2 → sarepo-0.1.3}/pyproject.toml +1 -1
- {sarepo-0.1.2 → sarepo-0.1.3}/LICENSE +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/README.md +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/__init__.py +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/base.py +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/models.py +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/specs.py +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo/uow.py +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo.egg-info/SOURCES.txt +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo.egg-info/dependency_links.txt +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo.egg-info/requires.txt +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/SARepo.egg-info/top_level.txt +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/setup.cfg +0 -0
- {sarepo-0.1.2 → sarepo-0.1.3}/tests/test_sync_basic.py +0 -0
@@ -12,4 +12,5 @@ class CrudRepository(Protocol, Generic[T]):
|
|
12
12
|
def add(self, entity: T) -> T: ...
|
13
13
|
def update(self, entity: T) -> T: ...
|
14
14
|
def remove(self, entity: T) -> None: ...
|
15
|
+
def delete_by_id(self, id_: Any) -> bool: ...
|
15
16
|
def page(self, page: PageRequest, spec=None, order_by=None) -> Page[T]: ...
|
@@ -2,7 +2,7 @@
|
|
2
2
|
from typing import List, Type, Generic, TypeVar, Optional, Sequence, Any, Callable
|
3
3
|
from sqlalchemy.orm import Session
|
4
4
|
from sqlalchemy.ext.asyncio import AsyncSession
|
5
|
-
from sqlalchemy import select, func
|
5
|
+
from sqlalchemy import inspect, select, func
|
6
6
|
from .base import PageRequest, Page, NotFoundError
|
7
7
|
|
8
8
|
T = TypeVar("T")
|
@@ -45,11 +45,26 @@ class SARepository(Generic[T]):
|
|
45
45
|
return entity
|
46
46
|
|
47
47
|
def remove(self, entity: T) -> None:
|
48
|
+
insp = inspect(entity, raiseerr=False)
|
49
|
+
if not (insp and (insp.persistent or insp.pending)):
|
50
|
+
pk = getattr(entity, "id", None)
|
51
|
+
if pk is None:
|
52
|
+
raise ValueError("remove() needs a persistent entity or an entity with a primary key set")
|
53
|
+
entity = self.session.get(self.model, pk)
|
54
|
+
if entity is None:
|
55
|
+
return
|
48
56
|
if hasattr(entity, "is_deleted"):
|
49
57
|
setattr(entity, "is_deleted", True)
|
50
58
|
else:
|
51
59
|
self.session.delete(entity)
|
52
60
|
|
61
|
+
def delete_by_id(self, id_: Any) -> bool:
|
62
|
+
obj = self.session.get(self.model, id_)
|
63
|
+
if not obj:
|
64
|
+
return False
|
65
|
+
self.remove(obj)
|
66
|
+
return True
|
67
|
+
|
53
68
|
def page(self, page: PageRequest, spec: Optional[Spec] = None, order_by=None) -> Page[T]:
|
54
69
|
stmt = self._select()
|
55
70
|
if spec:
|
@@ -101,11 +116,26 @@ class SAAsyncRepository(Generic[T]):
|
|
101
116
|
return entity
|
102
117
|
|
103
118
|
async def remove(self, entity: T) -> None:
|
119
|
+
insp = inspect(entity, raiseerr=False)
|
120
|
+
if not (insp and (insp.persistent or insp.pending)):
|
121
|
+
pk = getattr(entity, "id", None)
|
122
|
+
if pk is None:
|
123
|
+
raise ValueError("remove() needs a persistent entity or an entity with a primary key set")
|
124
|
+
entity = await self.session.get(self.model, pk)
|
125
|
+
if entity is None:
|
126
|
+
return
|
104
127
|
if hasattr(entity, "is_deleted"):
|
105
128
|
setattr(entity, "is_deleted", True)
|
106
129
|
else:
|
107
130
|
await self.session.delete(entity)
|
108
131
|
|
132
|
+
async def delete_by_id(self, id_: Any) -> bool:
|
133
|
+
obj = await self.session.get(self.model, id_)
|
134
|
+
if not obj:
|
135
|
+
return False
|
136
|
+
await self.remove(obj)
|
137
|
+
return True
|
138
|
+
|
109
139
|
async def page(self, page: PageRequest, spec: Optional[Spec] = None, order_by=None) -> Page[T]:
|
110
140
|
stmt = self._select()
|
111
141
|
if spec:
|
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
|