SARepo 0.1.5__py3-none-any.whl → 0.1.6__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.
- SARepo/repo.py +1 -1
- SARepo/sa_repo.py +23 -6
- {sarepo-0.1.5.dist-info → sarepo-0.1.6.dist-info}/METADATA +1 -1
- sarepo-0.1.6.dist-info/RECORD +12 -0
- sarepo-0.1.5.dist-info/RECORD +0 -12
- {sarepo-0.1.5.dist-info → sarepo-0.1.6.dist-info}/WHEEL +0 -0
- {sarepo-0.1.5.dist-info → sarepo-0.1.6.dist-info}/licenses/LICENSE +0 -0
- {sarepo-0.1.5.dist-info → sarepo-0.1.6.dist-info}/top_level.txt +0 -0
SARepo/repo.py
CHANGED
@@ -13,7 +13,7 @@ class CrudRepository(Protocol, Generic[T]):
|
|
13
13
|
def try_get(self, id_: Any, *, include_deleted: bool = False) -> Optional[T]: ...
|
14
14
|
def add(self, entity: T) -> T: ...
|
15
15
|
def update(self, entity: T) -> T: ...
|
16
|
-
def remove(self, entity: T) ->
|
16
|
+
def remove(self, entity: Optional[T] = None, id: Optional[Any] = None) -> bool: ...
|
17
17
|
def delete_by_id(self, id_: Any) -> bool: ...
|
18
18
|
def page(self, page: PageRequest, spec: Optional[Spec] = None, order_by=None, *, include_deleted: bool = False) -> Page[T]: ...
|
19
19
|
def get_all_by_column(
|
SARepo/sa_repo.py
CHANGED
@@ -71,7 +71,13 @@ class SARepository(Generic[T]):
|
|
71
71
|
self.session.refresh(entity)
|
72
72
|
return entity
|
73
73
|
|
74
|
-
def remove(self, entity: T) ->
|
74
|
+
def remove(self, entity: Optional[T] = None, id: Optional[Any] = None) -> bool:
|
75
|
+
if entity is None and id is None:
|
76
|
+
raise ValueError("remove() requires either entity or id")
|
77
|
+
|
78
|
+
if id is not None:
|
79
|
+
return self._delete_by_id(id)
|
80
|
+
|
75
81
|
insp = inspect(entity, raiseerr=False)
|
76
82
|
if not (insp and (insp.persistent or insp.pending)):
|
77
83
|
pk = getattr(entity, "id", None)
|
@@ -79,13 +85,15 @@ class SARepository(Generic[T]):
|
|
79
85
|
raise ValueError("remove() needs a persistent entity or an entity with a primary key set")
|
80
86
|
entity = self.session.get(self.model, pk)
|
81
87
|
if entity is None:
|
82
|
-
return
|
88
|
+
return False
|
83
89
|
if hasattr(entity, "is_deleted"):
|
84
90
|
setattr(entity, "is_deleted", True)
|
85
91
|
else:
|
86
92
|
self.session.delete(entity)
|
93
|
+
|
94
|
+
return True
|
87
95
|
|
88
|
-
def
|
96
|
+
def _delete_by_id(self, id_: Any) -> bool:
|
89
97
|
obj = self.session.get(self.model, id_)
|
90
98
|
if not obj:
|
91
99
|
return False
|
@@ -283,7 +291,13 @@ class SAAsyncRepository(Generic[T]):
|
|
283
291
|
await self.session.refresh(entity)
|
284
292
|
return entity
|
285
293
|
|
286
|
-
async def remove(self, entity: T) ->
|
294
|
+
async def remove(self, entity: Optional[T] = None, id: Optional[Any] = None) -> bool:
|
295
|
+
if entity is None and id is None:
|
296
|
+
raise ValueError("remove() requires either entity or id")
|
297
|
+
|
298
|
+
if id is not None:
|
299
|
+
return await self._delete_by_id(id)
|
300
|
+
|
287
301
|
insp = inspect(entity, raiseerr=False)
|
288
302
|
if not (insp and (insp.persistent or insp.pending)):
|
289
303
|
pk = getattr(entity, "id", None)
|
@@ -291,13 +305,16 @@ class SAAsyncRepository(Generic[T]):
|
|
291
305
|
raise ValueError("remove() needs a persistent entity or an entity with a primary key set")
|
292
306
|
entity = await self.session.get(self.model, pk)
|
293
307
|
if entity is None:
|
294
|
-
return
|
308
|
+
return False
|
295
309
|
if hasattr(entity, "is_deleted"):
|
296
310
|
setattr(entity, "is_deleted", True)
|
297
311
|
else:
|
298
312
|
await self.session.delete(entity)
|
313
|
+
|
314
|
+
return True
|
299
315
|
|
300
|
-
|
316
|
+
|
317
|
+
async def _delete_by_id(self, id_: Any) -> bool:
|
301
318
|
obj = await self.session.get(self.model, id_)
|
302
319
|
if not obj:
|
303
320
|
return False
|
@@ -0,0 +1,12 @@
|
|
1
|
+
SARepo/__init__.py,sha256=tNYbuUDloC1qVnXq7uomS3jRcaPUvy0VEZiMdYR6x1M,183
|
2
|
+
SARepo/base.py,sha256=UbAdZ9WYh_o93mrCVL3D8Q0tY_8mvm0HspO_L5m0GTQ,874
|
3
|
+
SARepo/models.py,sha256=ypSmbKAijvNH4WjSeJBgyNT8mKa_e_7-I5kiNisjGAI,570
|
4
|
+
SARepo/repo.py,sha256=q99K9odCVuxJ9HIKwgVpu3p9-hyzxmGlE-wkiCp9tbg,1820
|
5
|
+
SARepo/sa_repo.py,sha256=iPJan94ALJ3N58aU1D6rgO6uhqLDUxcHXvORpQrAt9c,17258
|
6
|
+
SARepo/specs.py,sha256=e-X1cCkva3e71M37hcfbjNDMezZAaOkkRaPToUzhEeU,687
|
7
|
+
SARepo/uow.py,sha256=yPlvi7PoH9x2pLNt6hEin9zT5qG9axUKn_TkZcIuz1s,859
|
8
|
+
sarepo-0.1.6.dist-info/licenses/LICENSE,sha256=px90NOQCrnZ77qoFT8IvAiNS1CXQ2OU27uVBKbki9DM,131
|
9
|
+
sarepo-0.1.6.dist-info/METADATA,sha256=4Yfl0Eh0h8Sb2Lrs_DxZRfPJuZzGTg7-I9blRPva9aw,2691
|
10
|
+
sarepo-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
sarepo-0.1.6.dist-info/top_level.txt,sha256=0k952UYVZLIIv3kZzFlxI0yzBMusZo3-XCQtxms_kS0,7
|
12
|
+
sarepo-0.1.6.dist-info/RECORD,,
|
sarepo-0.1.5.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
SARepo/__init__.py,sha256=tNYbuUDloC1qVnXq7uomS3jRcaPUvy0VEZiMdYR6x1M,183
|
2
|
-
SARepo/base.py,sha256=UbAdZ9WYh_o93mrCVL3D8Q0tY_8mvm0HspO_L5m0GTQ,874
|
3
|
-
SARepo/models.py,sha256=ypSmbKAijvNH4WjSeJBgyNT8mKa_e_7-I5kiNisjGAI,570
|
4
|
-
SARepo/repo.py,sha256=N_LaqguNE3Y_9vZBPBvqQreu-6Sy9-BZFR3-pZl5eT4,1777
|
5
|
-
SARepo/sa_repo.py,sha256=iIscSTNoZGb8XMTY66_fiooWPVwGMOMYAL9BC_xS7bI,16691
|
6
|
-
SARepo/specs.py,sha256=e-X1cCkva3e71M37hcfbjNDMezZAaOkkRaPToUzhEeU,687
|
7
|
-
SARepo/uow.py,sha256=yPlvi7PoH9x2pLNt6hEin9zT5qG9axUKn_TkZcIuz1s,859
|
8
|
-
sarepo-0.1.5.dist-info/licenses/LICENSE,sha256=px90NOQCrnZ77qoFT8IvAiNS1CXQ2OU27uVBKbki9DM,131
|
9
|
-
sarepo-0.1.5.dist-info/METADATA,sha256=m9z_QHD-D1dN95nAGWvpFGAUT7hCad990Lb-nNS5two,2691
|
10
|
-
sarepo-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
-
sarepo-0.1.5.dist-info/top_level.txt,sha256=0k952UYVZLIIv3kZzFlxI0yzBMusZo3-XCQtxms_kS0,7
|
12
|
-
sarepo-0.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|