File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -78,9 +78,16 @@ impl PoolBuilder {
78
78
79
79
/// Specify the number of sqlite connections to open as part of the pool.
80
80
///
81
- /// Defaults to the number of logical CPUs of the current system.
81
+ /// Defaults to the number of logical CPUs of the current system. Values
82
+ /// less than `1` are clamped to `1`.
83
+ ///
84
+ /// ```
85
+ /// use async_sqlite::PoolBuilder;
86
+ ///
87
+ /// let builder = PoolBuilder::new().num_conns(2);
88
+ /// ```
82
89
pub fn num_conns ( mut self , num_conns : usize ) -> Self {
83
- self . num_conns = Some ( num_conns) ;
90
+ self . num_conns = Some ( num_conns. max ( 1 ) ) ;
84
91
self
85
92
}
86
93
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ async_test!(test_journal_mode);
84
84
async_test ! ( test_concurrency) ;
85
85
async_test ! ( test_pool) ;
86
86
async_test ! ( test_pool_conn_for_each) ;
87
+ async_test ! ( test_pool_num_conns_zero_clamps) ;
87
88
88
89
async fn test_journal_mode ( ) {
89
90
let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -227,3 +228,15 @@ async fn test_pool_conn_for_each() {
227
228
// cleanup
228
229
pool. close ( ) . await . expect ( "closing client conn" ) ;
229
230
}
231
+
232
+ async fn test_pool_num_conns_zero_clamps ( ) {
233
+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
234
+ let pool = PoolBuilder :: new ( )
235
+ . path ( tmp_dir. path ( ) . join ( "clamp.db" ) )
236
+ . num_conns ( 0 )
237
+ . open ( )
238
+ . await
239
+ . expect ( "pool unable to be opened" ) ;
240
+ let results = pool. conn_for_each ( |_| Ok ( ( ) ) ) . await ;
241
+ assert_eq ! ( results. len( ) , 1 ) ;
242
+ }
You can’t perform that action at this time.
0 commit comments