Skip to content

Commit f8e8122

Browse files
committed
docs update
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent 498c676 commit f8e8122

File tree

5 files changed

+48
-40
lines changed

5 files changed

+48
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ _test*
7676
_load_test
7777

7878
# JS
79-
node_modules
79+
node_modules
80+
.temp

docs/.vuepress/sidebar.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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
},

docs/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,27 @@ Don't make useless abstractions and make it like a mirror to `PostgreSQL`.
3636
It 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
4143
pip install psqlpy
4244
```
4345

44-
Using poetry
46+
@tab poetry
47+
4548
```bash
4649
poetry 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!
5061
You can get support from the creators and users of `PSQLPy` in some social media:
5162
- [Telegram](https://t.me/+f3Y8mYKgXxhmYThi)

docs/usage/row_factories/overall_usage.md

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
---
22
title: 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+
```

0 commit comments

Comments
 (0)