diff options
author | FxQnLr <[email protected]> | 2024-04-11 09:20:04 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-11 09:20:04 +0200 |
commit | 6b05d1a437a49db98056de7b029923e8aedf1a5a (patch) | |
tree | bc70f14cae1760e91369705273904c0de1bfbf75 /src/db.rs | |
parent | 907e5cb5bc48899b444f7fedd85af7b5974d9a2e (diff) | |
parent | 2476e182f61d209768635e8eca6e75b4acfbd007 (diff) | |
download | webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.tar webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.tar.gz webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.zip |
Merge pull request #32 from FxQnLr/0.4.0
0.4.0
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 | } | ||