Skip to content

Commit 833f224

Browse files
committed
Added docs for ConnectionPool context manager
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent ce0a9f5 commit 833f224

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

docs/components/connection_pool.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ You cannot set the minimum size for the connection pool, by it is 0.
1313
So, if you set `max_db_pool_size` to 100, pool will create new connection every time there aren't enough connections to handle the load.
1414
:::
1515

16-
## Connection pool methods
17-
1816
### All available ConnectionPool parameters
1917

2018
- `dsn`: Full dsn connection string.
@@ -105,9 +103,6 @@ db_pool: Final = ConnectionPool(
105103
db_name="postgres",
106104
max_db_pool_size=10,
107105
)
108-
109-
async def main() -> None:
110-
111106
```
112107

113108
### Initialize Connection Pool with DSN
@@ -124,9 +119,6 @@ db_pool: Final = ConnectionPool(
124119
dsn="postgres://postgres:postgres@localhost:5432/postgres",
125120
max_db_pool_size=10,
126121
)
127-
128-
async def main() -> None:
129-
130122
```
131123

132124
### Create Connection Pool with one function
@@ -143,6 +135,26 @@ db_pool: Final = connect(
143135
```
144136
`connect` function has the same parameters as `ConnectionPool`.
145137

138+
### Use Connection Pool as context manager
139+
```py
140+
from typing import Final
141+
142+
from psqlpy import ConnectionPool
143+
144+
145+
async def main() -> None:
146+
with ConnectionPool(
147+
dsn="postgres://postgres:postgres@localhost:5432/postgres",
148+
max_db_pool_size=10,
149+
) as db_pool:
150+
# ConnectionPool is opened
151+
await db_pool.execute("SOME_SQL")
152+
# ConnectionPool is opened
153+
# ConnectionPool is closed
154+
```
155+
156+
## Connection pool methods
157+
146158
### Resize
147159
Resize connection pool capacity.
148160

0 commit comments

Comments
 (0)