-
Hello, Here is my existing code: pub type Connection = SqliteConnection;
pub struct Database {
connection: Pool<ConnectionManager<Connection>>,
}
impl Database {
pub fn new(database_url: Url) -> Self {
let manager = ConnectionManager::<Connection>::new(database_url);
let connection = r2d2::Pool::builder()
.max_size(16)
.build(manager)
.expect("Failed to create pool.");
Self { connection }
} Now I need to run some async transactions. So I'm thinking the best way to do this is to use a pool of async connections. Since I am using SQLite, here is what I tried: pub type Connection = SyncConnectionWrapper<SqliteConnection>;
pub struct Database {
connection: Pool<ConnectionManager<Connection>>,
}
impl Database {
pub fn new(database_url: Url) -> Self {
let manager = ConnectionManager::<Connection>::new(database_url);
let connection = r2d2::Pool::builder()
.max_size(16)
.build(manager)
.expect("Failed to create pool.");
Self { connection }
} But it doesn't work:
I' ve found the example on how to use Please advise, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is expected behavior. The |
Beta Was this translation helpful? Give feedback.
This is expected behavior. The
SyncConnectionWrapper
exposes an async connection implementation.r2d2
is a sync connection pool implementation and therefore fundamentally incompatible with async connection implementations. You might want to use an async connection pool likedeadpool
,bb8
ormobc
instead.