File tree Expand file tree Collapse file tree 5 files changed +48
-40
lines changed Expand file tree Collapse file tree 5 files changed +48
-40
lines changed Original file line number Diff line number Diff line change 7676_load_test
7777
7878# JS
79- node_modules
79+ node_modules
80+ .temp
Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ export default sidebar({
6060 collapsible : true ,
6161 children : [
6262 "row_factories" ,
63- "overall_usage" ,
6463 "predefined_row_factories" ,
6564 ]
6665 } ,
Original file line number Diff line number Diff line change @@ -36,16 +36,27 @@ Don't make useless abstractions and make it like a mirror to `PostgreSQL`.
3636It has all necessary components to create high-load and fault tolerance applications.
3737
3838## How to install
39- Using pip
39+ ::: tabs
40+ @tab pip
41+
4042``` bash
4143pip install psqlpy
4244```
4345
44- Using poetry
46+ @tab poetry
47+
4548``` bash
4649poetry add psqlpy
4750```
4851
52+ @tab git
53+
54+ ``` bash
55+ pip install git+https://github.com/qaspen-python/psqlpy
56+ ```
57+
58+ :::
59+
4960## Join community!
5061You can get support from the creators and users of ` PSQLPy ` in some social media:
5162- [ Telegram] ( https://t.me/+f3Y8mYKgXxhmYThi )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11---
22title : Row Factories Usage
33---
4+
5+ ` row_factory ` must be used when you want to process result from Database in a custom way and return something different from dictionary.
6+
7+ ` row_factory ` requires a function that accepts parameter ` Dict[str, typing.Any] ` and can return anything you want.
8+
9+ ::: tip
10+ ` row_factory ` can be a function or a class with ` __call__ ` method which returns target converted instance.
11+ :::
12+
13+ ### Example:
14+ We create custom class and function with this class as a parameter and return function which will be used in processing row from database.
15+ ``` python
16+ @dataclass
17+ class ValidationTestModel :
18+ id : int
19+ name: str
20+
21+ def to_class (
22+ class_ : Type[ValidationTestModel],
23+ ) -> Callable[[Dict[str , Any]], ValidationTestModel]:
24+ def to_class_inner (row : Dict[str , Any]) -> ValidationTestModel:
25+ return class_(** row)
26+
27+ return to_class_inner
28+
29+ async def main () -> None :
30+ conn_result = await psql_pool.execute(
31+ querystring = f " SELECT * FROM { table_name} " ,
32+ )
33+ class_res = conn_result.row_factory(row_factory = to_class(ValidationTestModel))
34+
35+ assert isinstance (class_res[0 ], ValidationTestModel)
36+ ```
You can’t perform that action at this time.
0 commit comments