Skip to content

Commit d9bb588

Browse files
authored
Merge branch 'main' into codex/refactor-pool--close-to-await-futures-concurrently
2 parents 46f0378 + b443ff7 commit d9bb588

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/pool.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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

tests/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ async_test!(test_concurrency);
8585
async_test!(test_pool);
8686
async_test!(test_pool_conn_for_each);
8787
async_test!(test_pool_close_concurrent);
88+
async_test!(test_pool_num_conns_zero_clamps);
8889

8990
async 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+
}

0 commit comments

Comments
 (0)