summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
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}