feat: add persistance
This commit is contained in:
parent
68e825c942
commit
f2552a74ed
6 changed files with 81 additions and 69 deletions
|
|
@ -44,4 +44,11 @@ impl DatabaseSettings {
|
|||
self.username, self.password, self.host, self.port, self.name
|
||||
)
|
||||
}
|
||||
|
||||
pub fn connection_string_without_db(&self) -> String {
|
||||
format!(
|
||||
"postgres://{}:{}@{}:{}",
|
||||
self.username, self.password, self.host, self.port
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
src/main.rs
13
src/main.rs
|
|
@ -1,8 +1,6 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use learn_axum::configuration::get_configuration;
|
||||
use learn_axum::startup;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::PgPool;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -10,11 +8,8 @@ async fn main() {
|
|||
let configuration = get_configuration().expect("Failed to read configuration.");
|
||||
let addr = format!("127.0.0.1:{}", configuration.application_port);
|
||||
let listener = TcpListener::bind(addr).await.unwrap(); //.expect("Unable to bind to port");
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.acquire_timeout(Duration::from_secs(3))
|
||||
.connect(&configuration.database.connection_string())
|
||||
let connection_pool = PgPool::connect(&configuration.database.connection_string())
|
||||
.await
|
||||
.expect("can't connect to database");
|
||||
startup::run(listener, pool).await.unwrap();
|
||||
.expect("Failed to connect to Postgres.");
|
||||
startup::run(listener, connection_pool).await.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use tokio::net::TcpListener;
|
|||
pub fn app(connection: PgPool) -> Router {
|
||||
Router::new()
|
||||
.merge(crate::routes::routes_health_check())
|
||||
.merge(crate::routes::routes_subscriptions(connection))
|
||||
.merge(crate::routes::routes_subscriptions(connection.clone()))
|
||||
}
|
||||
|
||||
/// Start the server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue