New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please document how to dynamically use TLS and NoTLS connections #31
Comments
Always include the MakeTlsConnector. It will internally decide if TLS is necessary or not. |
Thank you for your answer! Can you expand on that? I try to learn (and I'll blog about it once I understand this!) I have changed the create_pool function to return Pool<PostgresConnectionManager>, but now the no ssl pool creation makes the compiler complain that it found the 'NoTls' struct, but expected 'MakeTlsConnector':
Which makes sense on itself: these are two different structs. |
You shouldn't need to do any of that. Just always make a pool configuration using a manager with MakeTlsConnector. |
How would that look like? |
How would what look like? |
How would that MakeTLS look like? I also don't really know if I need this crate or not. I use diesel as ORM and have in my main.rs this code so I can switch between the databases quickly. If I use this crate I get another type and an error in LoadQuery dsl. Can I put this together with: #[cfg(postgresql)]
async fn init_db_pool(database_url: &str)-> Result<Pool<ConnectionManager<PgConnection>>,
String> {
let manager = ConnectionManager::<PgConnection>::new(database_url);
let pool = Pool::builder()
.max_size(1)
.build(manager)
.expect("Failed to create pool.");
Ok(pool)
} #[cfg(sqlite)]
type DbPool = Pool<ConnectionManager<SqliteConnection>>;
#[cfg(sqlite)]
type DbConnection = SqliteConnection;
#[cfg(postgresql)]
type DbPool = Pool<ConnectionManager<PgConnection>>;
#[cfg(postgresql)]
type DbConnection = PgConnection;
#[cfg(postgresql)]
type QueryBuilder = PgQueryBuilder;
#[cfg(mysql)]
type DbPool = Pool<ConnectionManager<MysqlConnection>>;
#[cfg(mysql)]
type DbConnection = MysqlConnection; |
This crate provides a connection manager for the |
Thanks understood. I was just confused because it said postgres. |
I am not sure if this is the correct place for this question, if not please let me know, and I close it, because clearly this is also my personal learning path. However, I can imagine this is something that others will or might run into.
I want to create a (r2d2, postgres) connection pool that can be dynamically NoTls or Tls (MakeTlsConnector).
Currently, I swap function and function arguments, but I would like to make it generic.
So far I have created the following contruction:
However, when I create the pool, the compiler tells me it can't derive the type:
Error:
I do understand what the compiler tells me, but how I create a connection pool that can be dynamically NoTls or Tls?
The text was updated successfully, but these errors were encountered: