@@ -8,6 +8,9 @@ from typing_extensions import Self
88_CustomClass = TypeVar (
99 "_CustomClass" ,
1010)
11+ _RowFactoryRV = TypeVar (
12+ "_RowFactoryRV" ,
13+ )
1114
1215class QueryResult :
1316 """Result."""
@@ -16,7 +19,11 @@ class QueryResult:
1619 self : Self ,
1720 custom_decoders : dict [str , Callable [[bytes ], Any ]] | None = None ,
1821 ) -> list [dict [Any , Any ]]:
19- """Return result from database as a list of dicts."""
22+ """Return result from database as a list of dicts.
23+
24+ `custom_decoders` must be used when you use
25+ PostgreSQL Type which isn't supported, read more in our docs.
26+ """
2027 def as_class (
2128 self : Self ,
2229 as_class : Callable [..., _CustomClass ],
@@ -52,12 +59,39 @@ class QueryResult:
5259 )
5360 ```
5461 """
62+ def row_factory (
63+ self ,
64+ row_factory : Callable [[dict [str , Any ]], _RowFactoryRV ],
65+ custom_decoders : dict [str , Callable [[bytes ], Any ]] | None = None ,
66+ ) -> list [_RowFactoryRV ]:
67+ """Use custom function to convert results from database.
68+
69+ `custom_decoders` must be used when you use
70+ PostgreSQL Type isn't supported, read more in the docs.
71+
72+ Argument order: firstly we apply `custom_decoders` (if specified),
73+ then we apply `row_factory`.
74+
75+ ### Parameters:
76+ - `row_factory`: function which takes `dict[str, Any]` as an argument.
77+ - `custom_decoders`: functions for custom decoding.
78+
79+ ### Returns:
80+ List of type that return passed `row_factory`.
81+ """
5582
5683class SingleQueryResult :
5784 """Single result."""
5885
59- def result (self : Self ) -> dict [Any , Any ]:
60- """Return result from database as a dict."""
86+ def result (
87+ self : Self ,
88+ custom_decoders : dict [str , Callable [[bytes ], Any ]] | None = None ,
89+ ) -> dict [Any , Any ]:
90+ """Return result from database as a dict.
91+
92+ `custom_decoders` must be used when you use
93+ PostgreSQL Type which isn't supported, read more in our docs.
94+ """
6195 def as_class (
6296 self : Self ,
6397 as_class : Callable [..., _CustomClass ],
@@ -96,6 +130,26 @@ class SingleQueryResult:
96130 )
97131 ```
98132 """
133+ def row_factory (
134+ self ,
135+ row_factory : Callable [[dict [str , Any ]], _RowFactoryRV ],
136+ custom_decoders : dict [str , Callable [[bytes ], Any ]] | None = None ,
137+ ) -> _RowFactoryRV :
138+ """Use custom function to convert results from database.
139+
140+ `custom_decoders` must be used when you use
141+ PostgreSQL Type isn't supported, read more in our docs.
142+
143+ Argument order: firstly we apply `custom_decoders` (if specified),
144+ then we apply `row_factory`.
145+
146+ ### Parameters:
147+ - `row_factory`: function which takes `list[dict[str, Any]]` as an argument.
148+ - `custom_decoders`: functions for custom decoding.
149+
150+ ### Returns:
151+ Type that return passed function.
152+ """
99153
100154class IsolationLevel (Enum ):
101155 """Class for Isolation Level for transactions."""
0 commit comments