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

bb8 Update #82

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cockroach = []
default = [ "cockroach" ]

[dependencies]
bb8 = "0.8"
bb8 = "0.9"
async-trait = "0.1.81"
diesel = { version = "2.2.2", default-features = false, features = [ "r2d2" ] }
futures = "0.3"
Expand Down
20 changes: 13 additions & 7 deletions examples/customize_connection.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
//! An example showing how to cutomize connections while using pooling.

use std::future::Future;
use std::pin::Pin;

use async_bb8_diesel::{AsyncSimpleConnection, Connection, ConnectionError};
use async_trait::async_trait;
use diesel::pg::PgConnection;

#[derive(Debug)]
struct ConnectionCustomizer {}

type DieselPgConn = Connection<PgConnection>;

#[async_trait]
impl bb8::CustomizeConnection<DieselPgConn, ConnectionError> for ConnectionCustomizer {
async fn on_acquire(&self, connection: &mut DieselPgConn) -> Result<(), ConnectionError> {
connection
.batch_execute_async("please execute some raw sql for me")
.await
.map_err(ConnectionError::from)
fn on_acquire<'a>(
&'a self,
connection: &'a mut DieselPgConn,
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'a>> {
Box::pin(async move {
let res = connection
.batch_execute_async("please execute some raw sql for me")
.await;
res.map_err(ConnectionError::from)
})
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/connection_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! An async-safe connection pool for Diesel.

use crate::{Connection, ConnectionError};
use async_trait::async_trait;
use diesel::r2d2::{self, ManageConnection, R2D2Connection};
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -59,7 +58,6 @@ impl<T: Send + 'static> ConnectionManager<T> {
}
}

#[async_trait]
impl<T> bb8::ManageConnection for ConnectionManager<T>
where
T: R2D2Connection + Send + 'static,
Expand Down
Loading