2024-09-05 08:04:12 +00:00
|
|
|
use std::sync::LazyLock;
|
2023-01-07 08:32:18 +00:00
|
|
|
use surrealdb::engine::remote::ws::Client;
|
|
|
|
use surrealdb::engine::remote::ws::Ws;
|
2022-12-30 08:23:19 +00:00
|
|
|
use surrealdb::Surreal;
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
|
2024-09-05 08:04:12 +00:00
|
|
|
static DB: LazyLock<Surreal<Client>> = LazyLock::new(Surreal::init);
|
2022-12-30 08:23:19 +00:00
|
|
|
|
|
|
|
const NUM: usize = 100_000;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> surrealdb::Result<()> {
|
|
|
|
DB.connect::<Ws>("localhost:8000").with_capacity(NUM).await?;
|
|
|
|
|
|
|
|
DB.use_ns("namespace").use_db("database").await?;
|
|
|
|
|
|
|
|
let (tx, mut rx) = mpsc::channel::<()>(1);
|
|
|
|
|
|
|
|
for idx in 0..NUM {
|
|
|
|
let sender = tx.clone();
|
|
|
|
tokio::spawn(async move {
|
|
|
|
let mut result = DB.query("SELECT * FROM $idx").bind(("idx", idx)).await.unwrap();
|
|
|
|
|
|
|
|
let db_idx: Option<usize> = result.take(0).unwrap();
|
|
|
|
if let Some(db_idx) = db_idx {
|
|
|
|
println!("{idx}: {db_idx}");
|
|
|
|
}
|
|
|
|
|
|
|
|
drop(sender);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
drop(tx);
|
|
|
|
|
|
|
|
rx.recv().await;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|