@@ -183,6 +183,23 @@ impl RustPSQLPool {
183183 self . db_pool = Some ( db_pool_builder. build ( ) ?) ;
184184 Ok ( ( ) )
185185 }
186+
187+ /// Close connection pool.
188+ ///
189+ /// # Errors
190+ /// May return Err Result if connection pool isn't opened.
191+ pub fn inner_close ( & self ) -> RustPSQLDriverPyResult < ( ) > {
192+ let db_pool_manager =
193+ self . db_pool
194+ . as_ref ( )
195+ . ok_or ( RustPSQLDriverError :: DatabasePoolError (
196+ "Database pool is not initialized" . into ( ) ,
197+ ) ) ?;
198+
199+ db_pool_manager. close ( ) ;
200+
201+ Ok ( ( ) )
202+ }
186203}
187204
188205#[ pyclass( ) ]
@@ -257,16 +274,30 @@ impl PSQLPool {
257274 querystring : String ,
258275 parameters : Option < & ' a PyAny > ,
259276 ) -> RustPSQLDriverPyResult < & ' a PyAny > {
260- let engine_arc = self . rust_psql_pool . clone ( ) ;
277+ let db_pool_arc = self . rust_psql_pool . clone ( ) ;
261278 let mut params: Vec < PythonDTO > = vec ! [ ] ;
262279 if let Some ( parameters) = parameters {
263280 params = convert_parameters ( parameters) ?;
264281 }
265282
266283 rustengine_future ( py, async move {
267- let engine_guard = engine_arc. read ( ) . await ;
284+ let db_pool_guard = db_pool_arc. read ( ) . await ;
285+
286+ db_pool_guard. inner_execute ( querystring, params) . await
287+ } )
288+ }
289+
290+ /// Close connection pool.
291+ ///
292+ /// # Errors
293+ /// May return Err Result if connection pool isn't opened.
294+ pub fn close < ' a > ( & self , py : Python < ' a > ) -> RustPSQLDriverPyResult < & ' a PyAny > {
295+ let db_pool_arc = self . rust_psql_pool . clone ( ) ;
296+
297+ rustengine_future ( py, async move {
298+ let db_pool_guard = db_pool_arc. read ( ) . await ;
268299
269- engine_guard . inner_execute ( querystring , params ) . await
300+ db_pool_guard . inner_close ( )
270301 } )
271302 }
272303}
0 commit comments