summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-10-21 21:31:02 +0200
committerGitHub <[email protected]>2023-10-21 21:31:02 +0200
commite8a8b2d33eec5da6701b04181b14de755e8b8063 (patch)
tree5cd77421900fd8ec02f05d15e6fb195f28dfceb4 /src/db.rs
parent48943e0de28b99d7f108e96b7d250bbf1a6c5a5b (diff)
parentbf1aeb7191bfaa75f1acf47c675bc68b9fac1cd8 (diff)
downloadwebol-e8a8b2d33eec5da6701b04181b14de755e8b8063.tar
webol-e8a8b2d33eec5da6701b04181b14de755e8b8063.tar.gz
webol-e8a8b2d33eec5da6701b04181b14de755e8b8063.zip
Merge pull request #4 from FxQnLr/database-init
int db in process
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/db.rs b/src/db.rs
index 87943ca..295780e 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1,8 +1,32 @@
1use std::env;
2
1use serde::Serialize; 3use serde::Serialize;
4use sqlx::{PgPool, postgres::PgPoolOptions};
5use tracing::{debug, info};
2 6
3#[derive(Serialize)] 7#[derive(Serialize)]
4pub struct Device { 8pub struct Device {
5 pub id: String, 9 pub id: String,
6 pub mac: String, 10 pub mac: String,
7 pub broadcast_addr: String 11 pub broadcast_addr: String
8} \ No newline at end of file 12}
13
14pub async fn init_db_pool() -> PgPool {
15 #[cfg(not(debug_assertions))]
16 let db_url = SETTINGS.get_string("database.url").unwrap();
17
18 #[cfg(debug_assertions)]
19 let db_url = env::var("DATABASE_URL").unwrap();
20
21 debug!("attempt to connect dbPool to '{}'", db_url);
22
23 let pool = PgPoolOptions::new()
24 .max_connections(5)
25 .connect(&db_url)
26 .await
27 .unwrap();
28
29 info!("dbPool successfully connected to '{}'", db_url);
30
31 pool
32}