mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
Clean up examples
This commit is contained in:
parent
6a18d0effd
commit
122700a789
@ -10,10 +10,7 @@ use fake::{
|
|||||||
Dummy, Fake, Faker,
|
Dummy, Fake, Faker,
|
||||||
};
|
};
|
||||||
use futures::{channel::oneshot::channel, future, stream::TryStreamExt};
|
use futures::{channel::oneshot::channel, future, stream::TryStreamExt};
|
||||||
use sqlx::{
|
use sqlx::{pg::Pg, Pool};
|
||||||
pg::{Pg, PgQuery},
|
|
||||||
Connection, Pool, Query,
|
|
||||||
};
|
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@ -47,13 +44,13 @@ async fn main() -> Fallible<()> {
|
|||||||
|
|
||||||
ensure_schema(&pool).await?;
|
ensure_schema(&pool).await?;
|
||||||
insert(&pool, 50_000).await?;
|
insert(&pool, 50_000).await?;
|
||||||
// select(&pool, 50_000).await?;
|
select(&pool, 1_000).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ensure_schema(pool: &PgPool) -> io::Result<()> {
|
async fn ensure_schema(pool: &PgPool) -> io::Result<()> {
|
||||||
sqlx::query::<PgQuery>(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
CREATE TABLE IF NOT EXISTS contacts (
|
CREATE TABLE IF NOT EXISTS contacts (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
@ -69,9 +66,7 @@ CREATE TABLE IF NOT EXISTS contacts (
|
|||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query::<PgQuery>("TRUNCATE contacts")
|
sqlx::query("TRUNCATE contacts").execute(&pool).await?;
|
||||||
.execute(&pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -86,7 +81,7 @@ async fn insert(pool: &PgPool, count: usize) -> io::Result<()> {
|
|||||||
let (tx, rx) = channel::<()>();
|
let (tx, rx) = channel::<()>();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
sqlx::query::<PgQuery>(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO contacts (name, username, password, email, phone)
|
INSERT INTO contacts (name, username, password, email, phone)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
@ -122,7 +117,7 @@ async fn select(pool: &PgPool, iterations: usize) -> io::Result<()> {
|
|||||||
|
|
||||||
for _ in 0..iterations {
|
for _ in 0..iterations {
|
||||||
// TODO: Once we have FromRow derives we can replace this with Vec<Contact>
|
// TODO: Once we have FromRow derives we can replace this with Vec<Contact>
|
||||||
let contacts: Vec<(String, String, String, String, String)> = sqlx::query::<PgQuery>(
|
let contacts: Vec<(String, String, String, String, String)> = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT name, username, password, email, phone
|
SELECT name, username, password, email, phone
|
||||||
FROM contacts
|
FROM contacts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user