Skip to content

Commit 88a11a8

Browse files
committed
Add test for deadpool-rs#323
1 parent 2a584a9 commit 88a11a8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

postgres/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ tokio-postgres = { version = "0.7.9", default-features = false }
4040
config = { version = "0.14", features = ["json"] }
4141
dotenvy = "0.15.0"
4242
futures = "0.3.1"
43+
futures-util = "0.3.30"
4344
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

postgres/tests/async_trait.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This code must compile even without the async_trait crate
2+
// See: https://github.com/bikeshedder/deadpool/issues/323
3+
4+
use deadpool_postgres::{tokio_postgres::Row, GenericClient};
5+
use futures_util::{Stream, StreamExt};
6+
use std::future::Future;
7+
use tokio_postgres::types::ToSql;
8+
9+
// this function borrowed from tokio_postgres source code
10+
fn slice_iter<'a>(
11+
s: &'a [&'a (dyn ToSql + Sync)],
12+
) -> impl ExactSizeIterator<Item = &'a dyn ToSql> + 'a {
13+
s.iter().map(|s| *s as _)
14+
}
15+
16+
pub trait PgQuery {
17+
fn query_raw(
18+
db: &impl GenericClient,
19+
params: &[&(dyn ToSql + Sync)],
20+
) -> impl Future<Output = impl Stream<Item = Row>> + Send {
21+
async {
22+
let rows = db.query_raw("SELECT 1", slice_iter(params)).await.unwrap();
23+
rows.map(|row| row.unwrap())
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy