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 {
7878
7979 /// Specify the number of sqlite connections to open as part of the pool.
8080 ///
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+ /// ```
8289 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 ) ) ;
8491 self
8592 }
8693
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ async_test!(test_concurrency);
8585async_test ! ( test_pool) ;
8686async_test ! ( test_pool_conn_for_each) ;
8787async_test ! ( test_pool_close_concurrent) ;
88+ async_test ! ( test_pool_num_conns_zero_clamps) ;
8889
8990async fn test_journal_mode ( ) {
9091 let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -249,3 +250,15 @@ async fn test_pool_close_concurrent() {
249250 let res = pool. conn ( |c| c. execute ( "SELECT 1" , ( ) ) ) . await ;
250251 assert ! ( matches!( res, Err ( Error :: Closed ) ) ) ;
251252}
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