Creating a keep-alive connection to prevent a new connection for every statement #2418
-
Hi, I have several functions to communicate with my database i.e.: pub async fn get_images(
con: &DatabaseConnection
) -> Result<Vec<entities::image::Model>, sea_orm::DbErr>{
let images: Vec<entities::image::Model> = Image::find().all(con).await?;
Ok(images)
} pub async fn get_queries(
con: &DatabaseConnection
) -> Result<Vec<serde_json::Value>, sea_orm::DbErr> {
let queries = Query::find().into_json().all(con).await?;
Ok(queries)
} // Init actix
HttpServer::new(move || {
let auth = HttpAuthentication::with_fn(validator);
App::new()
.wrap(Logger::default())
.app_data(web::Data::new(db.clone())) //etc. However, the logic of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
this is the rusty-way of doing things. the dependency is explicitly provided, so the logic is easy to test. it also makes it possible to use multiple databases in the same app. you can, for example, use |
Beta Was this translation helpful? Give feedback.
-
Found a solution: #1645 (comment) |
Beta Was this translation helpful? Give feedback.
Found a solution: #1645 (comment)