diff options
author | FxQnLr <[email protected]> | 2024-04-10 00:16:55 +0200 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-04-10 00:16:55 +0200 |
commit | 3428a637ce420baef9aa9f9803e71bd587867005 (patch) | |
tree | a1ad8234ae9bf3709794324a41e38c2f7fa58d0d /src/db.rs | |
parent | 907e5cb5bc48899b444f7fedd85af7b5974d9a2e (diff) | |
download | webol-3428a637ce420baef9aa9f9803e71bd587867005.tar webol-3428a637ce420baef9aa9f9803e71bd587867005.tar.gz webol-3428a637ce420baef9aa9f9803e71bd587867005.zip |
Closes #24. Changed postgres to json directory storage
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/src/db.rs b/src/db.rs deleted file mode 100644 index a2b2009..0000000 --- a/src/db.rs +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | use serde::Serialize; | ||
2 | use sqlx::{PgPool, postgres::PgPoolOptions, types::{ipnetwork::IpNetwork, mac_address::MacAddress}}; | ||
3 | use tracing::{debug, info}; | ||
4 | use utoipa::ToSchema; | ||
5 | |||
6 | #[derive(Serialize, Debug)] | ||
7 | pub struct Device { | ||
8 | pub id: String, | ||
9 | pub mac: MacAddress, | ||
10 | pub broadcast_addr: String, | ||
11 | pub ip: IpNetwork, | ||
12 | pub times: Option<Vec<i64>> | ||
13 | } | ||
14 | |||
15 | #[derive(ToSchema)] | ||
16 | #[schema(as = Device)] | ||
17 | pub struct DeviceSchema { | ||
18 | pub id: String, | ||
19 | pub mac: String, | ||
20 | pub broadcast_addr: String, | ||
21 | pub ip: String, | ||
22 | pub times: Option<Vec<i64>> | ||
23 | } | ||
24 | |||
25 | pub async fn init_db_pool(db_url: &str) -> PgPool { | ||
26 | debug!("attempt to connect dbPool to '{}'", db_url); | ||
27 | |||
28 | let pool = PgPoolOptions::new() | ||
29 | .max_connections(5) | ||
30 | .connect(db_url) | ||
31 | .await | ||
32 | .unwrap(); | ||
33 | |||
34 | info!("dbPool successfully connected to '{}'", db_url); | ||
35 | |||
36 | pool | ||
37 | } | ||