11"""Service base classes for SQLSpec application services."""
22
33from contextlib import asynccontextmanager , contextmanager
4- from typing import TYPE_CHECKING , Any , Generic , cast
4+ from typing import TYPE_CHECKING , Any , Generic , cast , overload
55
66from typing_extensions import TypeVar
77
@@ -51,6 +51,28 @@ def driver(self) -> AsyncDriverT:
5151 """Alias for :attr:`session` matching the recipe-doc terminology."""
5252 return self ._session
5353
54+ @overload
55+ async def paginate (
56+ self ,
57+ statement : "Statement | QueryBuilder" ,
58+ / ,
59+ * parameters : "StatementParameters | StatementFilter" ,
60+ schema_type : "type[SchemaT]" ,
61+ count_with_window : bool = False ,
62+ ** kwargs : Any ,
63+ ) -> OffsetPagination [SchemaT ]: ...
64+
65+ @overload
66+ async def paginate (
67+ self ,
68+ statement : "Statement | QueryBuilder" ,
69+ / ,
70+ * parameters : "StatementParameters | StatementFilter" ,
71+ schema_type : None = None ,
72+ count_with_window : bool = False ,
73+ ** kwargs : Any ,
74+ ) -> OffsetPagination [dict [str , Any ]]: ...
75+
5476 async def paginate (
5577 self ,
5678 statement : "Statement | QueryBuilder" ,
@@ -59,7 +81,7 @@ async def paginate(
5981 schema_type : "type[SchemaT] | None" = None ,
6082 count_with_window : bool = False ,
6183 ** kwargs : Any ,
62- ) -> OffsetPagination [SchemaT ]:
84+ ) -> " OffsetPagination[SchemaT] | OffsetPagination[dict[str, Any]]" :
6385 """Execute a paginated query and return an OffsetPagination container.
6486
6587 Args:
@@ -78,13 +100,54 @@ async def paginate(
78100 statement , * parameters , schema_type = schema_type , count_with_window = count_with_window , ** kwargs
79101 )
80102
103+ if schema_type is None :
104+ return OffsetPagination (
105+ items = cast ("list[dict[str, Any]]" , items ),
106+ limit = limit_offset .limit if limit_offset is not None else len (items ),
107+ offset = limit_offset .offset if limit_offset is not None else 0 ,
108+ total = total ,
109+ )
110+
81111 return OffsetPagination (
82112 items = cast ("list[SchemaT]" , items ),
83113 limit = limit_offset .limit if limit_offset is not None else len (items ),
84114 offset = limit_offset .offset if limit_offset is not None else 0 ,
85115 total = total ,
86116 )
87117
118+ @overload
119+ async def get_one (
120+ self ,
121+ statement : "Statement | QueryBuilder" ,
122+ / ,
123+ * parameters : "StatementParameters | StatementFilter" ,
124+ schema_type : "type[SchemaT]" ,
125+ error_message : str | None = None ,
126+ ** kwargs : Any ,
127+ ) -> SchemaT : ...
128+
129+ @overload
130+ async def get_one (
131+ self ,
132+ statement : "Statement | QueryBuilder" ,
133+ / ,
134+ * parameters : "StatementParameters | StatementFilter" ,
135+ schema_type : None = None ,
136+ error_message : str | None = None ,
137+ ** kwargs : Any ,
138+ ) -> dict [str , Any ]: ...
139+
140+ @overload
141+ async def get_one (
142+ self ,
143+ statement : "Statement | QueryBuilder" ,
144+ / ,
145+ * parameters : "StatementParameters | StatementFilter" ,
146+ schema_type : "type[SchemaT] | None" = None ,
147+ error_message : str | None = None ,
148+ ** kwargs : Any ,
149+ ) -> "SchemaT | dict[str, Any]" : ...
150+
88151 async def get_one (
89152 self ,
90153 statement : "Statement | QueryBuilder" ,
@@ -191,6 +254,28 @@ def driver(self) -> SyncDriverT:
191254 """Alias for :attr:`session` matching the recipe-doc terminology."""
192255 return self ._session
193256
257+ @overload
258+ def paginate (
259+ self ,
260+ statement : "Statement | QueryBuilder" ,
261+ / ,
262+ * parameters : "StatementParameters | StatementFilter" ,
263+ schema_type : "type[SchemaT]" ,
264+ count_with_window : bool = False ,
265+ ** kwargs : Any ,
266+ ) -> OffsetPagination [SchemaT ]: ...
267+
268+ @overload
269+ def paginate (
270+ self ,
271+ statement : "Statement | QueryBuilder" ,
272+ / ,
273+ * parameters : "StatementParameters | StatementFilter" ,
274+ schema_type : None = None ,
275+ count_with_window : bool = False ,
276+ ** kwargs : Any ,
277+ ) -> OffsetPagination [dict [str , Any ]]: ...
278+
194279 def paginate (
195280 self ,
196281 statement : "Statement | QueryBuilder" ,
@@ -199,7 +284,7 @@ def paginate(
199284 schema_type : "type[SchemaT] | None" = None ,
200285 count_with_window : bool = False ,
201286 ** kwargs : Any ,
202- ) -> OffsetPagination [SchemaT ]:
287+ ) -> " OffsetPagination[SchemaT] | OffsetPagination[dict[str, Any]]" :
203288 """Execute a paginated query and return an OffsetPagination container.
204289
205290 Args:
@@ -218,13 +303,54 @@ def paginate(
218303 statement , * parameters , schema_type = schema_type , count_with_window = count_with_window , ** kwargs
219304 )
220305
306+ if schema_type is None :
307+ return OffsetPagination (
308+ items = cast ("list[dict[str, Any]]" , items ),
309+ limit = limit_offset .limit if limit_offset is not None else len (items ),
310+ offset = limit_offset .offset if limit_offset is not None else 0 ,
311+ total = total ,
312+ )
313+
221314 return OffsetPagination (
222315 items = cast ("list[SchemaT]" , items ),
223316 limit = limit_offset .limit if limit_offset is not None else len (items ),
224317 offset = limit_offset .offset if limit_offset is not None else 0 ,
225318 total = total ,
226319 )
227320
321+ @overload
322+ def get_one (
323+ self ,
324+ statement : "Statement | QueryBuilder" ,
325+ / ,
326+ * parameters : "StatementParameters | StatementFilter" ,
327+ schema_type : "type[SchemaT]" ,
328+ error_message : str | None = None ,
329+ ** kwargs : Any ,
330+ ) -> SchemaT : ...
331+
332+ @overload
333+ def get_one (
334+ self ,
335+ statement : "Statement | QueryBuilder" ,
336+ / ,
337+ * parameters : "StatementParameters | StatementFilter" ,
338+ schema_type : None = None ,
339+ error_message : str | None = None ,
340+ ** kwargs : Any ,
341+ ) -> dict [str , Any ]: ...
342+
343+ @overload
344+ def get_one (
345+ self ,
346+ statement : "Statement | QueryBuilder" ,
347+ / ,
348+ * parameters : "StatementParameters | StatementFilter" ,
349+ schema_type : "type[SchemaT] | None" = None ,
350+ error_message : str | None = None ,
351+ ** kwargs : Any ,
352+ ) -> "SchemaT | dict[str, Any]" : ...
353+
228354 def get_one (
229355 self ,
230356 statement : "Statement | QueryBuilder" ,
0 commit comments