@@ -816,6 +816,13 @@ class Connection:
816816 It can be created only from connection pool.
817817 """
818818
819+ async def __aenter__ (self : Self ) -> Self : ...
820+ async def __aexit__ (
821+ self : Self ,
822+ exception_type : type [BaseException ] | None ,
823+ exception : BaseException | None ,
824+ traceback : types .TracebackType | None ,
825+ ) -> None : ...
819826 async def execute (
820827 self : Self ,
821828 querystring : str ,
@@ -1040,6 +1047,18 @@ class Connection:
10401047 ... # do something with this result.
10411048 ```
10421049 """
1050+ def back_to_pool (self : Self ) -> None :
1051+ """Return connection back to the pool.
1052+
1053+ It necessary to commit all transactions and close all cursor
1054+ made by this connection. Otherwise, it won't have any practical usage.
1055+ """
1056+
1057+ class ConnectionPoolStatus :
1058+ max_size : int
1059+ size : int
1060+ available : int
1061+ waiting : int
10431062
10441063class ConnectionPool :
10451064 """Connection pool for executing queries.
@@ -1142,6 +1161,21 @@ class ConnectionPool:
11421161 - `max_db_pool_size`: maximum size of the connection pool.
11431162 - `conn_recycling_method`: how a connection is recycled.
11441163 """
1164+ def status (self : Self ) -> ConnectionPoolStatus :
1165+ """Return information about connection pool.
1166+
1167+ ### Returns
1168+ `ConnectionPoolStatus`
1169+ """
1170+ def resize (self : Self , new_max_size : int ) -> None :
1171+ """Resize the connection pool.
1172+
1173+ This change the max_size of the pool dropping
1174+ excess objects and/or making space for new ones.
1175+
1176+ ### Parameters:
1177+ - `new_max_size`: new size for the connection pool.
1178+ """
11451179 async def execute (
11461180 self : Self ,
11471181 querystring : str ,
@@ -1202,6 +1236,24 @@ class ConnectionPool:
12021236
12031237 It acquires new connection from the database pool.
12041238 """
1239+ def acquire (self : Self ) -> Connection :
1240+ """Create new connection for async context manager.
1241+
1242+ Must be used only in async context manager.
1243+
1244+ ### Example:
1245+ ```python
1246+ import asyncio
1247+
1248+ from psqlpy import PSQLPool, QueryResult
1249+
1250+
1251+ async def main() -> None:
1252+ db_pool = PSQLPool()
1253+ async with db_pool.acquire() as connection:
1254+ res = await connection.execute(...)
1255+ ```
1256+ """
12051257 def close (self : Self ) -> None :
12061258 """Close the connection pool."""
12071259
0 commit comments