diff options
author | FxQnLr <[email protected]> | 2024-02-12 16:00:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-12 16:00:45 +0100 |
commit | c663810817183c8f92a4279236ca84d271365088 (patch) | |
tree | 0c844cc883e5e474a9cdad30004108852f13f903 /src/db.rs | |
parent | da6367885d31698464e1bec122e3e673974427c6 (diff) | |
parent | 9139d76cb1cf462820b2ddfa80d9a8d55bb30996 (diff) | |
download | webol-c663810817183c8f92a4279236ca84d271365088.tar webol-c663810817183c8f92a4279236ca84d271365088.tar.gz webol-c663810817183c8f92a4279236ca84d271365088.zip |
Merge pull request #14 from FxQnLr/axum7
Axum7 & config changes
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 | ||