8000 Creating a keep-alive connection to prevent a new connection for every statement · SeaQL sea-orm · Discussion #2418 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Creating a keep-alive connection to prevent a new connection for every statement #2418

Closed Answered by EvilWatermelon
EvilWatermelon asked this question in Q&A
Discussion options

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 sea_orm requires to pass the DatabaseConnection for each statement. Is it possible to create a keep-alive connection that starts an initial connection after the program starts and keeps it up as long as the program runs? Or is the passing the more secure way and I should accept it like it is?

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@EvilWatermelon
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by EvilWatermelon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
0