-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
sqlite_fetch_all.rs
45 lines (36 loc) 路 1.16 KB
/
sqlite_fetch_all.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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(())
})
}