@@ -65,11 +65,6 @@ async def _get_session(self, commit: bool = True) -> AsyncIterator[AsyncSession]
6565 yield self ._external_session
6666
6767 async def save (self , instance : MODEL ) -> MODEL :
68- """Persist a model.
69-
70- :param instance: A mapped object instance to be persisted
71- :return: The model instance after being persisted
72- """
7368 async with self ._get_session () as session :
7469 session .add (instance )
7570 return instance
@@ -78,24 +73,11 @@ async def save_many(
7873 self ,
7974 instances : Iterable [MODEL ],
8075 ) -> Iterable [MODEL ]:
81- """Persist many models in a single database get_session.
82-
83- :param instances: A list of mapped objects to be persisted
84- :type instances: Iterable
85- :return: The model instances after being persisted
86- """
8776 async with self ._get_session () as session :
8877 session .add_all (instances )
8978 return instances
9079
9180 async def get (self , identifier : PRIMARY_KEY ) -> MODEL :
92- """Get a model by primary key.
93-
94- :param identifier: The primary key
95- :return: A model instance
96- :raises ModelNotFound: No model has been found using the primary key
97- """
98- # TODO: implement get_many()
9981 async with self ._get_session (commit = False ) as session :
10082 model = await session .get (self ._model , identifier )
10183 if model is None :
@@ -106,11 +88,6 @@ async def delete(
10688 self ,
10789 entity : Union [MODEL , PRIMARY_KEY ],
10890 ) -> None :
109- """Deletes a model.
110-
111- :param entity: The model instance or the primary key
112- :type entity: Union[MODEL, PRIMARY_KEY]
113- """
11491 # TODO: delete without loading the model
11592 if isinstance (entity , self ._model ):
11693 obj = entity
@@ -124,20 +101,6 @@ async def find(
124101 search_params : Union [None , Mapping [str , Any ]] = None ,
125102 order_by : Union [None , Iterable [Union [str , Tuple [str , SortDirection ]]]] = None ,
126103 ) -> List [MODEL ]:
127- """Find models using filters
128-
129- E.g.
130- find(search_params={"name": "John"}) finds all models with name = John
131-
132- :param order_by:
133- :param search_params: A dictionary containing equality filters
134- :param limit: Number of models to retrieve
135- :type limit: int
136- :param offset: Number of models to skip
137- :type offset: int
138- :return: A collection of models
139- :rtype: List
140- """
141104 stmt = self ._find_query (search_params , order_by )
142105
143106 async with self ._get_session () as session :
@@ -147,25 +110,10 @@ async def find(
147110 async def paginated_find (
148111 self ,
149112 items_per_page : int ,
150- page : int ,
113+ page : int = 1 ,
151114 search_params : Union [None , Mapping [str , Any ]] = None ,
152115 order_by : Union [None , Iterable [Union [str , Tuple [str , SortDirection ]]]] = None ,
153116 ) -> PaginatedResult [MODEL ]:
154- """Find models using filters and pagination
155-
156- E.g.
157- find(name="John") finds all models with name = John
158-
159- :param items_per_page: Number of models to retrieve
160- :type items_per_page: int
161- :param page: Page to retrieve
162- :type page: int
163- :param search_params: A dictionary containing equality filters
164- :param order_by:
165- :return: A collection of models
166- :rtype: List
167- """
168-
169117 find_stmt = self ._find_query (search_params , order_by )
170118 paginated_stmt = self ._paginate_query_by_page (find_stmt , page , items_per_page )
171119
@@ -191,23 +139,6 @@ async def cursor_paginated_find(
191139 is_before_cursor : bool = False ,
192140 search_params : Union [None , Mapping [str , Any ]] = None ,
193141 ) -> CursorPaginatedResult [MODEL ]:
194- """Find models using filters and cursor based pagination
195-
196- E.g.
197- find(name="John") finds all models with name = John
198-
199- :param items_per_page: Number of models to retrieve
200- :type items_per_page: int
201- :param order_by: Model property to use for ordering and before/after evaluation
202- :type order_by: str
203- :param before: Identifier of the last node to skip
204- :type before: Union[int, str]
205- :param after: Identifier of the last node to skip
206- :type after: Union[int, str]
207- :param search_params: A dictionary containing equality filters
208- :return: A collection of models
209- :rtype: List
210- """
211142 find_stmt = self ._find_query (search_params )
212143 paginated_stmt = self ._cursor_paginated_query (
213144 find_stmt ,
0 commit comments