@@ -10,7 +10,7 @@ use crate::{
1010 value_converter:: { convert_parameters, PythonDTO } ,
1111} ;
1212
13- use super :: connection:: Connection ;
13+ use super :: { common_options :: ConnRecyclingMethod , connection:: Connection } ;
1414
1515/// `PSQLPool` for internal use only.
1616///
@@ -23,12 +23,14 @@ pub struct RustPSQLPool {
2323 port : Option < u16 > ,
2424 db_name : Option < String > ,
2525 max_db_pool_size : Option < usize > ,
26+ conn_recycling_method : Option < ConnRecyclingMethod > ,
2627 db_pool : Arc < tokio:: sync:: RwLock < Option < Pool > > > ,
2728}
2829
2930impl RustPSQLPool {
3031 /// Create new `RustPSQLPool`.
3132 #[ must_use]
33+ #[ allow( clippy:: too_many_arguments) ]
3234 pub fn new (
3335 dsn : Option < String > ,
3436 username : Option < String > ,
@@ -37,6 +39,7 @@ impl RustPSQLPool {
3739 port : Option < u16 > ,
3840 db_name : Option < String > ,
3941 max_db_pool_size : Option < usize > ,
42+ conn_recycling_method : Option < ConnRecyclingMethod > ,
4043 ) -> Self {
4144 RustPSQLPool {
4245 dsn,
@@ -46,6 +49,7 @@ impl RustPSQLPool {
4649 port,
4750 db_name,
4851 max_db_pool_size,
52+ conn_recycling_method,
4953 db_pool : Arc :: new ( tokio:: sync:: RwLock :: new ( None ) ) ,
5054 }
5155 }
@@ -124,6 +128,7 @@ impl RustPSQLPool {
124128 let db_host = self . host . clone ( ) ;
125129 let db_port = self . port ;
126130 let db_name = self . db_name . clone ( ) ;
131+ let conn_recycling_method = self . conn_recycling_method ;
127132 let max_db_pool_size = self . max_db_pool_size ;
128133
129134 let mut db_pool_guard = db_pool_arc. write ( ) . await ;
@@ -163,9 +168,16 @@ impl RustPSQLPool {
163168 }
164169 }
165170
166- let mgr_config = ManagerConfig {
167- recycling_method : RecyclingMethod :: Fast ,
168- } ;
171+ let mgr_config: ManagerConfig ;
172+ if let Some ( conn_recycling_method) = conn_recycling_method {
173+ mgr_config = ManagerConfig {
174+ recycling_method : conn_recycling_method. to_internal ( ) ,
175+ }
176+ } else {
177+ mgr_config = ManagerConfig {
178+ recycling_method : RecyclingMethod :: Fast ,
179+ } ;
180+ }
169181 let mgr = Manager :: from_config ( pg_config, NoTls , mgr_config) ;
170182
171183 let mut db_pool_builder = Pool :: builder ( mgr) ;
@@ -186,6 +198,7 @@ pub struct PSQLPool {
186198#[ pymethods]
187199impl PSQLPool {
188200 #[ new]
201+ #[ allow( clippy:: too_many_arguments) ]
189202 #[ must_use]
190203 pub fn new (
191204 dsn : Option < String > ,
@@ -195,6 +208,7 @@ impl PSQLPool {
195208 port : Option < u16 > ,
196209 db_name : Option < String > ,
197210 max_db_pool_size : Option < usize > ,
211+ conn_recycling_method : Option < ConnRecyclingMethod > ,
198212 ) -> Self {
199213 PSQLPool {
200214 rust_psql_pool : Arc :: new ( tokio:: sync:: RwLock :: new ( RustPSQLPool {
@@ -205,6 +219,7 @@ impl PSQLPool {
205219 port,
206220 db_name,
207221 max_db_pool_size,
222+ conn_recycling_method,
208223 db_pool : Arc :: new ( tokio:: sync:: RwLock :: new ( None ) ) ,
209224 } ) ) ,
210225 }
0 commit comments