@@ -13,8 +13,6 @@ You cannot set the minimum size for the connection pool, by it is 0.
13
13
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.
14
14
:::
15
15
16
- ## Connection pool methods
17
-
18
16
### All available ConnectionPool parameters
19
17
20
18
- ` dsn ` : Full dsn connection string.
@@ -105,9 +103,6 @@ db_pool: Final = ConnectionPool(
105
103
db_name = " postgres" ,
106
104
max_db_pool_size = 10 ,
107
105
)
108
-
109
- async def main () -> None :
110
-
111
106
```
112
107
113
108
### Initialize Connection Pool with DSN
@@ -124,9 +119,6 @@ db_pool: Final = ConnectionPool(
124
119
dsn = " postgres://postgres:postgres@localhost:5432/postgres" ,
125
120
max_db_pool_size = 10 ,
126
121
)
127
-
128
- async def main () -> None :
129
-
130
122
```
131
123
132
124
### Create Connection Pool with one function
@@ -143,6 +135,26 @@ db_pool: Final = connect(
143
135
```
144
136
` connect ` function has the same parameters as ` ConnectionPool ` .
145
137
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
+
146
158
### Resize
147
159
Resize connection pool capacity.
148
160
0 commit comments