sqlx/sqlx-bench/benches/sqlite_fetch_all.rs
Yuri Astrakhan a824e8468c
Cleanup format arguments (#2650)
Inlined format args make code more readable, and code more compact.

I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases.

```
cargo clippy --bins --examples  --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2023-07-31 13:27:04 -07:00

46 lines
1.2 KiB
Rust

use sqlx::{Connection, Executor};
use std::time::Instant;
#[derive(sqlx::FromRow)]
struct Test {
id: i32,
}
fn main() -> sqlx::Result<()> {
sqlx::__rt::block_on(async {
let mut conn = sqlx::SqliteConnection::connect("sqlite://test.db?mode=rwc").await?;
let delete_sql = "DROP TABLE IF EXISTS test";
conn.execute(delete_sql).await?;
let create_sql = "CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY NOT NULL)";
conn.execute(create_sql).await?;
let mut tx = conn.begin().await?;
for entry in 0i32..100000 {
sqlx::query("INSERT INTO test (id) VALUES ($1)")
.bind(entry)
.execute(&mut tx)
.await?;
}
tx.commit().await?;
for _ in 0..10i8 {
let start = chrono::Utc::now();
println!(
"total: {}",
sqlx::query!("SELECT id from test")
.fetch_all(&mut conn)
.await?
.len()
);
let elapsed = chrono::Utc::now() - start;
println!("elapsed {elapsed}");
}
Ok(())
})
}