Added some logging in database code and fixed some warnings
This commit is contained in:
parent
2cb4acc604
commit
779381df2d
|
@ -1,3 +1,4 @@
|
|||
use anyhow::bail;
|
||||
use sqlx::{postgres::PgPoolOptions, Postgres};
|
||||
|
||||
use crate::config::definition::Config;
|
||||
|
@ -14,12 +15,24 @@ pub struct Database {
|
|||
|
||||
impl Database {
|
||||
pub async fn new(config: &Config) -> anyhow::Result<Self> {
|
||||
log::info!("Database connecting to {}", config.database.url);
|
||||
let conn = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&config.database.url).await?;
|
||||
.connect(&config.database.url).await;
|
||||
|
||||
|
||||
match conn {
|
||||
Ok(c) => {
|
||||
log::info!("Connection successfull");
|
||||
Ok(Self {
|
||||
connection: conn
|
||||
connection: c
|
||||
})
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("Failed to connect to database: {e}");
|
||||
bail!(e)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connection(&self) -> &sqlx::Pool<Postgres> {
|
||||
|
|
|
@ -30,6 +30,7 @@ impl Users {
|
|||
.execute(db.connection())
|
||||
.await?;
|
||||
|
||||
log::debug!("Created user with id '{id}'");
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
@ -126,6 +127,8 @@ impl Users {
|
|||
.execute(db.connection())
|
||||
.await?;
|
||||
|
||||
log::debug!("Deleted user with id '{}'", self.id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ mod templates;
|
|||
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use actix_files as actix_fs;
|
||||
use sqlx::database;
|
||||
|
||||
use crate::{config::definition::Config, database::Database};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user