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 76
76
_load_test
77
77
78
78
# 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({
60
60
collapsible : true ,
61
61
children : [
62
62
"row_factories" ,
63
- "overall_usage" ,
64
63
"predefined_row_factories" ,
65
64
]
66
65
} ,
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`.
36
36
It has all necessary components to create high-load and fault tolerance applications.
37
37
38
38
## How to install
39
- Using pip
39
+ ::: tabs
40
+ @tab pip
41
+
40
42
``` bash
41
43
pip install psqlpy
42
44
```
43
45
44
- Using poetry
46
+ @tab poetry
47
+
45
48
``` bash
46
49
poetry add psqlpy
47
50
```
48
51
52
+ @tab git
53
+
54
+ ``` bash
55
+ pip install git+https://github.com/qaspen-python/psqlpy
56
+ ```
57
+
58
+ :::
59
+
49
60
## Join community!
50
61
You can get support from the creators and users of ` PSQLPy ` in some social media:
51
62
- [ Telegram] ( https://t.me/+f3Y8mYKgXxhmYThi )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
---
2
2
title : Row Factories Usage
3
3
---
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