Skip to content
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

AsyncConnectionWrapper does not implement build_transaction #115

Open
3 tasks done
banool opened this issue Sep 30, 2023 · 2 comments
Open
3 tasks done

AsyncConnectionWrapper does not implement build_transaction #115

banool opened this issue Sep 30, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@banool
Copy link

banool commented Sep 30, 2023

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,
                &current_ans_lookups,
                &ans_lookups,
                &current_ans_primary_names,
                &ans_primary_names,
                &current_ans_lookups_v2,
                &ans_lookups_v2,
                &current_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 git@github.com: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
@banool banool added the bug Something isn't working label Sep 30, 2023
@banool
Copy link
Author

banool commented Sep 30, 2023

I'm trying to fix this here: #116.

Update: Okay, should be ready for a review.

@banool
Copy link
Author

banool commented Oct 1, 2023

Alright that PR needed work I don't quite have time for, but this issue is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant