From 122700a789424062cb244c596399a1e79f1f7d14 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 20 Aug 2019 18:26:37 -0700 Subject: [PATCH] Clean up examples --- examples/contacts/src/main.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/contacts/src/main.rs b/examples/contacts/src/main.rs index 546cc4af..1b79f20c 100644 --- a/examples/contacts/src/main.rs +++ b/examples/contacts/src/main.rs @@ -10,10 +10,7 @@ use fake::{ Dummy, Fake, Faker, }; use futures::{channel::oneshot::channel, future, stream::TryStreamExt}; -use sqlx::{ - pg::{Pg, PgQuery}, - Connection, Pool, Query, -}; +use sqlx::{pg::Pg, Pool}; use std::{ io, time::{Duration, Instant}, @@ -47,13 +44,13 @@ async fn main() -> Fallible<()> { ensure_schema(&pool).await?; insert(&pool, 50_000).await?; - // select(&pool, 50_000).await?; + select(&pool, 1_000).await?; Ok(()) } async fn ensure_schema(pool: &PgPool) -> io::Result<()> { - sqlx::query::( + sqlx::query( r#" CREATE TABLE IF NOT EXISTS contacts ( id BIGSERIAL PRIMARY KEY, @@ -69,9 +66,7 @@ CREATE TABLE IF NOT EXISTS contacts ( .execute(&pool) .await?; - sqlx::query::("TRUNCATE contacts") - .execute(&pool) - .await?; + sqlx::query("TRUNCATE contacts").execute(&pool).await?; Ok(()) } @@ -86,7 +81,7 @@ async fn insert(pool: &PgPool, count: usize) -> io::Result<()> { let (tx, rx) = channel::<()>(); tokio::spawn(async move { - sqlx::query::( + sqlx::query( r#" INSERT INTO contacts (name, username, password, email, phone) VALUES ($1, $2, $3, $4, $5) @@ -122,7 +117,7 @@ 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 - let contacts: Vec<(String, String, String, String, String)> = sqlx::query::( + let contacts: Vec<(String, String, String, String, String)> = sqlx::query( r#" SELECT name, username, password, email, phone FROM contacts