Run rustfmt

This commit is contained in:
Ryan Leckey 2019-08-18 20:42:45 -07:00
parent f79e901a3c
commit cdf7453f8f
3 changed files with 37 additions and 26 deletions

View File

@ -9,16 +9,15 @@ use fake::{
},
Dummy, Fake, Faker,
};
use std::time::Duration;
use futures::future;
use futures::channel::oneshot::channel;
use futures::stream::TryStreamExt;
use std::io;
use futures::{channel::oneshot::channel, future, stream::TryStreamExt};
use sqlx::{
pg::{Pg, PgQuery},
Pool, Query, Connection,
Connection, Pool, Query,
};
use std::{
io,
time::{Duration, Instant},
};
use std::time::Instant;
type PgPool = Pool<Pg>;
@ -88,18 +87,19 @@ async fn insert(pool: &PgPool, count: usize) -> io::Result<()> {
tokio::spawn(async move {
sqlx::query::<PgQuery>(
r#"
r#"
INSERT INTO contacts (name, username, password, email, phone)
VALUES ($1, $2, $3, $4, $5)
"#,
)
.bind(contact.name)
.bind(contact.username)
.bind(contact.password)
.bind(contact.email)
.bind(contact.phone)
.execute(&pool)
.await.unwrap();
)
.bind(contact.name)
.bind(contact.username)
.bind(contact.password)
.bind(contact.email)
.bind(contact.phone)
.execute(&pool)
.await
.unwrap();
tx.send(()).unwrap();
});
@ -123,11 +123,14 @@ async fn select(pool: &PgPool, iterations: usize) -> io::Result<()> {
for _ in 0..iterations {
// TODO: Once we have FromRow derives we can replace this with Vec<Contact>
let contacts: Vec<(String, String, String, String, String)> = sqlx::query::<PgQuery>(
r#"
r#"
SELECT name, username, password, email, phone
FROM contacts
"#,
).fetch(&pool).try_collect().await?;
)
.fetch(&pool)
.try_collect()
.await?;
rows = contacts.len();
}
@ -135,7 +138,10 @@ FROM contacts
let elapsed = start_at.elapsed();
let per = Duration::from_nanos((elapsed.as_nanos() / (iterations as u128)) as u64);
println!("select {} rows in ~{:?} [ x{} in {:?} ]", rows, per, iterations, elapsed);
println!(
"select {} rows in ~{:?} [ x{} in {:?} ]",
rows, per, iterations, elapsed
);
Ok(())
}

View File

@ -9,8 +9,10 @@ use futures::{
use std::{
io,
ops::{Deref, DerefMut},
sync::Arc,
sync::atomic::{AtomicBool, Ordering},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
pub trait RawConnection: Send {
@ -73,7 +75,7 @@ where
Ok(Self(Arc::new(shared)))
}
async fn get(&self) -> ConnectionFairy<DB> {
let raw = self.0.acquire().await;
let conn = ConnectionFairy::new(&self.0, raw);

View File

@ -23,13 +23,16 @@ pub trait Executor: Send {
T: FromRow<A, Self::Backend>;
}
impl<'e, E> Executor for &'e E where E: Executor + Send + Sync {
impl<'e, E> Executor for &'e E
where
E: Executor + Send + Sync,
{
type Backend = E::Backend;
#[inline]
fn execute<'c, 'q, Q: 'q + 'c>(&'c self, query: Q) -> BoxFuture<'c, io::Result<u64>>
where
Q: Query<'q, Backend = Self::Backend>
Q: Query<'q, Backend = Self::Backend>,
{
(*self).execute(query)
}
@ -37,7 +40,7 @@ impl<'e, E> Executor for &'e E where E: Executor + Send + Sync {
fn fetch<'c, 'q, A: 'c, T: 'c, Q: 'q + 'c>(&'c self, query: Q) -> BoxStream<'c, io::Result<T>>
where
Q: Query<'q, Backend = Self::Backend>,
T: FromRow<A, Self::Backend> + Send + Unpin
T: FromRow<A, Self::Backend> + Send + Unpin,
{
(*self).fetch(query)
}
@ -48,7 +51,7 @@ impl<'e, E> Executor for &'e E where E: Executor + Send + Sync {
) -> BoxFuture<'c, io::Result<Option<T>>>
where
Q: Query<'q, Backend = Self::Backend>,
T: FromRow<A, Self::Backend>
T: FromRow<A, Self::Backend>,
{
(*self).fetch_optional(query)
}