Skip to content

Commit 37160a3

Browse files
authored
Merge pull request #152 from AliRn76/main
Add `Panther` framework usage example
2 parents b9869b3 + e7adf9f commit 37160a3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default sidebar({
6565
"litestar",
6666
"blacksheep",
6767
"robyn",
68+
"panther",
6869
]
6970
},
7071
],

docs/usage/frameworks/panther.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Panther
3+
---
4+
5+
There is the default example for `Panther` framework.
6+
7+
We strongly recommend to use the following example as a standard way to use `PSQLPy` with `Panther` framework.
8+
9+
## Complete example
10+
11+
```python
12+
import uvicorn
13+
from psqlpy import ConnectionPool
14+
15+
from panther import Panther
16+
from panther.app import API
17+
from panther.configs import config
18+
from panther.events import Event
19+
from panther.response import Response
20+
21+
22+
@Event.startup
23+
async def create_connection_pool():
24+
config.connection_pool = ConnectionPool(
25+
dsn="postgres://postgres:postgres@localhost:5432/postgres",
26+
max_db_pool_size=10,
27+
)
28+
29+
30+
@Event.shutdown
31+
async def close_connection_pool():
32+
config.connection_pool.close()
33+
34+
35+
@API()
36+
async def pg_pool_example():
37+
connection = await config.connection_pool.connection()
38+
query_result = await connection.execute(
39+
"SELECT * FROM users",
40+
)
41+
return Response(data=query_result.result())
42+
43+
44+
app = Panther(__name__, configs=__name__, urls={'/': pg_pool_example})
45+
46+
if __name__ == "__main__":
47+
uvicorn.run(app)
48+
```

0 commit comments

Comments
 (0)