2727# Software is furnished to do so, subject to the following conditions:
2828#
2929#
30- from abc import ABC , abstractmethod
3130from typing import (
3231 Any ,
33- Generic ,
3432 Iterable ,
3533 List ,
3634 Literal ,
3735 Mapping ,
36+ Protocol ,
3837 Tuple ,
3938 Union ,
4039)
4847)
4948
5049
51- class SQLAlchemyAsyncRepositoryInterface (Generic [MODEL ], ABC ):
52- @abstractmethod
50+ class SQLAlchemyAsyncRepositoryInterface (Protocol [MODEL ]):
5351 async def get (self , identifier : PRIMARY_KEY ) -> MODEL :
5452 """Get a model by primary key.
5553
@@ -59,7 +57,6 @@ async def get(self, identifier: PRIMARY_KEY) -> MODEL:
5957 """
6058 ...
6159
62- @abstractmethod
6360 async def get_many (self , identifiers : Iterable [PRIMARY_KEY ]) -> List [MODEL ]:
6461 """Get a list of models by primary keys.
6562
@@ -68,7 +65,6 @@ async def get_many(self, identifiers: Iterable[PRIMARY_KEY]) -> List[MODEL]:
6865 """
6966 ...
7067
71- @abstractmethod
7268 async def save (self , instance : MODEL ) -> MODEL :
7369 """Persist a model.
7470
@@ -77,7 +73,6 @@ async def save(self, instance: MODEL) -> MODEL:
7773 """
7874 ...
7975
80- @abstractmethod
8176 async def save_many (self , instances : Iterable [MODEL ]) -> Iterable [MODEL ]:
8277 """Persist many models in a single database get_session.
8378
@@ -86,23 +81,20 @@ async def save_many(self, instances: Iterable[MODEL]) -> Iterable[MODEL]:
8681 """
8782 ...
8883
89- @abstractmethod
9084 async def delete (self , instance : MODEL ) -> None :
9185 """Deletes a model.
9286
9387 :param instance: The model instance
9488 """
9589 ...
9690
97- @abstractmethod
9891 async def delete_many (self , instances : Iterable [MODEL ]) -> None :
9992 """Deletes a collection of models in a single transaction.
10093
10194 :param instances: The model instances
10295 """
10396 ...
10497
105- @abstractmethod
10698 async def find (
10799 self ,
108100 search_params : Union [None , Mapping [str , Any ]] = None ,
@@ -130,7 +122,6 @@ async def find(
130122 """
131123 ...
132124
133- @abstractmethod
134125 async def paginated_find (
135126 self ,
136127 items_per_page : int ,
@@ -169,7 +160,6 @@ async def paginated_find(
169160 """
170161 ...
171162
172- @abstractmethod
173163 async def cursor_paginated_find (
174164 self ,
175165 items_per_page : int ,
@@ -205,8 +195,7 @@ async def cursor_paginated_find(
205195 ...
206196
207197
208- class SQLAlchemyRepositoryInterface (Generic [MODEL ], ABC ):
209- @abstractmethod
198+ class SQLAlchemyRepositoryInterface (Protocol [MODEL ]):
210199 def get (self , identifier : PRIMARY_KEY ) -> MODEL :
211200 """Get a model by primary key.
212201
@@ -216,7 +205,6 @@ def get(self, identifier: PRIMARY_KEY) -> MODEL:
216205 """
217206 ...
218207
219- @abstractmethod
220208 def get_many (self , identifiers : Iterable [PRIMARY_KEY ]) -> List [MODEL ]:
221209 """Get a list of models by primary keys.
222210
@@ -225,7 +213,6 @@ def get_many(self, identifiers: Iterable[PRIMARY_KEY]) -> List[MODEL]:
225213 """
226214 ...
227215
228- @abstractmethod
229216 def save (self , instance : MODEL ) -> MODEL :
230217 """Persist a model.
231218
@@ -234,7 +221,6 @@ def save(self, instance: MODEL) -> MODEL:
234221 """
235222 ...
236223
237- @abstractmethod
238224 def save_many (self , instances : Iterable [MODEL ]) -> Iterable [MODEL ]:
239225 """Persist many models in a single database get_session.
240226
@@ -243,23 +229,20 @@ def save_many(self, instances: Iterable[MODEL]) -> Iterable[MODEL]:
243229 """
244230 ...
245231
246- @abstractmethod
247232 def delete (self , instance : MODEL ) -> None :
248233 """Deletes a model.
249234
250235 :param instance: The model instance
251236 """
252237 ...
253238
254- @abstractmethod
255239 def delete_many (self , instances : Iterable [MODEL ]) -> None :
256240 """Deletes a collection of models in a single transaction.
257241
258242 :param instances: The model instances
259243 """
260244 ...
261245
262- @abstractmethod
263246 def find (
264247 self ,
265248 search_params : Union [None , Mapping [str , Any ]] = None ,
@@ -287,7 +270,6 @@ def find(
287270 """
288271 ...
289272
290- @abstractmethod
291273 def paginated_find (
292274 self ,
293275 items_per_page : int ,
@@ -326,7 +308,6 @@ def paginated_find(
326308 """
327309 ...
328310
329- @abstractmethod
330311 def cursor_paginated_find (
331312 self ,
332313 items_per_page : int ,
0 commit comments