Description
Setup
Versions
- Rust: 1.71.1
- Diesel: 2.1.1
- Diesel_async: 0.4.1
- Database: Postgres
- Operating System MacOS 14
Feature Flags
- diesel: postgres_backend, r2d2, serde_json, numeric, chrono
- diesel_async: postgres, async-connection-wrapper, r2d2, tokio
Problem Description
I have the following types defined:
use diesel::{
pg::Pg,
query_builder::{AstPass, Query, QueryFragment},
r2d2::{ConnectionManager, PoolError, PooledConnection},
QueryResult, RunQueryDsl,
};
use diesel_async::{
AsyncPgConnection, async_connection_wrapper::AsyncConnectionWrapper,
};
use std::{cmp::min, sync::Arc};
pub type MyDbConnection = AsyncConnectionWrapper<AsyncPgConnection>;
pub type PgPool = diesel::r2d2::Pool<ConnectionManager<MyDbConnection>>;
pub type PgDbPool = Arc<PgPool>;
pub type PgPoolConnection = PooledConnection<ConnectionManager<MyDbConnection>>;
and this function to get a pool:
pub fn new_db_pool(database_url: &str) -> Result<PgDbPool, PoolError> {
let manager = ConnectionManager::<MyDbConnection>::new(database_url);
PgPool::builder().build(manager).map(Arc::new)
}
This all compiles fine.
When I try to use my PgPoolConnection
connection however, like this:
fn insert_to_db(
conn: &mut PgPoolConnection,
) {
let result = conn.build_transaction()
.read_write()
.run::<_, Error, _>(|pg_conn| {
insert_to_db_impl(
pg_conn,
¤t_ans_lookups,
&ans_lookups,
¤t_ans_primary_names,
&ans_primary_names,
¤t_ans_lookups_v2,
&ans_lookups_v2,
¤t_ans_primary_names_v2,
&ans_primary_names_v2,
)
...
I get this error:
no method named `build_transaction` found for mutable reference `&mut PooledConnection<ConnectionManager<AsyncConnectionWrapper<AsyncPgConnection, Tokio>>>` in the current scope
Given that this used to work when this code was just using the PgConnection from Diesel directly, and AsyncPgConnection itself implements build_transaction
, I can only assume the issue lies with AsyncConnectionWrapper
not exposing it properly.
What are you trying to accomplish?
Use Diesel without relying on libpq.
What is the expected output?
The code should compile an work happily (assuming I use spawn_blocking).
What is the actual output?
The compilation error above.
Are you seeing any additional errors?
Nup. Though it's quite hard to figure out what's meant to be supported. This crate purportedly supports bb8 for example but it doesn't work for AsyncConnectionWrapper. r2d2 does (maybe, pending this fix) but it isn't documented that r2d2 is supported.
Steps to reproduce
git clone [email protected]:aptos-labs/aptos-indexer-processors.git
git checkout bd8c9147c6db748678e3110b937cdd7eb819d574
cd rust
cargo build -p processor
Checklist
- I have already looked over the issue tracker for similar possible closed issues.
- This issue can be reproduced on Rust's stable channel. (Your issue will be
closed if this is not the case) - This issue can be reproduced without requiring a third party crate