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 @@ -85,6 +85,7 @@ async_test!(test_concurrency);
85
85
async_test ! ( test_pool) ;
86
86
async_test ! ( test_pool_conn_for_each) ;
87
87
async_test ! ( test_pool_close_concurrent) ;
88
+ async_test ! ( test_pool_num_conns_zero_clamps) ;
88
89
89
90
async fn test_journal_mode ( ) {
90
91
let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -249,3 +250,15 @@ async fn test_pool_close_concurrent() {
249
250
let res = pool. conn ( |c| c. execute ( "SELECT 1" , ( ) ) ) . await ;
250
251
assert ! ( matches!( res, Err ( Error :: Closed ) ) ) ;
251
252
}
253
+
254
+ async fn test_pool_num_conns_zero_clamps ( ) {
255
+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
256
+ let pool = PoolBuilder :: new ( )
257
+ . path ( tmp_dir. path ( ) . join ( "clamp.db" ) )
258
+ . num_conns ( 0 )
259
+ . open ( )
260
+ . await
261
+ . expect ( "pool unable to be opened" ) ;
262
+ let results = pool. conn_for_each ( |_| Ok ( ( ) ) ) . await ;
263
+ assert_eq ! ( results. len( ) , 1 ) ;
264
+ }
You can’t perform that action at this time.
0 commit comments