Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ impl PoolBuilder {

/// Specify the number of sqlite connections to open as part of the pool.
///
/// Defaults to the number of logical CPUs of the current system.
/// Defaults to the number of logical CPUs of the current system. Values
/// less than `1` are clamped to `1`.
///
/// ```
/// use async_sqlite::PoolBuilder;
///
/// let builder = PoolBuilder::new().num_conns(2);
/// ```
pub fn num_conns(mut self, num_conns: usize) -> Self {
self.num_conns = Some(num_conns);
self.num_conns = Some(num_conns.max(1));
self
}

Expand Down
13 changes: 13 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async_test!(test_journal_mode);
async_test!(test_concurrency);
async_test!(test_pool);
async_test!(test_pool_conn_for_each);
async_test!(test_pool_num_conns_zero_clamps);

async fn test_journal_mode() {
let tmp_dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -227,3 +228,15 @@ async fn test_pool_conn_for_each() {
// cleanup
pool.close().await.expect("closing client conn");
}

async fn test_pool_num_conns_zero_clamps() {
let tmp_dir = tempfile::tempdir().unwrap();
let pool = PoolBuilder::new()
.path(tmp_dir.path().join("clamp.db"))
.num_conns(0)
.open()
.await
.expect("pool unable to be opened");
let results = pool.conn_for_each(|_| Ok(())).await;
assert_eq!(results.len(), 1);
}