diff options
author | FxQnLr <[email protected]> | 2024-02-12 15:05:03 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-12 15:05:03 +0100 |
commit | ca395b81bcadb9dde9214098f2cab0c7a3561574 (patch) | |
tree | 055bae9ef4e65f53b826b240f0b8e3b15b73693e /src/db.rs | |
parent | e4832b4cf36ba0eaed298ee458498eddd7176590 (diff) | |
parent | e50a868f69b602cc0bc84d51e9940878924f49ef (diff) | |
download | webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar.gz webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.zip |
Merge pull request #13 from FxQnLr/config
Config
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 16 |
1 files changed, 2 insertions, 14 deletions
@@ -1,13 +1,7 @@ | |||
1 | #[cfg(debug_assertions)] | ||
2 | use std::env; | ||
3 | |||
4 | use serde::Serialize; | 1 | use serde::Serialize; |
5 | use sqlx::{PgPool, postgres::PgPoolOptions}; | 2 | use sqlx::{PgPool, postgres::PgPoolOptions}; |
6 | use tracing::{debug, info}; | 3 | use tracing::{debug, info}; |
7 | 4 | ||
8 | #[cfg(not(debug_assertions))] | ||
9 | use crate::config::SETTINGS; | ||
10 | |||
11 | #[derive(Serialize, Debug)] | 5 | #[derive(Serialize, Debug)] |
12 | pub struct Device { | 6 | pub struct Device { |
13 | pub id: String, | 7 | pub id: String, |
@@ -17,18 +11,12 @@ pub struct Device { | |||
17 | pub times: Option<Vec<i64>> | 11 | pub times: Option<Vec<i64>> |
18 | } | 12 | } |
19 | 13 | ||
20 | pub async fn init_db_pool() -> PgPool { | 14 | pub async fn init_db_pool(db_url: &str) -> PgPool { |
21 | #[cfg(not(debug_assertions))] | ||
22 | let db_url = SETTINGS.get_string("database.url").unwrap(); | ||
23 | |||
24 | #[cfg(debug_assertions)] | ||
25 | let db_url = env::var("DATABASE_URL").unwrap(); | ||
26 | |||
27 | debug!("attempt to connect dbPool to '{}'", db_url); | 15 | debug!("attempt to connect dbPool to '{}'", db_url); |
28 | 16 | ||
29 | let pool = PgPoolOptions::new() | 17 | let pool = PgPoolOptions::new() |
30 | .max_connections(5) | 18 | .max_connections(5) |
31 | .connect(&db_url) | 19 | .connect(db_url) |
32 | .await | 20 | .await |
33 | .unwrap(); | 21 | .unwrap(); |
34 | 22 | ||