feat: sqlite
This commit is contained in:
parent
c142a33319
commit
d7fd79196a
5 changed files with 1135 additions and 5 deletions
1073
Cargo.lock
generated
1073
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
actix-rt = "2.8.0"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
clap = { version = "4.3.11", features = ["derive"] }
|
clap = { version = "4.3.11", features = ["derive"] }
|
||||||
log = "0.4.19"
|
log = "0.4.19"
|
||||||
|
@ -16,3 +17,5 @@ rayon = "1.7.0"
|
||||||
serde = { version = "1.0.169", features = ["derive"] }
|
serde = { version = "1.0.169", features = ["derive"] }
|
||||||
serde_json = "1.0.100"
|
serde_json = "1.0.100"
|
||||||
sled = "0.34.7"
|
sled = "0.34.7"
|
||||||
|
sqlx = { version = "0.7", features = [ "runtime-tokio", "sqlite" ] }
|
||||||
|
url = { version = "2.4.0", features = ["serde"] }
|
||||||
|
|
7
migrations/20230802225710_logs.sql
Normal file
7
migrations/20230802225710_logs.sql
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS logs (
|
||||||
|
string VARCHAR(100) NOT NULL,
|
||||||
|
salt VARCHAR(100) NOT NULL,
|
||||||
|
time VARCHAR(100) NOT NULL,
|
||||||
|
difficulty INTEGER NOT NULL UNIQUE,
|
||||||
|
ID INTEGER PRIMARY KEY NOT NULL
|
||||||
|
);
|
18
sliqte.sh
Executable file
18
sliqte.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m3kto1m4k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m4kto1m5k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m5kto1m6k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m6kto1m7k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m7kto1m8k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m8kto1m9k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/1m9kto2m
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/5kto50k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/50kto100k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/200kto300k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/300kto500k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/500kto600k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/600kto700k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/700kto800k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/800kto900k
|
||||||
|
cargo run --release -- sqlite --sqlite $DATABASE_URL --sled db2/900kto1m
|
39
src/main.rs
39
src/main.rs
|
@ -6,6 +6,7 @@ use clap::Parser;
|
||||||
use pow_sha256::ConfigBuilder;
|
use pow_sha256::ConfigBuilder;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sqlx::sqlite::SqlitePoolOptions;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Parser)] // requires `derive` feature
|
#[derive(Parser)] // requires `derive` feature
|
||||||
|
@ -14,6 +15,7 @@ use std::time::Instant;
|
||||||
enum PoWdCli {
|
enum PoWdCli {
|
||||||
Generate(GenerateDeriveArgs),
|
Generate(GenerateDeriveArgs),
|
||||||
PrintDB(PrintRes),
|
PrintDB(PrintRes),
|
||||||
|
Sqlite(Sqlite),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::Args, Debug, Clone)]
|
#[derive(clap::Args, Debug, Clone)]
|
||||||
|
@ -50,7 +52,9 @@ impl GenerateDeriveArgs {
|
||||||
let time_elapsed = finish.duration_since(start);
|
let time_elapsed = finish.duration_since(start);
|
||||||
|
|
||||||
let time = time_elapsed.as_micros();
|
let time = time_elapsed.as_micros();
|
||||||
log::info!("Difficulty factor {difficulty} generated in {time}");
|
if difficulty % 10000 == 0 {
|
||||||
|
log::info!("Difficulty factor {difficulty} generated in {time}");
|
||||||
|
}
|
||||||
|
|
||||||
let log = Log {
|
let log = Log {
|
||||||
salt: salt.clone(),
|
salt: salt.clone(),
|
||||||
|
@ -74,7 +78,17 @@ struct PrintRes {
|
||||||
db: std::path::PathBuf,
|
db: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[derive(clap::Args, Debug, Clone)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct Sqlite {
|
||||||
|
#[arg(long)]
|
||||||
|
sled: std::path::PathBuf,
|
||||||
|
#[arg(long)]
|
||||||
|
sqlite: url::Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::main]
|
||||||
|
async fn main() {
|
||||||
std::env::set_var("RUST_LOG", "INFO");
|
std::env::set_var("RUST_LOG", "INFO");
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
match PoWdCli::parse() {
|
match PoWdCli::parse() {
|
||||||
|
@ -92,6 +106,27 @@ fn main() {
|
||||||
println!("{difficulty}: {}", log.time);
|
println!("{difficulty}: {}", log.time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoWdCli::Sqlite(args) => {
|
||||||
|
let sqlite_db = SqlitePoolOptions::new().connect(&args.sqlite.to_string()).await.unwrap();
|
||||||
|
|
||||||
|
println!("{:?}", args);
|
||||||
|
let sled_db = sled::open(args.sled).unwrap();
|
||||||
|
for entry in sled_db.iter() {
|
||||||
|
let (difficulty, entry) = entry.unwrap();
|
||||||
|
let log: Log = bincode::deserialize::<Log>(&entry[..]).unwrap();
|
||||||
|
let difficulty: u32 = bincode::deserialize::<u32>(&difficulty).unwrap();
|
||||||
|
|
||||||
|
let time = log.time.to_string();
|
||||||
|
sqlx::query!(
|
||||||
|
"INSERT OR IGNORE INTO logs (string, salt, time, difficulty) VALUES ($1, $2, $3, $4);",
|
||||||
|
log.string,
|
||||||
|
log.salt,
|
||||||
|
time,
|
||||||
|
difficulty
|
||||||
|
).execute(&sqlite_db).await.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue