-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a584a9
commit 88a11a8
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |