Skip to content

Commit

Permalink
Add test for #323
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed Jun 4, 2024
1 parent 2a584a9 commit 88a11a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ tokio-postgres = { version = "0.7.9", default-features = false }
config = { version = "0.14", features = ["json"] }
dotenvy = "0.15.0"
futures = "0.3.1"
futures-util = "0.3.30"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
26 changes: 26 additions & 0 deletions postgres/tests/async_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This code must compile even without the async_trait crate
// See: https://github.com/bikeshedder/deadpool/issues/323

use deadpool_postgres::{tokio_postgres::Row, GenericClient};
use futures_util::{Stream, StreamExt};
use std::future::Future;
use tokio_postgres::types::ToSql;

// this function borrowed from tokio_postgres source code
fn slice_iter<'a>(
s: &'a [&'a (dyn ToSql + Sync)],
) -> impl ExactSizeIterator<Item = &'a dyn ToSql> + 'a {
s.iter().map(|s| *s as _)
}

pub trait PgQuery {
fn query_raw(
db: &impl GenericClient,
params: &[&(dyn ToSql + Sync)],
) -> impl Future<Output = impl Stream<Item = Row>> + Send {
async {
let rows = db.query_raw("SELECT 1", slice_iter(params)).await.unwrap();
rows.map(|row| row.unwrap())
}
}
}

0 comments on commit 88a11a8

Please sign in to comment.