Make connection pool size customizable

This commit is contained in:
Raphaël Thériault 2019-10-07 18:04:52 -04:00
parent 8b4eaa6e0a
commit 0aa081ed49
3 changed files with 4 additions and 1 deletions

1
Cargo.lock generated
View File

@ -503,6 +503,7 @@ dependencies = [
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libsqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
actix-web = "1.0.8"
chrono = "0.4.9"
num_cpus = "1.10.1"
[dependencies.diesel]
version = "1.4.2"
features = ["r2d2", "sqlite"]

View File

@ -19,9 +19,10 @@ pub mod setup {
use diesel::sqlite::SqliteConnection;
/// Creates a SQLite database connection pool
pub fn create_pool(url: &str) -> Pool {
pub fn create_pool(url: &str, size: u32) -> Pool {
let manager = ConnectionManager::<SqliteConnection>::new(url);
r2d2::Pool::builder()
.max_size(size)
.build(manager)
.expect("Can't create pool.")
}