aboutsummaryrefslogtreecommitdiff
path: root/src/utils/db.rs
blob: 86f66fd2bde283d38b2c3f02929cc8da4a38d40b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyleft (ɔ) 2021-2021 Whirlsplash
// SPDX-License-Identifier: GPL-3.0-only

use std::error::Error;

use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};

pub async fn get_pool() -> Result<SqlitePool, Box<dyn Error>> {
  let pool = SqlitePoolOptions::new()
    .max_connections(20)
    .connect(&std::env::var("DATABASE_URL")?)
    .await?;

  debug!(
    "connected to database at url '{}'",
    &std::env::var("DATABASE_URL")?
  );

  Ok(pool)
}