mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-05 00:35:30 +00:00

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 ```
46 lines
1.2 KiB
Rust
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(())
|
|
})
|
|
}
|