About the connection of the database (cassandra)

I would like to ask questions about establishing a database connection (about cassandra).
Because of my architecture, combined with web and database processing (actix_web + cassandra), but such a method, the input of a url to establish a connection.

If I want to connect with cassandra always, instead of re-establishing the request every time I send it. What is the way?

I only know that using static variable (global variable), is there a better way?

other post

1 Like

Connection reference stored as application state. You can use R2D2 to have connection pool.

Because I am using the cassandra cpp driver, it has a pool mechanism, so there is no conflict with r2d2? (I don’t know much…)

In that case you don’t need R2D2. Anyway, application state is one the place where you can hold connection (or some pool reference). lazy_static is an alternative one you can use instead.

This way is to save the connection status to lazy_static?
Can unsafe functions be used?

Yes. https://github.com/rust-lang-nursery/lazy-static.rs